pub trait VectorIndex:
Send
+ Sync
+ 'static {
// Required methods
fn ensure_collection(
&self,
vector_dim: usize,
) -> impl Future<Output = Result<(), VectorError>> + Send;
fn upsert(
&self,
memory: &Memory,
vector: Vec<f32>,
) -> impl Future<Output = Result<(), VectorError>> + Send;
fn search(
&self,
scope: Scope,
query_embedding: Vec<f32>,
limit: usize,
kinds: KindSelector,
extra_filter: Option<MemoryFilter>,
min_similarity: Option<f32>,
) -> impl Future<Output = Result<Vec<(String, f32)>, VectorError>> + Send;
fn delete_by_pids(
&self,
pids: &[&str],
) -> impl Future<Output = Result<(), VectorError>> + Send;
fn list_pids_in_scope(
&self,
scope: Scope,
page_size: usize,
) -> impl Future<Output = Result<Vec<String>, VectorError>> + Send;
}Expand description
Stores and queries vectors keyed by memory pid.
Implementations own the vector-backend connection. The trait methods are
async and Send-bound so callers can drive them from any tokio runtime.
Required Methods§
Sourcefn ensure_collection(
&self,
vector_dim: usize,
) -> impl Future<Output = Result<(), VectorError>> + Send
fn ensure_collection( &self, vector_dim: usize, ) -> impl Future<Output = Result<(), VectorError>> + Send
Ensures the backing collection exists with the configured dimension.
Idempotent: callers invoke this on startup; second-call is a no-op.
vector_dim must match the dimension produced by the embedding model
the consumer pairs with this index.
§Errors
Returns VectorError::Connection if the backend is unreachable,
VectorError::BadRequest if the collection exists with a
different vector dimension than requested.
Sourcefn upsert(
&self,
memory: &Memory,
vector: Vec<f32>,
) -> impl Future<Output = Result<(), VectorError>> + Send
fn upsert( &self, memory: &Memory, vector: Vec<f32>, ) -> impl Future<Output = Result<(), VectorError>> + Send
Upserts a memory’s vector + payload for similarity search and filtering.
The payload carries enough of the memory’s state to support payload-
level filters at search time: scope (agent_id, org_id, user_id),
kind, created_at, event_at (when known), and the memory’s
arbitrary JSON metadata flattened to top-level payload keys. The
source-of-truth row in Postgres still holds the canonical copy; the
payload is a derived index. Callers are responsible for ensuring the
Postgres row exists before this completes
(crate::store::IndexStatus::Pending covers the gap).
§Errors
Returns VectorError::Connection on backend errors and
VectorError::BadRequest when the vector’s dimension does not
match the collection’s.
Sourcefn search(
&self,
scope: Scope,
query_embedding: Vec<f32>,
limit: usize,
kinds: KindSelector,
extra_filter: Option<MemoryFilter>,
min_similarity: Option<f32>,
) -> impl Future<Output = Result<Vec<(String, f32)>, VectorError>> + Send
fn search( &self, scope: Scope, query_embedding: Vec<f32>, limit: usize, kinds: KindSelector, extra_filter: Option<MemoryFilter>, min_similarity: Option<f32>, ) -> impl Future<Output = Result<Vec<(String, f32)>, VectorError>> + Send
Returns the top similarity hits within scope, filtered by kind.
Returns pid+score tuples ordered by descending score. The caller
hydrates these into full crate::memory::Memory values via
crate::store::MemoryStore::find_by_pids.
extra_filter AND-joins with the scope + kind filter — caller-supplied
conditions cannot widen scope. An empty filter (or None) is inert.
min_similarity sets a score floor; hits below it are dropped by the
backend before they reach the result. None applies no floor.
§Errors
Returns VectorError::Connection on backend errors and
VectorError::BadRequest when the query vector’s dimension does
not match the collection’s.
Sourcefn delete_by_pids(
&self,
pids: &[&str],
) -> impl Future<Output = Result<(), VectorError>> + Send
fn delete_by_pids( &self, pids: &[&str], ) -> impl Future<Output = Result<(), VectorError>> + Send
Deletes vectors for the given pids.
Best-effort: failures are not propagated up to user-facing requests in the canonical Forget flow. The caller decides whether to surface errors (e.g. reconciliation propagates; user-facing Forget logs).
§Errors
Returns VectorError::Connection on backend errors.
Sourcefn list_pids_in_scope(
&self,
scope: Scope,
page_size: usize,
) -> impl Future<Output = Result<Vec<String>, VectorError>> + Send
fn list_pids_in_scope( &self, scope: Scope, page_size: usize, ) -> impl Future<Output = Result<Vec<String>, VectorError>> + Send
Returns every pid in the index that matches scope.
Used by the reconciliation sweep’s orphan-cleanup pass. Implementations
paginate internally using page_size and concatenate the result.
§Errors
Returns VectorError::Connection on backend errors.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".