fix: make HNSW graph build deterministic to stabilize test_ann_prefilter#6818
Merged
wjones127 merged 1 commit intoMay 19, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
782ad68 to
f766bc2
Compare
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.
Problem
test_ann_prefilteris flaky and failed on CI (linux-arm, Rust) — e.g. on the unrelated PR #6757 — with the HNSW+SQ parametrization returning a near-miss neighbor (row 10 instead of 6).Root cause
HNSW node-level assignment uses an unseeded thread RNG (
rand::rng()) in both the offline (HnswBuilder) and online (OnlineHnswBuilder) builders, so every index build produces a different random graph. On a tiny 300-vector dataset, an approximate HNSW+SQ search over a different graph each run can return a near neighbor instead of the exact one.mainwas green by luck of the RNG, not correctness.This is not caused by #6757 (the
String→Uuidindex-id refactor): index cache keys and on-disk index paths are byte-identical before/after that change; the test only surfaced the pre-existing flakiness.Fix
HNSW_LEVEL_RNG_SEED) viaSmallRng, making graph construction reproducible. Recall is statistically unaffected (identical level distribution; only the draws are fixed). A constant — rather than a newHnswBuildParamsfield — keeps the change contained (no serde/proto/binding changes).test_ann_prefilterto assert the property it actually validates (prefilter honored:filterable > 5) instead of an exact nearest-neighbor id, per the repo guideline that vector-index tests assert recall, not exact matches.