pub struct VectorSearchIndex { /* private fields */ }Expand description
Vector search index
Implementations§
Source§impl VectorSearchIndex
impl VectorSearchIndex
Sourcepub fn new(config: SearchConfig) -> Self
pub fn new(config: SearchConfig) -> Self
Create new vector search index
Sourcepub fn build(&mut self, embeddings: &HashMap<String, Vec<f32>>) -> Result<()>
pub fn build(&mut self, embeddings: &HashMap<String, Vec<f32>>) -> Result<()>
Build search index from embeddings
Sourcepub fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>
pub fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>
Search for K nearest neighbors
Sourcepub fn batch_search(
&self,
queries: &[Vec<f32>],
k: usize,
) -> Result<Vec<Vec<SearchResult>>>
pub fn batch_search( &self, queries: &[Vec<f32>], k: usize, ) -> Result<Vec<Vec<SearchResult>>>
Batch search for multiple queries
Sourcepub fn get_stats(&self) -> IndexStats
pub fn get_stats(&self) -> IndexStats
Get index statistics
Sourcepub fn radius_search(
&self,
query: &[f32],
radius: f32,
) -> Result<Vec<SearchResult>>
pub fn radius_search( &self, query: &[f32], radius: f32, ) -> Result<Vec<SearchResult>>
Find entities within a radius
Sourcepub fn set_metadata(&mut self, entity_id: &str, metadata: Metadata)
pub fn set_metadata(&mut self, entity_id: &str, metadata: Metadata)
Set metadata for an entity
Sourcepub fn set_metadata_batch(&mut self, metadata_map: HashMap<String, Metadata>)
pub fn set_metadata_batch(&mut self, metadata_map: HashMap<String, Metadata>)
Set metadata for multiple entities
Sourcepub fn get_metadata(&self, entity_id: &str) -> Option<&Metadata>
pub fn get_metadata(&self, entity_id: &str) -> Option<&Metadata>
Get metadata for an entity
Sourcepub fn filtered_search(
&self,
query: &[f32],
k: usize,
filter: &Filter,
) -> Result<Vec<SearchResult>>
pub fn filtered_search( &self, query: &[f32], k: usize, filter: &Filter, ) -> Result<Vec<SearchResult>>
Search with metadata filtering (post-filtering)
Post-filtering searches all vectors first, then filters results. This is efficient when the filter is selective.
Sourcepub fn prefiltered_search(
&self,
query: &[f32],
k: usize,
filter: &Filter,
) -> Result<Vec<SearchResult>>
pub fn prefiltered_search( &self, query: &[f32], k: usize, filter: &Filter, ) -> Result<Vec<SearchResult>>
Search with pre-filtering (filter before computing distances)
Pre-filtering only computes distances for entities matching the filter. This is efficient when the filter discards most entities.
Sourcepub fn add_vector(
&mut self,
entity_id: String,
embedding: Vec<f32>,
) -> Result<()>
pub fn add_vector( &mut self, entity_id: String, embedding: Vec<f32>, ) -> Result<()>
Add a single vector to the index incrementally (without full rebuild)
This is more efficient than rebuilding when adding a few vectors.
For bulk additions, consider using add_vectors or build.
Sourcepub fn add_vectors(
&mut self,
embeddings: &HashMap<String, Vec<f32>>,
) -> Result<()>
pub fn add_vectors( &mut self, embeddings: &HashMap<String, Vec<f32>>, ) -> Result<()>
Add multiple vectors to the index incrementally
More efficient than calling add_vector multiple times.
Sourcepub fn remove_vector(&mut self, entity_id: &str) -> Result<()>
pub fn remove_vector(&mut self, entity_id: &str) -> Result<()>
Remove a vector from the index
Sourcepub fn remove_vectors(&mut self, entity_ids: &[&str]) -> Result<()>
pub fn remove_vectors(&mut self, entity_ids: &[&str]) -> Result<()>
Remove multiple vectors from the index
Sourcepub fn update_vector(
&mut self,
entity_id: &str,
new_embedding: Vec<f32>,
) -> Result<()>
pub fn update_vector( &mut self, entity_id: &str, new_embedding: Vec<f32>, ) -> Result<()>
Update an existing vector in the index
Sourcepub fn merge(
&mut self,
other: &VectorSearchIndex,
overwrite_duplicates: bool,
) -> Result<()>
pub fn merge( &mut self, other: &VectorSearchIndex, overwrite_duplicates: bool, ) -> Result<()>
Merge another index into this one
Combines vectors from another index, handling duplicates and dimension checks.
By default, duplicates are skipped. Use overwrite_duplicates to update existing vectors.
Sourcepub fn merge_multiple(
indexes: &[&VectorSearchIndex],
) -> Result<VectorSearchIndex>
pub fn merge_multiple( indexes: &[&VectorSearchIndex], ) -> Result<VectorSearchIndex>
Create a new index by merging multiple indexes
This is more efficient than merging sequentially when combining many indexes.
Trait Implementations§
Source§impl Clone for VectorSearchIndex
impl Clone for VectorSearchIndex
Source§fn clone(&self) -> VectorSearchIndex
fn clone(&self) -> VectorSearchIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VectorSearchIndex
impl Debug for VectorSearchIndex
Source§impl<'de> Deserialize<'de> for VectorSearchIndex
impl<'de> Deserialize<'de> for VectorSearchIndex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for VectorSearchIndex
impl RefUnwindSafe for VectorSearchIndex
impl Send for VectorSearchIndex
impl Sync for VectorSearchIndex
impl Unpin for VectorSearchIndex
impl UnwindSafe for VectorSearchIndex
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more