vicinity 0.11.1

Approximate nearest-neighbor search
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use super::*;

#[test]
fn test_hnsw_l2_distance() {
    let mut index = HNSWIndex::builder(4)
        .metric(DistanceMetric::L2)
        .build()
        .unwrap();
    index.add_slice(0, &[1.0, 0.0, 0.0, 0.0]).unwrap();
    index.add_slice(1, &[0.0, 1.0, 0.0, 0.0]).unwrap();
    index.add_slice(2, &[100.0, 100.0, 0.0, 0.0]).unwrap();
    index.build().unwrap();
    let results = index.search(&[1.0, 0.1, 0.0, 0.0], 2, 10).unwrap();
    assert_eq!(results[0].0, 0, "closest to [1,0,0,0] should be doc 0");
}