pub struct HnswVectorIndex { /* private fields */ }Expand description
A thread-safe HNSW-based vector index.
Wraps HnswIndex with a parking_lot::RwLock so that multiple readers
can search concurrently, while writes (insert/remove) acquire exclusive access.
Implementations§
Source§impl HnswVectorIndex
impl HnswVectorIndex
Sourcepub fn new(dimension: usize, metric: DistanceMetric) -> Self
pub fn new(dimension: usize, metric: DistanceMetric) -> Self
Create a new HNSW vector index with default parameters.
m = 16ef_construction = 200ef_search = 50
Sourcepub fn with_params(
dimension: usize,
metric: DistanceMetric,
m: usize,
ef_construction: usize,
ef_search: usize,
) -> Self
pub fn with_params( dimension: usize, metric: DistanceMetric, m: usize, ef_construction: usize, ef_search: usize, ) -> Self
Create a new HNSW vector index with custom parameters.
Sourcepub fn with_seed(dimension: usize, metric: DistanceMetric, seed: u64) -> Self
pub fn with_seed(dimension: usize, metric: DistanceMetric, seed: u64) -> Self
Create a new HNSW vector index with a fixed RNG seed for reproducible
level sampling — useful for tests and benchmarks where the exact
graph layout needs to be deterministic. Uses the same default
parameters as Self::new otherwise. astraeadb-issues.md #18.
Sourcepub fn save_to_file(&self, path: &Path) -> Result<()>
pub fn save_to_file(&self, path: &Path) -> Result<()>
Persist the index to the given file path.
Acquires a read lock on the inner index and writes the full HNSW state to a versioned binary file.
Sourcepub fn load_from_file(path: &Path) -> Result<Self>
pub fn load_from_file(path: &Path) -> Result<Self>
Load an index from the given file path.
Reads and validates the binary file, then wraps the deserialized
HnswIndex in a new HnswVectorIndex with the default ef_search.