pub trait VectorStore:
Send
+ Sync
+ Sealed {
// Required methods
fn add(
&self,
scope: &Scope,
vector: &[f32],
qualified_name: String,
) -> Result<u64, MemoryError>;
fn remove(
&self,
scope: &Scope,
qualified_name: &str,
) -> Result<(), MemoryError>;
fn search(
&self,
filter: &ScopeFilter,
query: &[f32],
limit: usize,
) -> Result<Vec<(u64, String, f32)>, MemoryError>;
fn find_by_name(&self, qualified_name: &str) -> Option<u64>;
fn save(&self, dir: &Path) -> Result<(), MemoryError>;
fn is_ready(&self) -> bool;
fn dimensions(&self) -> usize;
fn commit_sha(&self) -> Option<String>;
fn set_commit_sha(&self, sha: Option<&str>);
}Expand description
A pluggable vector similarity store.
Implementations must be Send + Sync so they can be shared across async
tasks and placed behind an Arc or Box.
§Object safety
The trait is object-safe: load (which would return Self) is intentionally
absent. Each implementation provides its own constructor.
Required Methods§
Sourcefn add(
&self,
scope: &Scope,
vector: &[f32],
qualified_name: String,
) -> Result<u64, MemoryError>
fn add( &self, scope: &Scope, vector: &[f32], qualified_name: String, ) -> Result<u64, MemoryError>
Insert or upsert vector for qualified_name in the given scope.
Returns the key assigned to the entry in the global “all” index.
Sourcefn remove(&self, scope: &Scope, qualified_name: &str) -> Result<(), MemoryError>
fn remove(&self, scope: &Scope, qualified_name: &str) -> Result<(), MemoryError>
Remove the entry for qualified_name from scope (and from the
all-index). Best-effort — does not fail if the entry is absent.
Sourcefn search(
&self,
filter: &ScopeFilter,
query: &[f32],
limit: usize,
) -> Result<Vec<(u64, String, f32)>, MemoryError>
fn search( &self, filter: &ScopeFilter, query: &[f32], limit: usize, ) -> Result<Vec<(u64, String, f32)>, MemoryError>
Search for the limit nearest neighbours of query, filtered by
filter.
Returns (key, qualified_name, distance) triples sorted by ascending
distance (lower = more similar).
Sourcefn find_by_name(&self, qualified_name: &str) -> Option<u64>
fn find_by_name(&self, qualified_name: &str) -> Option<u64>
Look up the vector key for a qualified name in the all-index.
Returns None if the name is not indexed.
Sourcefn save(&self, dir: &Path) -> Result<(), MemoryError>
fn save(&self, dir: &Path) -> Result<(), MemoryError>
Persist all indexes to subdirectories under dir.
Sourcefn is_ready(&self) -> bool
fn is_ready(&self) -> bool
Returns true when the store is ready to accept queries.
For UsearchStore this is always true after construction. For
InMemoryStore it returns the configured value (useful to simulate
a not-yet-ready backend in tests).
Sourcefn dimensions(&self) -> usize
fn dimensions(&self) -> usize
The embedding dimensionality this store was initialised with.
Sourcefn commit_sha(&self) -> Option<String>
fn commit_sha(&self) -> Option<String>
The commit SHA last written to or read from the index metadata, if any.
Sourcefn set_commit_sha(&self, sha: Option<&str>)
fn set_commit_sha(&self, sha: Option<&str>)
Overwrite the stored commit SHA.