Squashed 'vendor/ruvector/' content from commit b64c2172
git-subtree-dir: vendor/ruvector git-subtree-split: b64c21726f2bb37286d9ee36a7869fef60cc6900
This commit is contained in:
36
crates/ruvector-core/src/index.rs
Normal file
36
crates/ruvector-core/src/index.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
//! Index structures for efficient vector search
|
||||
|
||||
pub mod flat;
|
||||
#[cfg(feature = "hnsw")]
|
||||
pub mod hnsw;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::types::{SearchResult, VectorId};
|
||||
|
||||
/// Trait for vector index implementations
|
||||
pub trait VectorIndex: Send + Sync {
|
||||
/// Add a vector to the index
|
||||
fn add(&mut self, id: VectorId, vector: Vec<f32>) -> Result<()>;
|
||||
|
||||
/// Add multiple vectors in batch
|
||||
fn add_batch(&mut self, entries: Vec<(VectorId, Vec<f32>)>) -> Result<()> {
|
||||
for (id, vector) in entries {
|
||||
self.add(id, vector)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Search for k nearest neighbors
|
||||
fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>;
|
||||
|
||||
/// Remove a vector from the index
|
||||
fn remove(&mut self, id: &VectorId) -> Result<bool>;
|
||||
|
||||
/// Get the number of vectors in the index
|
||||
fn len(&self) -> usize;
|
||||
|
||||
/// Check if the index is empty
|
||||
fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user