1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! # vector-index
//!
//! Generic HNSW (Hierarchical Navigable Small World) index with pluggable
//! distance metrics.
//!
//! This crate provides the *index structure* and a *metric trait*. It does
//! not bundle exotic metrics — implement [`Metric`] for your own type, or
//! use a companion crate (e.g. `sliced-wasserstein`) that already does.
//!
//! ## Quickstart
//!
//! ```
//! use vector_index::{HnswIndex, HnswConfig, metric::L2};
//!
//! let mut index = HnswIndex::<Vec<f32>, L2>::new(HnswConfig::default(), L2).expect("default config is valid");
//! index.insert(0, vec![1.0, 0.0, 0.0]).unwrap();
//! index.insert(1, vec![0.0, 1.0, 0.0]).unwrap();
//! index.insert(2, vec![1.0, 1.0, 0.0]).unwrap();
//!
//! let neighbors = index.search(&vec![1.0, 0.1, 0.0], 2);
//! assert_eq!(neighbors[0].id, 0); // closest point
//! ```
//!
//! ## Concurrency
//!
//! [`HnswIndex`] is not internally synchronized; wrap it in
//! [`ConcurrentHnsw`](concurrent::ConcurrentHnsw) for the
//! `Arc<RwLock<_>>` pattern with append-mostly write semantics.
// pedantic re-enabled when implementation matures.
extern crate alloc;
pub use ;
pub use ;
pub use Metric;
/// Stable identifier for a point in the index.
///
/// Chosen as `u64` rather than `usize` so that on-disk index serialization
/// is portable across 32-bit and 64-bit targets, and so the ID space is
/// large enough for write-heavy workloads where IDs are never reused.
pub type PointId = u64;