Skip to main content

VectorBackend

Trait VectorBackend 

Source
pub trait VectorBackend: Send + Sync {
Show 15 methods // Required methods fn insert( &self, id: u64, key: &str, vector: &[f32], metadata: Value, ) -> VectorResult<()>; fn search(&self, query: &[f32], k: usize) -> Vec<SearchResult>; fn len(&self) -> usize; fn contains(&self, id: u64) -> bool; fn remove(&self, id: u64) -> bool; fn flush(&self) -> VectorResult<()>; fn backend_name(&self) -> &str; // Provided methods fn is_empty(&self) -> bool { ... } fn current_epoch(&self) -> u64 { ... } fn insert_with_epoch( &self, id: u64, key: &str, vector: &[f32], metadata: Value, parent_epoch: u64, ) -> VectorResult<()> { ... } fn soft_delete(&self, id: u64) -> bool { ... } fn compact(&self, _older_than_epoch: u64) -> usize { ... } fn tombstone_count(&self) -> usize { ... } fn max_vectors(&self) -> Option<usize> { ... } fn set_max_vectors(&self, _limit: Option<usize>) { ... }
}
Expand description

Unified vector search backend interface.

Implementations must be Send + Sync so they can be shared across async tasks via Arc.

Required Methods§

Source

fn insert( &self, id: u64, key: &str, vector: &[f32], metadata: Value, ) -> VectorResult<()>

Insert a vector with the given numeric ID, string key, and metadata.

If a vector with the same id already exists, it is replaced (upsert semantics).

Source

fn search(&self, query: &[f32], k: usize) -> Vec<SearchResult>

Search for the k nearest vectors to query.

Results are sorted by ascending distance (closest first).

Source

fn len(&self) -> usize

Return the number of vectors currently stored.

Source

fn contains(&self, id: u64) -> bool

Check whether a vector with the given ID exists.

Source

fn remove(&self, id: u64) -> bool

Remove a vector by ID. Returns true if it was present.

Source

fn flush(&self) -> VectorResult<()>

Persist any in-memory state to durable storage.

For purely in-memory backends (HNSW), this is a no-op.

Source

fn backend_name(&self) -> &str

Return a human-readable name for this backend (e.g. “hnsw”, “diskann”, “hybrid”).

Provided Methods§

Source

fn is_empty(&self) -> bool

Return true if the store contains no vectors.

Source

fn current_epoch(&self) -> u64

Return the current monotonic epoch.

The epoch is bumped on every mutating operation (insert, delete, update, soft-delete, compact). Implementations should persist the epoch across restarts via [flush] / load.

Source

fn insert_with_epoch( &self, id: u64, key: &str, vector: &[f32], metadata: Value, parent_epoch: u64, ) -> VectorResult<()>

Insert a vector only if the store’s current epoch matches parent_epoch. If the epoch has advanced past parent_epoch, the call is rejected with VectorError::EpochConflict.

This enables optimistic concurrency control for multi-agent writes: each agent reads the epoch, performs its work, then submits with the epoch it observed.

Source

fn soft_delete(&self, id: u64) -> bool

Mark a vector as tombstoned instead of physically removing it.

Tombstoned vectors are excluded from search results but remain in storage until [compact] is called. Returns true if the vector existed and was not already tombstoned.

Source

fn compact(&self, _older_than_epoch: u64) -> usize

Physically remove tombstones whose deletion epoch is older than older_than_epoch. Returns the number of entries purged.

Source

fn tombstone_count(&self) -> usize

Return the number of tombstoned (soft-deleted) entries.

Source

fn max_vectors(&self) -> Option<usize>

Return the configured maximum number of vectors, or None if unbounded.

Source

fn set_max_vectors(&self, _limit: Option<usize>)

Set the maximum number of vectors. Pass None for unbounded.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl VectorBackend for DiskAnnBackend

Available on crate feature diskann only.
Source§

impl VectorBackend for HnswBackend

Source§

impl VectorBackend for HybridBackend