Add durable HNSW snapshots and persistent DocumentStore (RAG_STATE_PATH) - #6
Merged
Merged
Conversation
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.
Motivation
Description
HNSWSNP\0magic header, explicitSNAPSHOT_VERSION, little-endian fields, checksum, bounds checks, and rejection of truncated/corrupt/invalid snapshots, and addedHnsw::to_bytes,Hnsw::from_bytes,Hnsw::save(path), andHnsw::load(path)APIs in Rust.SplitMix64RNG state and all durable index fields (dim, metric,HnswParams, contiguous vector data, per-node per-level links, entry point/top level) while reconstructing ephemeral scratch buffers on load.Hnswbinding with clearIOError/ValueErrormappings, and added binding-levelsave/load/to_bytes/from_byteshelpers.DocumentStoresnapshot container (RAGSTATE) that wraps deterministic JSON metadata (chunks, documents,_next_doc_id, index configuration, embedder identity) together with the HNSW bytes, and implemented transactional atomic commits via write-to-temp →fsync→ atomicreplace→ parentfsyncwhile staging changes before publishing in memory.RAG_STATE_PATH, added embedder compatibility and metadata validation on load, updated/statsto reportpersistence: { enabled, loaded, format_version }, and extended the Next.js types to include the persistence fields.README.md.Testing
cargo fmt --all --check,cargo clippy --all-targets -- -D warnings, andcargo test --workspace, and all checks and tests completed successfully.python -m pip install --force-reinstall ./bindings) and ranPYTHONPATH=service pytest -q bindings/tests service/tests, which passed (63 passed) with one Starlette/httpx deprecation warning only.cd app && npm ci && npm run build && npx tsc --noEmit, which completed a successful production build and type-check;npm cireported existing vulnerability notices but the build and type checks passed.