Repository navigation
fix(core): verify index/.keys sidecar consistency on load - #1362
Merged
Merged
Conversation
The vector index file and its .keys sidecar are published by two separate renames, so a crash between them left a mismatched pair that load only caught when the whole key map was empty. A stale map silently hid live rows (vecq) or let next_key restart too low (usearch). save() now writes a header line with the SHA-256 of the index bytes and the row count; load() rejects a sidecar that names a different index, a missing/empty sidecar for a non-empty index, and (for header-less legacy sidecars) key counts or ranges the index cannot hold. The existing corrupt-index path then discards both files and rebuilds from SQLite. Older binaries ignore the header line. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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.
What
VectorIndex::savewrites a header as the first.keysline:#uteke-keys\t<sha256 of the index bytes>\t<engine rows>. The#prefix means older binaries skip it (it does not parse as<key>\t<id>), so downgrades keep working.VectorIndex::loadrunsverify_pair_consistencyand returns an error when:finish_open: both files are removed and the index is rebuilt from SQLite.Why
#1325: index file and sidecar are published by two renames, and
loadonly rebuilt when the whole key map was empty. After a crash between the renames the sidecar is stale but non-empty, so live vecq rows look dead and a usearchnext_keycan restart too low and collide. That is silent data loss from search, with SQLite intact.Testing
interrupted_save_pair_is_rebuilt_not_lost(both engines): saves, "crashes" by restoring the previous sidecar, reopens, and asserts the newest memory is still returned by the vector index. It fails without the fix (the memory is missing from the results) and passes with it.memory/vector.rs: stale sidecar rejected, matching pair survives load+resave, header-less sidecar still loads, missing/empty sidecar rejected, out-of-range keys rejected.cargo test -p uteke-core --lib: 621 passed.cargo clippy -p uteke-core --all-targets -- -D warnings,cargo fmt --all -- --checkclean;cargo checkand the vector tests also pass for--features onnx,vecqandonnx,usearch;cargo run -p docgenno diff.Cost: one SHA-256 over the index bytes on save and on load (already in memory in both paths).
Closes #1325
🤖 Generated with Claude Code