Skip to content

feat(embedding): version the vector space so an embedder swap is safe - #327

Merged
SMK1705 merged 1 commit into
mainfrom
feat/embedder-versioned-vectors
Jul 27, 2026
Merged

feat(embedding): version the vector space so an embedder swap is safe#327
SMK1705 merged 1 commit into
mainfrom
feat/embedder-versioned-vectors

Conversation

@SMK1705

@SMK1705 SMK1705 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

…#316)

Groundwork for the neural embedder. Today every stored vector is an anonymous BLOB:
note_embeddings is (noteId, vector) with nothing recording WHICH embedder produced it.
Drop a neural embedder in behind the Embedder seam and the index would silently cosine
a 768-dim neural query against 256-dim lexical vectors — not a crash, just quietly
meaningless similarity scores across search, Ask recall and near-duplicate merging.
That has to be fixed BEFORE a model lands, not after.

- Embedder gains `id` (its vector-space identity) and `searchFloor`. The floor was a
  single global constant tuned for the hashing space; it is calibrated per space, so it
  now travels with the embedder. All four call sites read it from the index instead.
- note_embeddings gains `embedderId` (migration 18→19, defaulting to hashing-v1 —
  which is in fact what produced every existing row, so an upgrade re-indexes nothing).
- SemanticIndex.index() tags what it writes; scores() only reads vectors from the ACTIVE
  embedder (plus a dimension guard), so a foreign-space vector is skipped rather than
  scored; backfill() treats a vector from another embedder as absent, so the backfill
  the app ALREADY runs on Ask/Notes launch re-indexes after a swap with no extra step.

Net effect: swapping the embedder becomes a one-line DI change that heals itself, and a
half-finished re-index degrades recall instead of inventing nonsense similarities.

Tests: SemanticIndexTest covers tagging, foreign-space vectors being skipped, re-index
after a swap (asserting the new dimension lands), and the per-embedder floor, using a
stand-in embedder with a different id/dimension/floor. MigrationTest registers 18→19 in
the full chain (so Room's schema validation covers it) and adds a targeted test that an
existing vector survives with its bytes intact and is tagged hashing-v1.

Does NOT add a model or a runtime — that's the follow-up, and it now has somewhere safe
to land.
@SMK1705
SMK1705 merged commit 9e4ffdf into main Jul 27, 2026
1 check passed
@SMK1705
SMK1705 deleted the feat/embedder-versioned-vectors branch July 28, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant