Repository navigation
perf(core): compact the vecq index when dead rows pass 25% - #1364
Merged
Merged
Conversation
vecq rows are append-only: updates and deletes leave tombstoned rows that grow the index and .keys files and make every search over-fetch k + dead from an O(N) scan. Nothing ever compacted them. VectorIndex::needs_compaction() flags a vecq index of >=128 rows with more than a quarter of them dead. Uteke::compact_index_if_needed(dry_run) rebuilds it from SQLite (original embeddings, chunks included) while holding the index write lock across the read and the build so no concurrent write is lost. It runs in the `dream` compact phase and in uteke-serve's 1s flusher thread (read-lock check only; the rebuild happens once the threshold is crossed). 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::needs_compaction(): true for a vecq index of at least 128 rows with more than 25% dead (tombstoned) rows. Newdead_rows()/physical_rows(). usearch removes in place, so it never has dead rows.Uteke::compact_index_if_needed(dry_run) -> Option<CompactionReport>: rebuilds the index from SQLite (original embeddings, document chunks included via the same loaderrepairnow shares) and persists. The index write lock is held across the SQLite read and the rebuild: a writer that committed before the read is rebuilt in, one that commits after blocks on the lock and inserts into the compacted index, so nothing is lost. Vectors of the wrong width are skipped beforebuild, which resets the index before it validates.dreamcompact phase (dry-run reports "would drop N dead rows") anduteke-serve's 1s flusher thread (read-lock check, rebuild only once the threshold is crossed).CompactionReporttype exported fromuteke-core.Why
#1324: vecq is append-only, so remove/re-insert leave dead rows. Search over-fetches
k + deadfrom an O(N) scan, and the index and.keysfiles only ever grow on update-heavy workloads. Nothing compacted them.Note: while a compaction runs in the server, requests wait (global
Mutex<Uteke>plus the index write lock). It only runs after the 25% threshold is crossed, so it is amortized, and only for vecq.Testing
vecq_compaction_shrinks_file_and_drops_dead_rows(acceptance): 200 memories, 150 forgotten -> 200 rows / 150 dead; dry run changes nothing; compaction -> 50 rows, 0 dead, file smaller, a surviving memory still found, state kept after reopen, and a second call is a no-op.cargo test --workspacepass,cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all -- --checkclean;onnx,usearchbuilds andonnx,vecqcore tests pass (626);cargo run -p docgenno diff.Closes #1324
🤖 Generated with Claude Code