fix(diskann): seed test RNGs to fix flaky test_diskann_basic#397
Merged
Conversation
`test_diskann_basic` and the other random-data tests in `crates/ruvector-diskann/src/index.rs` used `rand::thread_rng()`, so each CI run drew different vectors. The test asserts that the nearest neighbour of `vec-42` is `vec-42` itself; with unfavourable random draws the ANN graph traversal happened to settle on a near-duplicate (seen on main as `left: "vec-364"` vs `right: "vec-42"`) and the assertion failed. Fix: replace `thread_rng()` with `StdRng::seed_from_u64(0xD15CA77)` in `random_vectors()`, `test_recall_at_10`, and `test_scale_5k`. Output is fully deterministic across runs and platforms; verified locally with three repeats of `test_diskann_basic` and the full lib-test suite (17/17 passing in 49.6s). No production-code changes; tests-only.
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
Workspace-CI on main started failing
Tests (vector-index)after theACORN/RaBitQ-WASM merges (#391, #394) — not due to the new code, but
because
ruvector-diskann::index::tests::test_diskann_basicis flaky.The test draws 500 random 32-dim vectors, queries with
vec-42, andasserts the nearest neighbour is
vec-42itself. Withrand::thread_rng()(unseeded), CI run 24976593452 drew anunlucky distribution where the Vamana graph traversal returned
vec-364instead and the assertion failed.Fix
Replace
thread_rng()withStdRng::seed_from_u64(0xD15CA77)in thethree test-only RNG sites in
crates/ruvector-diskann/src/index.rs:random_vectors()— used bytest_diskann_basic,test_diskann_with_pq,test_diskann_save_loadtest_recall_at_10test_scale_5kNow fully deterministic across runs and platforms.
Verification
cargo test -p ruvector-diskann --lib→ 17/17 pass (49.6s)cargo test -p ruvector-diskann --lib test_diskann_basic×3 → allpass with identical timings (≈0.1s each)
No production-code changes; this is tests-only.