From c8af857714f3278b63bfad8376f17d6395658749 Mon Sep 17 00:00:00 2001 From: ruvnet Date: Mon, 22 Jun 2026 09:50:36 -0400 Subject: [PATCH] =?UTF-8?q?chore(gnn-rerank):=20cargo=20fmt=20=E2=80=94=20?= =?UTF-8?q?fix=20pre-existing=20rustfmt=20CI=20blocker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This formatting diff has blocked every PR's rustfmt check for weeks. Formatting only (no logic changes). Co-Authored-By: claude-flow --- crates/ruvector-gnn-rerank/src/graph.rs | 3 +- crates/ruvector-gnn-rerank/src/reranker.rs | 8 ++- .../tests/perf_benchmark.rs | 31 ++++++-- .../tests/recall_regression.rs | 26 +++++-- crates/ruvector-gnn-rerank/tests/security.rs | 71 +++++++++++++++---- 5 files changed, 109 insertions(+), 30 deletions(-) diff --git a/crates/ruvector-gnn-rerank/src/graph.rs b/crates/ruvector-gnn-rerank/src/graph.rs index a1d76eae0..9d4193798 100644 --- a/crates/ruvector-gnn-rerank/src/graph.rs +++ b/crates/ruvector-gnn-rerank/src/graph.rs @@ -35,8 +35,7 @@ impl CandidateGraph { // Cosine similarity is symmetric: sim(i,j) == sim(j,i). Compute each // pair once (upper triangle) and push it into both neighbour lists, // halving the dot-product work vs. the naive O(n²) double computation. - let mut sims: Vec> = - vec![Vec::with_capacity(n.saturating_sub(1)); n]; + let mut sims: Vec> = vec![Vec::with_capacity(n.saturating_sub(1)); n]; for i in 0..n { let (vi, ni) = (&candidates[i].vector, norms[i]); for j in (i + 1)..n { diff --git a/crates/ruvector-gnn-rerank/src/reranker.rs b/crates/ruvector-gnn-rerank/src/reranker.rs index 1b9b5a104..b941b5885 100644 --- a/crates/ruvector-gnn-rerank/src/reranker.rs +++ b/crates/ruvector-gnn-rerank/src/reranker.rs @@ -71,10 +71,14 @@ fn validate(candidates: &[Candidate], k: usize) -> Result<(), RerankerError> { }); } if !c.noisy_score.is_finite() { - return Err(RerankerError::NonFinite { what: "candidate score" }); + return Err(RerankerError::NonFinite { + what: "candidate score", + }); } if c.vector.iter().any(|x| !x.is_finite()) { - return Err(RerankerError::NonFinite { what: "candidate vector" }); + return Err(RerankerError::NonFinite { + what: "candidate vector", + }); } } Ok(()) diff --git a/crates/ruvector-gnn-rerank/tests/perf_benchmark.rs b/crates/ruvector-gnn-rerank/tests/perf_benchmark.rs index 5b1f7be93..e1096f71e 100644 --- a/crates/ruvector-gnn-rerank/tests/perf_benchmark.rs +++ b/crates/ruvector-gnn-rerank/tests/perf_benchmark.rs @@ -32,7 +32,9 @@ fn build_candidate_sets() -> (Vec>, Vec>) { let queries: Vec> = (0..N_SETS) .map(|_| { let base = &corpus[rng.gen_range(0..CORPUS)]; - base.iter().map(|&x| x + rng.gen_range(-0.1_f32..0.1)).collect() + base.iter() + .map(|&x| x + rng.gen_range(-0.1_f32..0.1)) + .collect() }) .collect(); let noise = Normal::new(0.0_f32, 0.40).unwrap(); @@ -51,14 +53,22 @@ fn build_candidate_sets() -> (Vec>, Vec>) { scored .into_iter() .take(RETRIEVAL_K) - .map(|(id, s)| Candidate { id: id as u32, vector: corpus[id].clone(), noisy_score: s }) + .map(|(id, s)| Candidate { + id: id as u32, + vector: corpus[id].clone(), + noisy_score: s, + }) .collect::>() }) .collect(); (queries, sets) } -fn time_reranker(r: &R, queries: &[Vec], sets: &[Vec]) -> f64 { +fn time_reranker( + r: &R, + queries: &[Vec], + sets: &[Vec], +) -> f64 { // warm up for (q, c) in queries.iter().zip(sets).take(16) { let _ = r.rerank(q, c, K).unwrap(); @@ -83,9 +93,18 @@ fn rerank_latency_throughput() { let gnn_us = time_reranker(&GnnDiffusionReranker::default(), &queries, &sets); eprintln!("rerank latency (DIM={DIM}, candidates={RETRIEVAL_K}, k={K}, n={N_SETS}):"); - eprintln!(" NoisyScore {noisy_us:8.2} µs/q {:.2} M QPS", 1.0 / noisy_us); - eprintln!(" GnnDiffusion {gnn_us:8.2} µs/q {:.2} M QPS", 1.0 / gnn_us); - eprintln!(" diffusion overhead: {:.1}× baseline", gnn_us / noisy_us.max(1e-6)); + eprintln!( + " NoisyScore {noisy_us:8.2} µs/q {:.2} M QPS", + 1.0 / noisy_us + ); + eprintln!( + " GnnDiffusion {gnn_us:8.2} µs/q {:.2} M QPS", + 1.0 / gnn_us + ); + eprintln!( + " diffusion overhead: {:.1}× baseline", + gnn_us / noisy_us.max(1e-6) + ); assert!( gnn_us < BUDGET_US, diff --git a/crates/ruvector-gnn-rerank/tests/recall_regression.rs b/crates/ruvector-gnn-rerank/tests/recall_regression.rs index 5474213d1..6e0b7c120 100644 --- a/crates/ruvector-gnn-rerank/tests/recall_regression.rs +++ b/crates/ruvector-gnn-rerank/tests/recall_regression.rs @@ -10,9 +10,7 @@ use std::collections::HashSet; use rand::{rngs::StdRng, Rng, SeedableRng}; use rand_distr::{Distribution, Normal}; -use ruvector_gnn_rerank::{ - Candidate, CandidateReranker, GnnDiffusionReranker, NoisyScoreReranker, -}; +use ruvector_gnn_rerank::{Candidate, CandidateReranker, GnnDiffusionReranker, NoisyScoreReranker}; const N: usize = 5_000; const DIM: usize = 128; @@ -44,7 +42,9 @@ fn gen_queries(corpus: &[Vec], n_queries: usize, seed: u64) -> Vec (0..n_queries) .map(|_| { let base = &corpus[rng.gen_range(0..corpus.len())]; - base.iter().map(|&x| x + rng.gen_range(-0.1_f32..0.1)).collect() + base.iter() + .map(|&x| x + rng.gen_range(-0.1_f32..0.1)) + .collect() }) .collect() } @@ -79,12 +79,24 @@ fn noisy_retrieve( scored .into_iter() .take(retrieval_k) - .map(|(id, noisy_score)| Candidate { id: id as u32, vector: corpus[id].clone(), noisy_score }) + .map(|(id, noisy_score)| Candidate { + id: id as u32, + vector: corpus[id].clone(), + noisy_score, + }) .collect() } -fn recall_at_k(results: &[ruvector_gnn_rerank::RankedResult], gt: &HashSet, k: usize) -> f64 { - let hits = results.iter().take(k).filter(|r| gt.contains(&(r.id as usize))).count(); +fn recall_at_k( + results: &[ruvector_gnn_rerank::RankedResult], + gt: &HashSet, + k: usize, +) -> f64 { + let hits = results + .iter() + .take(k) + .filter(|r| gt.contains(&(r.id as usize))) + .count(); hits as f64 / gt.len().min(k) as f64 } diff --git a/crates/ruvector-gnn-rerank/tests/security.rs b/crates/ruvector-gnn-rerank/tests/security.rs index 40ab0bfdf..56cada006 100644 --- a/crates/ruvector-gnn-rerank/tests/security.rs +++ b/crates/ruvector-gnn-rerank/tests/security.rs @@ -11,7 +11,11 @@ use ruvector_gnn_rerank::{ }; fn cand(id: u32, vector: Vec, noisy_score: f32) -> Candidate { - Candidate { id, vector, noisy_score } + Candidate { + id, + vector, + noisy_score, + } } /// Run an input through every variant; return whether ALL returned Ok. @@ -28,15 +32,24 @@ fn all_variants(query: &[f32], cands: &[Candidate], k: usize) -> Vec = (0..5).map(|i| cand(i, vec![0.0, 0.0, 0.0], 0.1 * i as f32)).collect(); + let identical: Vec = (0..5) + .map(|i| cand(i, vec![0.0, 0.0, 0.0], 0.1 * i as f32)) + .collect(); for r in all_variants(&[0.0, 0.0, 0.0], &identical, 5) { - assert!(r.is_ok(), "all-identical/zero vectors must not error or panic, got {r:?}"); + assert!( + r.is_ok(), + "all-identical/zero vectors must not error or panic, got {r:?}" + ); } }