Expand description
§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 for the
Arc<RwLock<_>> pattern with append-mostly write semantics.
Re-exports§
pub use error::IndexError;pub use error::IndexResult;pub use hnsw::HnswConfig;pub use hnsw::HnswIndex;pub use hnsw::Neighbor;pub use metric::Metric;
Modules§
- concurrent
- Concurrent access wrapper over
HnswIndex. - error
- Error types for the vector index.
- hnsw
- HNSW index implementation.
- metric
- The
Metrictrait and built-in implementations.
Type Aliases§
- PointId
- Stable identifier for a point in the index.