pub trait VectorBackend: Send + Sync {
// Required methods
fn insert(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>;
fn delete(&self, key: &str) -> Result<(), MemoryError>;
fn update(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>;
fn search(
&self,
query: &[f32],
top_k: usize,
) -> Result<Vec<VectorHit>, MemoryError>;
fn len(&self) -> usize;
fn save(&self, dir: &Path, basename: &str) -> Result<(), MemoryError>;
fn backend_name(&self) -> &'static str;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
Core vector index operations. All concrete backends implement this.
Object-safe: all methods take &self, no generic parameters. The
factory functions (new and load) are provided as free fn items
rather than trait methods, so the trait itself is dyn-compatible.
Required Methods§
Sourcefn insert(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>
fn insert(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>
Insert a key+vector pair. If the key already exists, the vector is updated.
Sourcefn delete(&self, key: &str) -> Result<(), MemoryError>
fn delete(&self, key: &str) -> Result<(), MemoryError>
Delete the key (if present). Idempotent.
Sourcefn update(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>
fn update(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>
Update the vector for an existing key (or insert if absent).
Sourcefn search(
&self,
query: &[f32],
top_k: usize,
) -> Result<Vec<VectorHit>, MemoryError>
fn search( &self, query: &[f32], top_k: usize, ) -> Result<Vec<VectorHit>, MemoryError>
k-NN search over the index. Returns up to top_k hits sorted by
ascending distance.
Sourcefn save(&self, dir: &Path, basename: &str) -> Result<(), MemoryError>
fn save(&self, dir: &Path, basename: &str) -> Result<(), MemoryError>
Flush the index to a backend-specific sidecar. Implementations may write additional files (manifest, digests, etc.) in the same dir.
Sourcefn backend_name(&self) -> &'static str
fn backend_name(&self) -> &'static str
Human-readable backend name (e.g. “hnsw_rs 0.3”, “usearch 2.25”).
Used in build receipts and VectorArtifactBuildReceiptV1.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".