pub struct HnswIndex { /* private fields */ }Expand description
HNSW Index for approximate nearest neighbor search
Implementations§
Source§impl HnswIndex
impl HnswIndex
Sourcepub fn new(dimension: usize, config: HnswConfig) -> HnswIndex
pub fn new(dimension: usize, config: HnswConfig) -> HnswIndex
Create a new empty HNSW index
Sourcepub fn with_dimension(dimension: usize) -> HnswIndex
pub fn with_dimension(dimension: usize) -> HnswIndex
Create with default configuration
Sourcepub fn get_vector(&self, id: u64) -> Option<&[f32]>
pub fn get_vector(&self, id: u64) -> Option<&[f32]>
Get the vector for a node ID
Sourcepub fn insert_with_id(&mut self, id: u64, vector: Vec<f32>)
pub fn insert_with_id(&mut self, id: u64, vector: Vec<f32>)
Insert a vector with a specific ID
Sourcepub fn search(&self, query: &[f32], k: usize) -> Vec<DistanceResult>
pub fn search(&self, query: &[f32], k: usize) -> Vec<DistanceResult>
Search for k nearest neighbors
Sourcepub fn search_with_ef(
&self,
query: &[f32],
k: usize,
ef: usize,
) -> Vec<DistanceResult>
pub fn search_with_ef( &self, query: &[f32], k: usize, ef: usize, ) -> Vec<DistanceResult>
Search with custom ef parameter
Sourcepub fn search_filtered(
&self,
query: &[f32],
k: usize,
filter: &HashSet<u64>,
) -> Vec<DistanceResult>
pub fn search_filtered( &self, query: &[f32], k: usize, filter: &HashSet<u64>, ) -> Vec<DistanceResult>
Search with a filter (bitset of allowed IDs)
Sourcepub fn search_filtered_with_ef(
&self,
query: &[f32],
k: usize,
filter: &HashSet<u64>,
ef: usize,
) -> Vec<DistanceResult>
pub fn search_filtered_with_ef( &self, query: &[f32], k: usize, filter: &HashSet<u64>, ef: usize, ) -> Vec<DistanceResult>
Search with filter and custom ef
Sourcepub fn insert_batch(&mut self, vectors: Vec<Vec<f32>>) -> Vec<u64>
pub fn insert_batch(&mut self, vectors: Vec<Vec<f32>>) -> Vec<u64>
Insert multiple vectors at once
More efficient than individual inserts for large batches
Sourcepub fn insert_batch_with_ids(&mut self, items: Vec<(u64, Vec<f32>)>)
pub fn insert_batch_with_ids(&mut self, items: Vec<(u64, Vec<f32>)>)
Insert multiple vectors with specific IDs
Sourcepub fn delete(&mut self, id: u64) -> bool
pub fn delete(&mut self, id: u64) -> bool
Remove a node from the index
Note: This is a “soft” delete - the node is marked as deleted and excluded from search results, but connections are not fully repaired. For better performance after many deletes, rebuild the index.
Sourcepub fn search_adaptive(&self, query: &[f32], k: usize) -> Vec<DistanceResult>
pub fn search_adaptive(&self, query: &[f32], k: usize) -> Vec<DistanceResult>
Search with adaptive ef based on index size
Automatically adjusts ef_search based on the number of results needed and the size of the index for better accuracy/speed tradeoff.
Auto Trait Implementations§
impl !Freeze for HnswIndex
impl RefUnwindSafe for HnswIndex
impl Send for HnswIndex
impl Sync for HnswIndex
impl Unpin for HnswIndex
impl UnsafeUnpin for HnswIndex
impl UnwindSafe for HnswIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request