Skip to content

Commit 1c6f810

Browse files
circulant parameter count
1 parent abda20a commit 1c6f810

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

parallel-hnsw/benches/bench.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,3 @@ fn create_test_data(length: usize) -> SillyComparator {
5050
data: Arc::new(vec),
5151
}
5252
}
53-
54-
#[bench]
55-
fn bla(b: &mut Bencher) {
56-
const LENGTH: usize = 10000;
57-
let comparator = create_test_data(LENGTH);
58-
let vs: Vec<VectorId> = (0..LENGTH).map(VectorId).collect();
59-
60-
b.iter(|| {
61-
let _result: Hnsw<_> = Hnsw::generate(comparator.clone(), vs.clone(), 24, 48, 2);
62-
});
63-
}

parallel-hnsw/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ use std::fmt::Debug;
3232
use crate::search::assert_layer_invariants;
3333
use crate::{priority_queue::PriorityQueue, search::match_within_epsilon};
3434

35+
const PRIMES: [usize; 40] = [
36+
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
37+
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
38+
];
39+
3540
pub enum WrappedBorrowable<'a, T: ?Sized, Borrowable: Deref<Target = T> + 'a> {
3641
Left(Borrowable),
3742
Right(&'a T),
@@ -158,12 +163,11 @@ impl<C> Layer<C> {
158163
}
159164

160165
pub fn routing_nodes(&self, nodeid: NodeId, sp: SearchParameters) -> Vec<NodeId> {
161-
let primes = [1, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37];
162166
// Calculate using the circulants
163167
let size = self.node_count();
164-
primes
168+
PRIMES
165169
.iter()
166-
.take(sp.grid_network_dimension)
170+
.take(sp.circulant_parameter_count)
167171
.map(|prime| NodeId((nodeid.0 + prime) % size))
168172
.filter(|i| *i != nodeid)
169173
.collect()
@@ -2251,7 +2255,9 @@ mod tests {
22512255
fn test_recall() {
22522256
let size = 10_000;
22532257
let dimension = 1536;
2254-
let bp = BuildParameters::default();
2258+
let mut bp = BuildParameters::default();
2259+
bp.initial_partition_search.circulant_parameter_count = 0;
2260+
bp.optimization.search.circulant_parameter_count = 0;
22552261
let mut hnsw: Hnsw<BigComparator> =
22562262
bigvec::make_random_hnsw_with_build_parameters(size, dimension, bp);
22572263
do_test_recall(&hnsw, 0.9);
@@ -2487,7 +2493,8 @@ mod tests {
24872493
let cc = Comparator32 { data: vecs.into() };
24882494
let vids: Vec<VectorId> = (0..size).map(VectorId).collect();
24892495
let mut bp = BuildParameters::default();
2490-
bp.optimization.search.grid_network_dimension = 0;
2496+
bp.initial_partition_search.circulant_parameter_count = 0;
2497+
bp.optimization.search.circulant_parameter_count = 0;
24912498
let mut hnsw: Hnsw<Comparator32> = Hnsw::generate(cc, vids, bp, &mut ());
24922499
hnsw.improve_index(bp, None, &mut ());
24932500
panic!()

parallel-hnsw/src/parameters.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub struct SearchParameters {
55
pub number_of_candidates: usize,
66
pub upper_layer_candidate_count: usize,
77
pub probe_depth: usize,
8-
pub grid_network_dimension: usize,
8+
pub circulant_parameter_count: usize,
99
}
1010

1111
impl Default for SearchParameters {
@@ -14,7 +14,7 @@ impl Default for SearchParameters {
1414
number_of_candidates: 300,
1515
upper_layer_candidate_count: 300,
1616
probe_depth: 2,
17-
grid_network_dimension: 12,
17+
circulant_parameter_count: 12,
1818
}
1919
}
2020
}
@@ -34,7 +34,7 @@ impl Default for OptimizationParameters {
3434
promotion_threshold: 0.01,
3535
neighborhood_threshold: 0.01,
3636
recall_proportion: 0.1,
37-
promotion_proportion: 1.0,
37+
promotion_proportion: 0.0,
3838
search: SearchParameters::default(),
3939
}
4040
}
@@ -60,7 +60,7 @@ impl Default for BuildParameters {
6060
number_of_candidates: 6,
6161
upper_layer_candidate_count: 6,
6262
probe_depth: 2,
63-
grid_network_dimension: 3,
63+
circulant_parameter_count: 12,
6464
},
6565
}
6666
}

0 commit comments

Comments
 (0)