Skip to main content

HnswVectorIndex

Struct HnswVectorIndex 

Source
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

Source

pub fn new(dimension: usize, metric: DistanceMetric) -> Self

Create a new HNSW vector index with default parameters.

  • m = 16
  • ef_construction = 200
  • ef_search = 50
Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl VectorIndex for HnswVectorIndex

Source§

fn insert(&self, node_id: NodeId, embedding: &[f32]) -> Result<()>

Insert a vector for a node. Dimension must match the index’s configured dimension.
Source§

fn remove(&self, node_id: NodeId) -> Result<bool>

Remove a vector for a node.
Source§

fn search(&self, query: &[f32], k: usize) -> Result<Vec<SimilarityResult>>

Search for the k nearest neighbors of the query vector.
Source§

fn dimension(&self) -> usize

The dimensionality of vectors in this index.
Source§

fn metric(&self) -> DistanceMetric

The distance metric used by this index.
Source§

fn len(&self) -> usize

Number of vectors currently in the index.
Source§

fn node_ids(&self) -> Vec<NodeId>

Return all node IDs currently held by the index. Read more
Source§

fn save_to_path(&self, path: &Path) -> Result<()>

Persist the full index state to the given file path. Read more
Source§

fn is_empty(&self) -> bool

Whether the index is empty.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V