pub trait VectorIndex: Send + Sync {
// Required methods
fn insert(&mut self, uri: String, vector: Vector) -> Result<()>;
fn search_knn(&self, query: &Vector, k: usize) -> Result<Vec<(String, f32)>>;
fn search_threshold(
&self,
query: &Vector,
threshold: f32,
) -> Result<Vec<(String, f32)>>;
fn get_vector(&self, uri: &str) -> Option<&Vector>;
// Provided methods
fn add_vector(
&mut self,
id: VectorId,
vector: Vector,
_metadata: Option<HashMap<String, String>>,
) -> Result<()> { ... }
fn update_vector(&mut self, id: VectorId, vector: Vector) -> Result<()> { ... }
fn update_metadata(
&mut self,
_id: VectorId,
_metadata: HashMap<String, String>,
) -> Result<()> { ... }
fn remove_vector(&mut self, _id: VectorId) -> Result<()> { ... }
fn iter_vectors(&self) -> Vec<(String, Vector)> { ... }
fn supports_enumeration(&self) -> bool { ... }
}Expand description
Vector index trait for efficient similarity search
Required Methods§
Sourcefn insert(&mut self, uri: String, vector: Vector) -> Result<()>
fn insert(&mut self, uri: String, vector: Vector) -> Result<()>
Insert a vector with associated URI
Sourcefn search_knn(&self, query: &Vector, k: usize) -> Result<Vec<(String, f32)>>
fn search_knn(&self, query: &Vector, k: usize) -> Result<Vec<(String, f32)>>
Find k nearest neighbors
Sourcefn search_threshold(
&self,
query: &Vector,
threshold: f32,
) -> Result<Vec<(String, f32)>>
fn search_threshold( &self, query: &Vector, threshold: f32, ) -> Result<Vec<(String, f32)>>
Find all vectors within threshold similarity
Sourcefn get_vector(&self, uri: &str) -> Option<&Vector>
fn get_vector(&self, uri: &str) -> Option<&Vector>
Get a vector by its URI
Provided Methods§
Sourcefn add_vector(
&mut self,
id: VectorId,
vector: Vector,
_metadata: Option<HashMap<String, String>>,
) -> Result<()>
fn add_vector( &mut self, id: VectorId, vector: Vector, _metadata: Option<HashMap<String, String>>, ) -> Result<()>
Add a vector with associated ID and metadata
Sourcefn update_vector(&mut self, id: VectorId, vector: Vector) -> Result<()>
fn update_vector(&mut self, id: VectorId, vector: Vector) -> Result<()>
Update an existing vector
Sourcefn update_metadata(
&mut self,
_id: VectorId,
_metadata: HashMap<String, String>,
) -> Result<()>
fn update_metadata( &mut self, _id: VectorId, _metadata: HashMap<String, String>, ) -> Result<()>
Update metadata for a vector
Sourcefn remove_vector(&mut self, _id: VectorId) -> Result<()>
fn remove_vector(&mut self, _id: VectorId) -> Result<()>
Remove a vector by its ID
Sourcefn iter_vectors(&self) -> Vec<(String, Vector)>
fn iter_vectors(&self) -> Vec<(String, Vector)>
Iterate all stored (id, vector) pairs.
The default returns an empty list; concrete index types that hold their
vectors in memory (or can reconstruct them, e.g. via decoding quantized
codes) should override this and VectorIndex::supports_enumeration
so callers like VectorStore::save_to_disk can tell real emptiness
apart from “this index type cannot enumerate its vectors”.
Sourcefn supports_enumeration(&self) -> bool
fn supports_enumeration(&self) -> bool
Whether VectorIndex::iter_vectors returns a real, complete
enumeration of the vectors held by this index.
Index types that override iter_vectors with a real implementation
(e.g. MemoryVectorIndex, HnswIndex, IvfIndex, PQIndex) must
also override this to return true. Callers that need to persist or
otherwise fully enumerate an index (e.g. VectorStore::save_to_disk)
should check this flag and fail loudly instead of silently persisting
an empty snapshot when it is false.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".