@@ -21,7 +21,7 @@ bool pickIdsDivisibleBySeven(unsigned int ep_id) {
21
21
}
22
22
23
23
template <typename filter_func_t >
24
- void test (filter_func_t filter_func, size_t div_num) {
24
+ void test (filter_func_t filter_func, size_t div_num, size_t label_id_start ) {
25
25
int d = 4 ;
26
26
idx_t n = 100 ;
27
27
idx_t nq = 10 ;
@@ -40,15 +40,15 @@ void test(filter_func_t filter_func, size_t div_num) {
40
40
for (idx_t i = 0 ; i < nq * d; ++i) {
41
41
query[i] = distrib (rng);
42
42
}
43
-
44
43
45
44
hnswlib::L2Space space (d);
46
45
hnswlib::AlgorithmInterface<float >* alg_brute = new hnswlib::BruteforceSearch<float ,hnswlib::FILTERFUNC>(&space, 2 * n);
47
46
hnswlib::AlgorithmInterface<float >* alg_hnsw = new hnswlib::HierarchicalNSW<float ,hnswlib::FILTERFUNC>(&space, 2 * n);
48
47
49
48
for (size_t i = 0 ; i < n; ++i) {
50
- alg_brute->addPoint (data.data () + d * i, i);
51
- alg_hnsw->addPoint (data.data () + d * i, i);
49
+ // `label_id_start` is used to ensure that the returned IDs are labels and not internal IDs
50
+ alg_brute->addPoint (data.data () + d * i, label_id_start + i);
51
+ alg_hnsw->addPoint (data.data () + d * i, label_id_start + i);
52
52
}
53
53
54
54
// test searchKnnCloserFirst of BruteforceSearch with filtering
@@ -87,8 +87,8 @@ void test(filter_func_t filter_func, size_t div_num) {
87
87
88
88
int main () {
89
89
std::cout << " Testing ..." << std::endl;
90
- test (pickIdsDivisibleByThree, 3 );
91
- test (pickIdsDivisibleBySeven, 7 );
90
+ test (pickIdsDivisibleByThree, 3 , 17 );
91
+ test (pickIdsDivisibleBySeven, 7 , 17 );
92
92
std::cout << " Test ok" << std::endl;
93
93
94
94
return 0 ;
0 commit comments