feat(storage): incremental HNSW updates on embedding writes - #53
Merged
Conversation
- HNSWIndex.Upsert/Remove: single-vector add/replace and detach with neighbor link pruning, entry-point repair, and per-node row upsert into embeddings_hnsw (no full rebuild) - Store.SaveEmbedding applies Upsert to the built index for the model (best-effort; next Build reconciles); Store.DeleteEmbedding removes the graph row before the embedding row (FK order) - Transactional embedding writes mark models dirty and drop the cache after commit, so the next SearchHNSW rebuilds from the embeddings table (the index cannot be safely mutated mid-transaction) - Tests: incremental upsert/replace, delete detach, tx invalidation, incremental-vs-full-build parity
This was referenced Aug 15, 2026
Patel230
added a commit
that referenced
this pull request
Aug 15, 2026
docs: mark Phase 2 items 1-3 shipped (PRs #53-55)
Patel230
added a commit
that referenced
this pull request
Aug 15, 2026
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.
Phase 2 follow-up to the Phase 1 HNSW work (#50).
Problem: every embedding write required a full
BuildHNSWIndexrebuild, so callers either searched a stale index or paid the O(n) rebuild cost.Solution:
HNSWIndex.Upsert(ctx, store, model, nodeID, vec)— add or replace one vector: detach old links, re-insert, and upsert only the affected rows inembeddings_hnswHNSWIndex.Remove(ctx, store, model, nodeID)— detach with neighbor link pruning, entry-point repair (when the top-level node is removed), and row deletionStore.SaveEmbeddingappliesUpsertto the built index for the embedding's model (best-effort; the embeddings table stays source of truth and a later build reconciles)Store.DeleteEmbeddingremoves the graph row before the embedding row (FK order — this also fixes a latent constraint failure on the delete path)WithTx) mark touched models dirty and drop the cache after commit, so the nextSearchHNSWrebuilds from the table (mid-transaction index mutation would be unsafe across busy-retry re-runs)Tests: incremental add/replace, delete detach + row cleanup, transactional invalidation, and incremental-vs-full-build top-5 parity. Full
go test ./...green.