From f1ec4980f5b37d3abff3957ac7be9c688fbfca73 Mon Sep 17 00:00:00 2001 From: ruvnet Date: Mon, 27 Apr 2026 01:27:00 -0400 Subject: [PATCH] fix(diskann): seed test RNGs to fix flaky test_diskann_basic `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. --- crates/ruvector-diskann/src/index.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ruvector-diskann/src/index.rs b/crates/ruvector-diskann/src/index.rs index 13f75d842..587bcebec 100644 --- a/crates/ruvector-diskann/src/index.rs +++ b/crates/ruvector-diskann/src/index.rs @@ -420,7 +420,10 @@ mod tests { fn random_vectors(n: usize, dim: usize) -> Vec<(String, Vec)> { use rand::prelude::*; - let mut rng = rand::thread_rng(); + // Seeded so tests are deterministic across CI runs — random data made + // basic-search assertions (nearest of vec-X is vec-X) flake when the + // ANN graph traversal happened to land on an unrelated near-duplicate. + let mut rng = rand::rngs::StdRng::seed_from_u64(0xD15CA77); (0..n) .map(|i| { let v: Vec = (0..dim).map(|_| rng.gen()).collect(); @@ -512,7 +515,7 @@ mod tests { fn test_recall_at_10() { // Measure recall@10: what fraction of true top-10 neighbors does DiskANN find? use rand::prelude::*; - let mut rng = rand::thread_rng(); + let mut rng = rand::rngs::StdRng::seed_from_u64(0xD15CA77); let n = 2000; let dim = 64; let k = 10; @@ -615,7 +618,7 @@ mod tests { // 5000 vectors, 128-dim — should build in under 5 seconds use rand::prelude::*; use std::time::Instant; - let mut rng = rand::thread_rng(); + let mut rng = rand::rngs::StdRng::seed_from_u64(0xD15CA77); let n = 5000; let dim = 128;