pub struct PgStorage { /* private fields */ }Expand description
PostgreSQL-backed storage for Mnemo.
Wraps a sqlx::PgPool and runs schema migrations on construction.
Embeddings are stored using the pgvector vector column type, while
event embeddings are stored as BYTEA (serialised Vec<f32> in
little-endian byte order), matching the DuckDB backend convention.
Implementations§
Source§impl PgStorage
impl PgStorage
Sourcepub async fn connect(url: &str, dimensions: usize) -> Result<Self>
pub async fn connect(url: &str, dimensions: usize) -> Result<Self>
Connect to a PostgreSQL database and run migrations.
url is a standard postgres:// connection string.
dimensions controls the width of the pgvector vector column.
Sourcepub async fn from_pool(pool: PgPool, dimensions: usize) -> Result<Self>
pub async fn from_pool(pool: PgPool, dimensions: usize) -> Result<Self>
Build a PgStorage from an existing pool (useful for tests).
Sourcepub fn pool(&self) -> PgPool
pub fn pool(&self) -> PgPool
A clone of the connection pool, so a crate::PgVectorIndex can share
the same connections for ANN search. sqlx::PgPool is Arc-backed, so
the clone is cheap and points at the same pool.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
The pgvector vector(dim) column width this storage was migrated with.
Trait Implementations§
Source§impl StorageBackend for PgStorage
impl StorageBackend for PgStorage
Source§fn backend_name(&self) -> &'static str
fn backend_name(&self) -> &'static str
"duckdb",
"postgres"). Used in diagnostics such as
crate::error::Error::EmbedderNotConfigured so an error names the
backend in play. Defaults to "unknown"; real backends override it.fn insert_memory<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 MemoryRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_memory<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<MemoryRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn update_memory<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 MemoryRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn soft_delete_memory<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn hard_delete_memory<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_memories<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 MemoryFilter,
limit: usize,
offset: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn touch_memory<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert_acl<'life0, 'life1, 'async_trait>(
&'life0 self,
acl: &'life1 Acl,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn check_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
memory_id: Uuid,
principal_id: &'life1 str,
required: Permission,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert_relation<'life0, 'life1, 'async_trait>(
&'life0 self,
relation: &'life1 Relation,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_relations_from<'life0, 'async_trait>(
&'life0 self,
source_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<Relation>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_relations_to<'life0, 'async_trait>(
&'life0 self,
target_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<Relation>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete_relation<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_latest_memory_hash<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
thread_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_latest_event_hash<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
thread_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_sync_watermark<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_sync_watermark<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn list_accessible_memory_ids<'life0, 'life1, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Uuid>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert_event<'life0, 'life1, 'async_trait>(
&'life0 self,
event: &'life1 AgentEvent,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list_events<'life0, 'life1, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
limit: usize,
offset: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<AgentEvent>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_events_by_thread<'life0, 'life1, 'async_trait>(
&'life0 self,
thread_id: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<AgentEvent>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_event<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<AgentEvent>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_child_events<'life0, 'async_trait>(
&'life0 self,
parent_event_id: Uuid,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<AgentEvent>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_memories_by_agent_ordered<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
thread_id: Option<&'life2 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn list_memories_since<'life0, 'life1, 'async_trait>(
&'life0 self,
updated_after: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn upsert_memory<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 MemoryRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn cleanup_expired<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert_delegation<'life0, 'life1, 'async_trait>(
&'life0 self,
d: &'life1 Delegation,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list_delegations_for<'life0, 'life1, 'async_trait>(
&'life0 self,
delegate_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Delegation>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn revoke_delegation<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn check_delegation<'life0, 'life1, 'async_trait>(
&'life0 self,
delegate_id: &'life1 str,
memory_id: Uuid,
required: Permission,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert_or_update_agent_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
profile: &'life1 AgentProfile,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_agent_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<AgentProfile>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert_or_update_embedding_baseline<'life0, 'life1, 'async_trait>(
&'life0 self,
baseline: &'life1 EmbeddingBaseline,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_embedding_baseline<'life0, 'life1, 'async_trait>(
&'life0 self,
agent_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<EmbeddingBaseline>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert_checkpoint<'life0, 'life1, 'async_trait>(
&'life0 self,
cp: &'life1 Checkpoint,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_checkpoint<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<Checkpoint>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_checkpoints<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
thread_id: &'life1 str,
branch: Option<&'life2 str>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Checkpoint>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_latest_checkpoint<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
thread_id: &'life1 str,
branch: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Checkpoint>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn events_are_append_only(&self) -> bool
fn events_are_append_only(&self) -> bool
agent_events log is append-only
— no code path (and, where enforceable, no schema path) can delete or
rewrite an event row. Both shipped backends guarantee this: DuckDB has no
DELETE/UPDATE on agent_events, and PostgreSQL additionally enforces
it with a prevent_event_modification trigger. A retention-conformance
profile relies on this to promise a retention floor; a backend that
cannot honour it should override this to false so the profile fails
loud (see mnemo-compliance’s RetentionProfile). Defaults to true.Auto Trait Implementations§
impl !RefUnwindSafe for PgStorage
impl !UnwindSafe for PgStorage
impl Freeze for PgStorage
impl Send for PgStorage
impl Sync for PgStorage
impl Unpin for PgStorage
impl UnsafeUnpin for PgStorage
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