pub struct PgVectorIndex { /* private fields */ }Expand description
A pgvector-backed VectorIndex for the PostgreSQL backend.
PostgreSQL stores each memory’s embedding in a pgvector vector column
(written by crate::PgStorage) and an HNSW index over it
(idx_memories_embedding_hnsw, built with vector_cosine_ops). When
constructed with a pool via PgVectorIndex::with_pool, search /
filtered_search run a real cosine-distance ANN query (<=>) against that
index and return the top-k memory ids + distances — the same
(id, distance) shape the USearch backend returns, so recall’s
score = 1.0 - distance conversion is identical across backends.
Constructed with PgVectorIndex::new (no pool) the ANN paths return the
typed Error::BackendUnsupported rather than a silent empty set —
silent-empty would make semantic / auto (hybrid) / graph /
domain_scoped recall look like it legitimately “found nothing”, the most
dangerous failure mode for a memory database.
§Runtime (v0.5.18)
VectorIndex::search / filtered_search
are async, so this backend .awaits its sqlx query directly on the
caller’s ambient Tokio runtime. There is no block_on bridge — semantic
recall works from inside the server/CLI #[tokio::main] runtime (any flavor,
single- or multi-threaded) without the “Cannot start a runtime from within a
runtime” panic or deadlock the old synchronous bridge risked. Integration
tests run under #[tokio::test] / #[tokio::test(flavor = "multi_thread")]
alike.
add / remove are intentional no-ops: the embedding is maintained by
PostgreSQL on the vector column (via PgStorage::insert_memory), not by
an in-process index. len() tracks an approximate element count for
is_empty() callers.
Implementations§
Source§impl PgVectorIndex
impl PgVectorIndex
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a pgvector index wrapper without a pool. The ANN search
paths return Error::BackendUnsupported (fail loud, never
silent-empty). Prefer PgVectorIndex::with_pool for a wired backend.
Trait Implementations§
Source§impl Default for PgVectorIndex
impl Default for PgVectorIndex
Source§impl VectorIndex for PgVectorIndex
impl VectorIndex for PgVectorIndex
fn add(&self, _id: Uuid, _vector: &[f32]) -> Result<()>
fn remove(&self, _id: Uuid) -> Result<()>
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, f32)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn filtered_search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 [f32],
limit: usize,
filter: &'life2 (dyn Fn(Uuid) -> bool + Send + Sync),
) -> Pin<Box<dyn Future<Output = Result<Vec<(Uuid, f32)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn save(&self, _path: &Path) -> Result<()>
fn load(&self, _path: &Path) -> Result<()>
fn len(&self) -> usize
fn is_empty(&self) -> bool
Auto Trait Implementations§
impl !Freeze for PgVectorIndex
impl !RefUnwindSafe for PgVectorIndex
impl !UnwindSafe for PgVectorIndex
impl Send for PgVectorIndex
impl Sync for PgVectorIndex
impl Unpin for PgVectorIndex
impl UnsafeUnpin for PgVectorIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more