Skip to content

Feat/persistent storage durability#96

Merged
luis-gasparschroeder merged 6 commits into
vcache-project:masterfrom
Safaael25:feat/persistent-storage-durability
Jul 18, 2026
Merged

Feat/persistent storage durability#96
luis-gasparschroeder merged 6 commits into
vcache-project:masterfrom
Safaael25:feat/persistent-storage-durability

Conversation

@Safaael25

Copy link
Copy Markdown
Contributor

Make persistent HNSWLib writes atomic and avoid full index rewrites

PersistentHNSWLibVectorDB used to call save_index() (a full index rewrite) plus a separate meta.json write on every add/remove, and neither write was atomic — a crash between the two could desync the index from its metadata.

This replaces that with a checkpoint + write-ahead-log scheme:

Mutations are appended to a WAL (cheap, O(1)) instead of rewriting the full index each time.
The index is only fully serialized on a periodic checkpoint, published atomically via temp-file + os.replace alongside a manifest that pins the current generation and its metadata — so the two can never disagree.
On restart, the last checkpoint is loaded and any WAL entries written after it are replayed.
Single-writer crash safety only; concurrent multi-process writers to the same path are still unsupported (noted in the docstring).

Adds two opt-in, drop-in strategy implementations so the cache can survive
process restarts: SQLiteEmbeddingMetadataStorage persists metadata to a
SQLite file, and PersistentHNSWLibVectorDB persists its hnswlib index plus
a small bookkeeping sidecar to disk. Existing defaults (in-memory storage,
non-persistent HNSWLib) are unchanged.
…rites

Addresses maintainer feedback on the persistent-storage PR: the previous
implementation called index.save_index() plus a separate meta.json write on
every add/remove, which rewrote the whole index each time and could leave
the index and metadata desynchronized if a crash landed between the two
writes.

Replaces this with a checkpoint + write-ahead-log scheme: mutations are
appended to a WAL (cheap, O(1) per call) and only folded into a full index
snapshot periodically. Checkpoints publish a new generation file and manifest
via temp-file-plus-os.replace, so the previous generation stays valid and
visible until the new one is fully committed, and a crash can never surface
a partially-written index or an index/metadata mismatch. On load, the last
checkpoint is restored and any WAL entries written after it are replayed.
@Safaael25

Copy link
Copy Markdown
Contributor Author

@luis-gasparschroeder

@Safaael25
Safaael25 force-pushed the feat/persistent-storage-durability branch from 16afb2d to a9412f5 Compare July 17, 2026 17:50

@luis-gasparschroeder luis-gasparschroeder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Safaael25

Copy link
Copy Markdown
Contributor Author

@luis-gasparschroeder
Thanks!!!
Just wanted to check if there's anything else I should address to get this PR merged..

@luis-gasparschroeder

Copy link
Copy Markdown
Collaborator

@Safaael25, good to be merged, thanks.

Co-authored-by: Cursor <cursoragent@cursor.com>
@luis-gasparschroeder
luis-gasparschroeder merged commit 5829293 into vcache-project:master Jul 18, 2026
2 checks passed
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.

3 participants