pub trait VectorIndex: Send + Sync {
// Required methods
fn add(&self, rowid: i64, embedding: &[f32]) -> Result<()>;
fn remove(&self, rowid: i64) -> Result<()>;
fn search(&self, query: &[f32], k: usize) -> Result<Vec<(i64, f32)>>;
fn save(&self, path: &Path) -> Result<()>;
fn len(&self) -> usize;
fn dim(&self) -> usize;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
Approximate nearest-neighbor index over FP32 vectors keyed by SQLite rowid.
All mutating methods take &self. The discipline that makes this safe is
twofold: (1) the impl handles its own concurrency, and (2) only one task
(the WriterActor on its dedicated OS thread) issues mutations — read tasks
only call search. The trait does not enforce (2); callers must.
Required Methods§
Sourcefn add(&self, rowid: i64, embedding: &[f32]) -> Result<()>
fn add(&self, rowid: i64, embedding: &[f32]) -> Result<()>
Add a vector keyed by SQLite rowid. Idempotent — adding an existing rowid replaces the prior vector.
Sourcefn remove(&self, rowid: i64) -> Result<()>
fn remove(&self, rowid: i64) -> Result<()>
Remove a vector by rowid. Idempotent — removing a missing rowid is OK. May leave a tombstone (HNSW does); index is rebuilt periodically to compact.
Sourcefn search(&self, query: &[f32], k: usize) -> Result<Vec<(i64, f32)>>
fn search(&self, query: &[f32], k: usize) -> Result<Vec<(i64, f32)>>
Approximate nearest-neighbor search. Returns up to k results sorted by distance (ascending — smaller distance is more similar).
Sourcefn save(&self, path: &Path) -> Result<()>
fn save(&self, path: &Path) -> Result<()>
Snapshot the index to disk atomically. Implementations MUST write to a
.tmp file, fsync, then atomically rename over the target. The
previous snapshot should be preserved as a .bak file until the new
snapshot is fully in place. See solo-v0-architecture.md §3.2 —
“the HNSW sidecar is a cache, not source-of-truth.”
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".