pub struct HnswIndex { /* private fields */ }Expand description
HNSW index for approximate nearest neighbor search
Thread-safe implementation using Arc<RwLock<>> for concurrent reads.
Implementations§
Source§impl HnswIndex
impl HnswIndex
Sourcepub fn with_config(config: HnswConfig) -> Self
pub fn with_config(config: HnswConfig) -> Self
Create a new HNSW index with custom configuration
Sourcepub fn insert(
&mut self,
vector: SemanticVector,
) -> Result<usize, FrameworkError>
pub fn insert( &mut self, vector: SemanticVector, ) -> Result<usize, FrameworkError>
Sourcepub fn insert_batch(
&mut self,
vectors: Vec<SemanticVector>,
) -> Result<Vec<usize>, FrameworkError>
pub fn insert_batch( &mut self, vectors: Vec<SemanticVector>, ) -> Result<Vec<usize>, FrameworkError>
Insert a batch of vectors
More efficient than inserting one at a time for large batches.
Sourcepub fn search_knn(
&self,
query: &[f32],
k: usize,
) -> Result<Vec<HnswSearchResult>, FrameworkError>
pub fn search_knn( &self, query: &[f32], k: usize, ) -> Result<Vec<HnswSearchResult>, FrameworkError>
Sourcepub fn search_threshold(
&self,
query: &[f32],
threshold: f32,
max_results: Option<usize>,
) -> Result<Vec<HnswSearchResult>, FrameworkError>
pub fn search_threshold( &self, query: &[f32], threshold: f32, max_results: Option<usize>, ) -> Result<Vec<HnswSearchResult>, FrameworkError>
Sourcepub fn get_vector(&self, node_id: usize) -> Option<&Vec<f32>>
pub fn get_vector(&self, node_id: usize) -> Option<&Vec<f32>>
Get the underlying vector for a node
Sourcepub fn get_external_id(&self, node_id: usize) -> Option<&str>
pub fn get_external_id(&self, node_id: usize) -> Option<&str>
Get the external ID for a node
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HnswIndex
impl RefUnwindSafe for HnswIndex
impl Send for HnswIndex
impl Sync for HnswIndex
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more