Skip to main content

VectorIndex

Trait VectorIndex 

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

Source

fn add(&self, rowid: i64, embedding: &[f32]) -> Result<()>

Add a vector keyed by SQLite rowid. Idempotent — adding an existing rowid replaces the prior vector.

Source

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.

Source

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).

Source

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.”

Source

fn len(&self) -> usize

Number of vectors currently in the index. Used at startup to detect drift against SELECT COUNT(*) FROM episodes WHERE tier = 'hot'. On mismatch, the index is rebuilt from SQLite.

Source

fn dim(&self) -> usize

Vector dimension. Must match the Embedder that produced the vectors.

Provided Methods§

Source

fn is_empty(&self) -> bool

True if the index contains no vectors.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§