pub trait VectorIndex: Send + Sync {
// Required methods
fn add(&self, id: Uuid, vector: &[f32]) -> Result<()>;
fn remove(&self, id: Uuid) -> Result<()>;
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, f32)>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn filtered_search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
filter: &'life2 (dyn Fn(Uuid) -> bool + Send + Sync),
) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, f32)>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn save(&self, path: &Path) -> Result<()>;
fn load(&self, path: &Path) -> Result<()>;
fn len(&self) -> usize;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
A pluggable approximate-nearest-neighbour index over memory embeddings.
search / filtered_search are async (v0.5.18). The PostgreSQL
(pgvector) backend runs a real sqlx query on the ambient Tokio runtime,
so the read path .awaits it directly instead of bridging through a
block_on — which, inside the server/CLI #[tokio::main] runtime, could
panic (“Cannot start a runtime from within a runtime”) or deadlock. The
in-memory USearch backend does synchronous CPU work inside its async method,
so it needs no runtime and assumes no runtime flavor. add / remove /
save / load / len remain synchronous.
The filter for filtered_search must be Send + Sync because it is held
across the .await inside the resulting Send future.
Required Methods§
fn add(&self, id: Uuid, vector: &[f32]) -> Result<()>
fn remove(&self, id: Uuid) -> Result<()>
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, f32)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn filtered_search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
filter: &'life2 (dyn Fn(Uuid) -> bool + Send + Sync),
) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, f32)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn save(&self, path: &Path) -> Result<()>
fn load(&self, path: &Path) -> Result<()>
fn len(&self) -> usize
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".