fix(memory): rebuild vec tables on embedder dimension change#138
Merged
rajkumarsakthivel merged 2 commits intoJul 13, 2026
Merged
Conversation
…abs#137) The decisions_vec / turn_summaries_vec tables were created at a hardcoded float[384] and never rebuilt, so any non-384-dim embedder (e.g. Ollama's default nomic-embed-text at 768) made every vec write a silently-swallowed dimension mismatch and killed semantic memory recall permanently. Implement the previously-referenced-but-missing _ensure_vec_dim (mirroring VectorStore._ensure_vec_table): drop + recreate both vec tables at the active embedder's dimension, leaving the source rows for backfill to re-embed. Hook it into the record_*_vec writers and reconcile up front in backfill_vec_tables so an already-populated index is repaired at cce serve startup too. Adds tests/memory/test_vec_dim.py covering the rebuild, the matching-dim no-op, and backfill after a dimension swap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #137.
Problem
decisions_vec/turn_summaries_vecare created at a hardcodedfloat[384](_VEC_DIM) and never rebuilt when the project's embedder has a different dimension._write_vec_rowswallows the resulting dimension-mismatchOperationalErroratdebug, so every semantic-memory write is silently dropped andsession_recallreturns nothing, permanently — no error surfaced. This hits the common zero-dependency path: without the[local]extra, cce falls back to Ollama, whose defaultnomic-embed-textis 768-dim.The comment at
memory/db.py:30already pointed at a_ensure_vec_dimrebuild — but it was never implemented (grepmatched only the comment). The code index solves the same problem viaVectorStore._ensure_vec_table; this brings the memory subsystem to parity.Fix
_ensure_vec_dim(conn, dim)(+_declared_vec_dim): when the active embedder's dimension differs from the vec tables', drop and recreate both*_vectables at the new dimension. Thedecisions/turn_summariessource rows are untouched —backfill_vec_tablesre-embeds them.record_*_vecwriters (self-heals on the next write) and reconcile up front inbackfill_vec_tables(runs atcce servestartup, so an already-populated index is repaired too — theNOT EXISTSfilter alone would miss that case).Both vec tables always share the embedder's dimension, so they're rebuilt together. No change to the source schema, migrations, or the 384-dim default path.
Testing
tests/memory/test_vec_dim.py: rebuild-on-larger-dim + row persists + searchable, matching-dim is a no-op (no data loss), and backfill-after-swap repopulates. These fail onmain(silent drop / missing function) and pass here.tests/memory/suite green (362 passed) on Python 3.13 with the sqlite-vec extension available.ruff check src/ tests/clean.vec rows: 1/search: [1].