Skip to main content

VectorBackend

Trait VectorBackend 

Source
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§

Source

fn insert(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>

Insert a key+vector pair. If the key already exists, the vector is updated.

Source

fn delete(&self, key: &str) -> Result<(), MemoryError>

Delete the key (if present). Idempotent.

Source

fn update(&self, key: String, vector: &[f32]) -> Result<(), MemoryError>

Update the vector for an existing key (or insert if absent).

Source

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.

Source

fn len(&self) -> usize

Number of live (non-deleted) entries.

Source

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.

Source

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§

Source

fn is_empty(&self) -> bool

Whether the index is empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§