memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Lance semantic index grows to 140 GB for 657 MB of vectors (one commit per row, full manifest per commit, no compaction)

Open chenshuangci opened this issue 1 month ago • 1 comments

Summary

On a long-running install, the Lance semantic index grew to 139.95 GB while the actual vector data was only 657 MB. The _versions/ directory contained 64,611 manifests (138.79 GB) and data/ contained 64,609 fragments (1.11 GB) for 42,059 vectors. The store had 52,819 observations across 6 projects.

The cause is three behaviors compounding: one Lance commit per observation, a full manifest written on every commit, and no compaction/cleanup. A cold-start path that re-embeds vectors missing from the in-memory cache amplifies it by tens of thousands of commits per restart.

What I observed

~/.memorix/data/semantic-index/observations_<hash>.lance:

Path Size Files
_versions/*.manifest 138.79 GB 64,611
data/*.lance (fragments) 1.11 GB 64,609
index (IvfHnswSq) ~180 MB —

The average fragment is ~18 KB and holds one row, so 64,609 fragments ≈ 64,609 single-row writes. The latest manifest was 3.59 MB and referenced 41,778 live fragments.

Growth timeline (manifest bytes / manifest count):

Date Size Manifests
2026-09-11 0.07 GB 1,328
2026-10-08 2.56 GB 7,839
2026-10-14 5.75 GB 5,649
2026-10-23 93.22 GB 34,448
2026-10-25 16.86 GB 4,827
2026-10-26 10.84 GB 3,103

Root cause

  1. One commit per vector. The backfill path loops per observation: backfillVectorEmbeddings → queueSemanticVectorSafely → upsertSemanticVectors(dataDir, profile, [record]) with a single record. mergeVectors then runs mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows). Each call creates a new table version.
  2. Every commit writes a full manifest. LanceDB manifests enumerate all live fragments. With N commits and N fragments, total manifest bytes grow O(N²). 64,610 commits × 2.15 MB average ≈ 138.8 GB of metadata for 657 MB of vectors.
  3. No compaction or cleanup. Neither 1.9.9 nor 1.10.1 calls optimize() or cleanupOldVersions(), so every version and fragment is retained indefinitely.

Amplifier: cold-start re-embedding

hasObservationVector checks the in-memory Orama document's embedding, not the Lance table. hydrateIndexForStartup only restores vectors present in the embedding cache. With a 4096-dim model and the default MEMORIX_EMBEDDING_CACHE_MAX_BYTES = 256 MB (BYTES_PER_DIM = 8), the cache holds exactly 8,192 entries. The store has 42,059 vectors, so on every cold start about 33,867 vectors are classified as missing and re-embedded, each producing another commit.

Evidence: on 2026-10-23 there were 34,448 new table versions. 42,059 − 8,192 = 33,867, plus 303 new observations that day — an almost exact match. The cache also thrashes (re-embedding evicts older entries), so the next restart repeats the cycle with a different subset.

Impact

  • 139.95 GB of metadata for 657 MB of vectors; the 500 GB volume dropped to 88 GB free.
  • Recovery required table.optimize({ cleanupOlderThan: new Date(), deleteUnverified: true }): 41,778 fragments → 2, 64,610 old versions removed, 149.45 GB reclaimed.
  • Without manual intervention the table keeps growing superlinearly on every restart.

Suggested fixes

  1. Batch backfill writes. Merge 100–500 rows per mergeInsert instead of one row per call.
  2. Call optimize() periodically (after N commits, or on startup) and/or expose a memorix index optimize command that runs cleanupOldVersions with a retention window.
  3. Determine vector presence from the Lance table (or a persisted ID set) instead of the in-memory Orama cache, and hydrate from Lance on startup, so a cold cache does not trigger full re-embedding.
  4. Bound the cache by entry count and document the interaction with corpus size. Consider LRU eviction that does not cause existing rows to be re-embedded.

Reproduction

  1. Use an API embedding provider where corpus size exceeds cache capacity (e.g., 4096 dims, default 256 MB cache, more than 8,192 observations).
  2. Restart the control plane several times.
  3. Observe _versions/ grow by roughly corpus − cache entries per restart, and data/ accumulate one fragment per row.
  4. du -sh ~/.memorix/data/semantic-index/*.lance/_versions

Environment

  • memorix 1.9.9 (checked 1.10.1: same per-row insertObservation path, still no optimize calls)
  • Windows 11 (10.0.26300), Node v24.15.0
  • @lancedb/lancedb 0.38.0
  • Embedding: qwen3-embedding:8b, 4096 dims, API provider (local Ollama-compatible endpoint)
  • Store: 52,819 observations, 42,059 vectors, 6 projects

chenshuangci avatar Oct 25 '26 20:10 chenshuangci

Thanks for the detailed reproduction and disk breakdown. Fixed in v1.10.2 via #369: individual vector writes are batched, Lance tables are optimized periodically, and startup checks persisted Lance IDs before scheduling re-embedding or rewriting cached vectors. For an existing inflated index, stop Memorix processes using the shared data directory, then run memorix repair index from an associated Git project. This uses a 24-hour retention window and does not delete unverified files, so recent space may require a later rerun. Please do not delete Lance _versions or data files manually. v1.10.2 is available on npm, the MCP Registry, and GitHub Releases.

AVIDS2 avatar Oct 30 '26 14:10 AVIDS2