Skip to content

Add persistent SQLite metadata storage and persistent HNSWLib vector DB#95

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

Add persistent SQLite metadata storage and persistent HNSWLib vector DB#95
luis-gasparschroeder merged 3 commits into
vcache-project:masterfrom
Safaael25:feat/persistent-storage

Conversation

@Safaael25

Copy link
Copy Markdown
Contributor

description

  • Adds SQLiteEmbeddingMetadataStorage, a drop-in EmbeddingMetadataStorage
    that persists metadata to a SQLite file (pickled per row, keyed by
    embedding_id) instead of only living in memory.
  • Adds PersistentHNSWLibVectorDB, a standalone VectorDB implementation
    that persists its hnswlib index plus a small JSON bookkeeping sidecar to
    disk, so the vector index survives process restarts.
  • Both are opt-in additions, registered alongside the existing strategies.
    VCacheConfig defaults (InMemoryEmbeddingMetadataStorage,
    HNSWLibVectorDB) are unchanged — no existing behavior is affected.

Why?
The cache is currently entirely in-memory: every restart/redeploy/crash
throws away both the cached responses and the per-embedding learning state
(observations, thresholds) that VerifiedDecisionPolicy builds up over
time. This adds an opt-in path to make that durable.

Test plan

  • New unit tests for both strategies, including "simulated restart"
    tests (write via one instance, reopen a fresh instance on the same
    path, confirm data survives)
  • Existing EmbeddingMetadataStrategy / VectorDBStrategy suites still pass

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.
@Safaael25

Copy link
Copy Markdown
Contributor Author

@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.

Thank you for contributing to vCache! The SQLite extension makes sense; regarding persistent HNSWLib, a future PR should make index and metadata writes atomic and avoid rewriting the entire index after every mutation, as crashes or concurrent processes can otherwise corrupt or desynchronize the stored data.

@luis-gasparschroeder

Copy link
Copy Markdown
Collaborator

@Safaael25, please run the poetry ruff formatter, push the changes, and the PR is good to be merged.

@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.

Looks good, thanks!

@luis-gasparschroeder
luis-gasparschroeder merged commit ffef5b3 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.

2 participants