Skip to content

feat(storage): restore HNSW graph from embeddings_hnsw across restarts - #54

Merged
Patel230 merged 1 commit into
mainfrom
feat/storage-hnsw-restore
Aug 15, 2026
Merged

feat(storage): restore HNSW graph from embeddings_hnsw across restarts#54
Patel230 merged 1 commit into
mainfrom
feat/storage-hnsw-restore

Conversation

@Patel230

Copy link
Copy Markdown
Contributor

Phase 2 follow-up to #50/#53.

Problem: a restart lost the in-memory HNSW graph, so the first SearchHNSW recomputed the entire index from scratch.

Solution:

  • Persisted payload is now versioned: {version, m, efConstruction, levels} so stored graphs can be validated (legacy rows from pre-restore builds safely fall back to a rebuild)
  • HNSWIndex.Restore loads vectors + link lists from embeddings_hnsw, only accepting the graph when its node set exactly matches the embeddings table and the construction parameters match
  • SearchHNSW restores on first use; falls back to Build when the graph is absent, stale, or foreign — the fallback re-persists so subsequent restarts restore again
  • BuildHNSWIndex keeps its force-rebuild semantics
  • Dropped the now-dead HNSWNode type

Tests: identical results across a simulated restart (new Store on the same DB), stale-graph rejection + rebuild fallback + re-persist, and construction-parameter mismatch rejection. go test ./... green.

- Persist a versioned neighbors payload (version, m, efConstruction,
  levels) so Restore can validate stored graphs and reject foreign or
  legacy formats
- HNSWIndex.Restore loads vectors + link lists from the graph table,
  requiring exact membership parity with the embeddings table
- SearchHNSW now restores the persisted graph on first use (no
  recomputation after a restart) and falls back to a full Build when
  the stored graph is absent, stale, or built with different parameters
- BuildHNSWIndex remains the force-rebuild path
- Remove now-dead HNSWNode type (superseded by the payload)
- Tests: restart restore, stale-graph fallback + re-persist, and
  parameter-mismatch rejection
@Patel230
Patel230 merged commit f42d48b into main Aug 15, 2026
12 checks passed
@Patel230
Patel230 deleted the feat/storage-hnsw-restore branch August 15, 2026 11:13
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