memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Lazy corpus mode (>10k observations) silently disables all new vector writes, and vector-backfill reports success without embedding anything

Open chenshuangci opened this issue 1 month ago • 1 comments

Summary

Once a project's observation store crosses the Orama hydration threshold (10,000 durable rows), every process runs in "lazy" corpus mode. In that mode no new observation can ever receive a vector, and the queued vector-backfill maintenance job always reports success without embedding anything. Semantic recall silently degrades to lexical-only for all new memories while search keeps working, so nothing surfaces the problem except a stderr line.

Environment

  • memorix v1.10.2 (global npm install), Node v24.15.0, Windows 11
  • Observation store backend: SQLite, with the persistent lexical (FTS) index present
  • Embedding: api-qwen3-embedding:8b via an OpenAI-compatible endpoint, 4096d
  • Persistent vector table (Lance): observations_e6c8f449f7452a637d49 — 46,058 rows, FixedSizeList[4096]
  • Corpus: 55.6k observations total, 36.5k in a single project

Symptom

[memorix] Embedding dimension mismatch for obs-64396: provider returned 4096d, index expects unknown (kept in backfill queue)

New observations are missing from the Lance vector table, and the queue that is supposed to fix them stays quiet.

Root-cause chain

Line numbers are from the bundled dist/index.js of 1.10.2.

  1. Lazy mode never hydrates Orama. DEFAULT_ORAMA_HYDRATION_THRESHOLD = 1e4 (:154990). When durableCount >= threshold && store.hasLexicalIndex() (:154055-154066) the in-memory corpus is dropped, and prepareSearchIndex() short-circuits without touching Orama (:154750-154758):

    if (largeCorpusLazyMode && getObservationStore().hasLexicalIndex?.()) {
      searchIndexPrepared = true;
      ...
      return 0;
    }
    
  2. So the embedding schema is never present. getVectorDimensions() returns null because embeddingEnabled is false (:9103) — this is the index expects unknown in the log. Every write therefore fails isVectorCompatibleWithCurrentIndex().

  3. The self-heal path is unreachable in exactly this mode. upgradeVectorSchemaAfterFirstEmbedding() (:154029-154040) calls reindexObservations() (:154673), whose first statement is if (observations.length === 0) return 0; (:154674). In lazy mode observations is always empty, so the schema upgrade is a no-op and the mismatch repeats on every write.

  4. The backfill is a no-op too (the important part).

    • getVectorStatus() derives missing from the in-memory observations array (:154800-154809).
    • The maintenance handler does const before = getVectorStatus2(projectId); if (before.missing === 0) { ... return { action: "complete" }; } (:153536-153540).
    • backfillVectorEmbeddings() builds its candidate list from that same empty array (:154829-154842).

    In lazy mode this means: handler sees missing === 0 → completes in ~100 ms → vector-backfill jobs are recorded as completed while zero vectors are written.

  5. The only working path is never launched by default. executeVectorBackfill() (:153790-153815) is correct — it calls initObservations(dataDir, { forceCorpusLoad: true }) — but queueVectorBackfill() only spawns it when embeddingWriteMode === "deferred" (:154079). With the default background mode nothing ever launches it.

Also related, mid-write transition: persistObservation() flips a process into lazy mode and calls resetDb() immediately after committing a write (:154286-154292), which strands that in-flight observation's embedding.

Measured impact (this instance)

Active observations vs. presence in the Lance table, matched by (project_id, observation_id):

project active missing vector ratio
media/x-spider 1,910 782 41%
ai/skills 736 147 20%
ai/understudy 642 637 99%
local/zcode-profiler 169 71 42%
ai/agent-sync 53 46 87%

Degradation was monotonic as lazy-mode processes took over, for the largest project (per day created):

day active created missing
10-27 99 2
10-28 38 4
10-29 25 3
10-30 12 4
10-31 24 5
11-01 97 39
11-02 232 228
11-03 497 490

The highest observation_id present in the vector table is 64,222 (2026-11-03T16:13:33Z); the next observation, 64,223 (16:14:00Z, hook-sourced), has none, and neither does anything after it.

A live CLI process confirms the state indirectly: memorix memory search --json reports retrieval.derivedViews.orama.generation = 0.

How to reproduce

  1. Prepare a store with > 10,000 durable observations and the SQLite lexical (FTS) index built, or force the state with MEMORIX_ORAMA_HYDRATION_THRESHOLD=1 after one observation + index build.
  2. In a long-lived process (MCP server / serve-http), write a new observation.
  3. Observe Embedding dimension mismatch ... index expects unknown on stderr.
  4. Inspect the semantic vector table: row count does not grow.
  5. Inspect maintenance_jobs: the vector-backfill rows transition to completed and getVectorStatus().missing is 0 throughout.

Suggested directions

  • Source backfill candidates from the store, not from the in-memory corpus: diff getPersistentSemanticVectorIds(dataDir) (or store.loadByProject) against observations lacking vectors, so lazy mode can still backfill.
  • Same for getVectorStatus() — missing should not be 0 merely because the corpus was not hydrated.
  • Let upgradeVectorSchemaAfterFirstEmbedding() create the Orama embedding schema from the provider's dimensions without requiring reindexObservations() over a loaded corpus (the schema only needs embeddingDimensions, not the documents).
  • Consider not treating a vector-backfill job as completed when the process is in lazy mode and nothing was attempted; at minimum report attempted: 0 distinctly.

chenshuangci avatar Nov 03 '26 21:11 chenshuangci

Fixed in main via PR #376. Lazy corpus mode now initializes the vector schema without hydrating the full Orama corpus, reconciles missing IDs from SQLite/Lance, tracks project ownership for missing vectors, and lets maintenance backfill directly from the durable store. The change is included in tag v1.10.3.

AVIDS2 avatar Nov 05 '26 05:11 AVIDS2