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§
Sourcefn insert(
&self,
id: u64,
key: &str,
vector: &[f32],
metadata: Value,
) -> VectorResult<()>
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).
Sourcefn search(&self, query: &[f32], k: usize) -> Vec<SearchResult>
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).
Sourcefn flush(&self) -> VectorResult<()>
fn flush(&self) -> VectorResult<()>
Persist any in-memory state to durable storage.
For purely in-memory backends (HNSW), this is a no-op.
Sourcefn backend_name(&self) -> &str
fn backend_name(&self) -> &str
Return a human-readable name for this backend (e.g. “hnsw”, “diskann”, “hybrid”).
Provided Methods§
Sourcefn current_epoch(&self) -> u64
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.
Sourcefn insert_with_epoch(
&self,
id: u64,
key: &str,
vector: &[f32],
metadata: Value,
parent_epoch: u64,
) -> VectorResult<()>
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.
Sourcefn soft_delete(&self, id: u64) -> bool
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.
Sourcefn compact(&self, _older_than_epoch: u64) -> usize
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.
Sourcefn tombstone_count(&self) -> usize
fn tombstone_count(&self) -> usize
Return the number of tombstoned (soft-deleted) entries.
Sourcefn max_vectors(&self) -> Option<usize>
fn max_vectors(&self) -> Option<usize>
Return the configured maximum number of vectors, or None if
unbounded.
Sourcefn set_max_vectors(&self, _limit: Option<usize>)
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§
impl VectorBackend for DiskAnnBackend
diskann only.