Skip to main content

MemoryService

Trait MemoryService 

Source
pub trait MemoryService: Send + Sync {
Show 16 methods // Required methods fn add_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, session_id: &'life3 str, entries: Vec<MemoryEntry>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn search<'life0, 'async_trait>( &'life0 self, req: SearchRequest, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn delete_user<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'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 export_user<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<UserMemory>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn delete_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, session_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn add_entry<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, entry: MemoryEntry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn delete_entries<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, query: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn list_recent<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn delete_memory<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, memory_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn purge_expired<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn supports_project_scoping(&self) -> bool { ... } fn add_session_to_project<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, session_id: &'life3 str, project_id: &'life4 str, entries: Vec<MemoryEntry>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait { ... } fn add_entry_to_project<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, project_id: &'life3 str, entry: MemoryEntry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn delete_entries_in_project<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, project_id: &'life3 str, query: &'life4 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait { ... } fn delete_project<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, project_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... }
}

Required Methods§

Source

fn add_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, session_id: &'life3 str, entries: Vec<MemoryEntry>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Source

fn search<'life0, 'async_trait>( &'life0 self, req: SearchRequest, ) -> Pin<Box<dyn Future<Output = Result<SearchResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Provided Methods§

Source

fn delete_user<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete all memory entries for a specific user.

Removes every stored memory of the user in the app, embeddings and project-scoped entries included.

Source

fn export_user<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<UserMemory>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Returns every memory held for user_id in app_name — added from a session or directly, global or project-scoped — oldest first. delete_user removes exactly these.

MemorySubjectData exports a data subject’s memory through it.

§Errors

The default returns subject.unsupported (SUBJECT_UNSUPPORTED_CODE), so a backend that cannot list a user’s entries is reported, not silently empty.

Source

fn delete_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, session_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Delete all memory entries for a specific session.

Source

fn add_entry<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, entry: MemoryEntry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Add a single memory entry directly (not tied to a session).

Source

fn delete_entries<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, query: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Delete entries matching a query. Returns count of deleted entries.

Source

fn list_recent<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

List the most recent entries for a user (global + project-scoped), newest first. Unlike search, this is a pure recency listing — no query, no similarity ranking — suitable for “what does the agent remember?” UIs and latest-item lookups.

Source

fn delete_memory<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, memory_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Deletes the memory memory_id of user_id in app_name, global or in any project, and returns how many entries it removed: 0 when the user holds none with that id.

memory_id is the MemoryEntry::id a search, listing or export returned, or the id the caller set with MemoryEntry::with_id. Another user’s entry with the same id is never touched.

§Errors

The default returns an error, so a backend that cannot delete one entry is reported rather than silently keeping it.

Source

fn purge_expired<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Removes every stored entry whose expiry has passed, across all apps and users, and returns how many it removed.

Reads never return an expired entry, so a purge reclaims storage without changing what a search recalls. A backend whose store expires data natively (Redis key expiry, the MongoDB TTL index, Memory Bank) also removes entries on the store’s own schedule; the count covers only what this call removed. crate::expiry::spawn_expiry_sweep runs it on an interval.

§Errors

The default returns an error, so a backend that cannot purge is reported rather than silently keeping expired entries.

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Verify backend connectivity.

Returns Ok(()) if the backend is reachable and responsive. The default implementation always succeeds (suitable for in-memory).

Source

fn supports_project_scoping(&self) -> bool

Whether this backend keeps project-scoped entries isolated.

Returns false by default. A backend that implements the project methods below overrides this to true, so a caller can tell isolation apart from a backend that has no project support rather than discovering it from data.

Source

fn add_session_to_project<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, session_id: &'life3 str, project_id: &'life4 str, entries: Vec<MemoryEntry>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Adds session entries scoped to a project.

§Errors

The default implementation returns an error. Discarding project_id and writing globally would make entries intended for one project visible to everything else under the same app and user, with nothing in the return value to say so, so a backend without project support refuses the write instead.

Source

fn add_entry_to_project<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, project_id: &'life3 str, entry: MemoryEntry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Adds a single entry scoped to a project.

§Errors

Returns an error by default, for the reason given on MemoryService::add_session_to_project.

Source

fn delete_entries_in_project<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, project_id: &'life3 str, query: &'life4 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Deletes entries matching a query within a specific project.

§Errors

Returns an error by default. Falling back to a global delete would remove entries outside the named project, which is worse than refusing.

Source

fn delete_project<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, app_name: &'life1 str, user_id: &'life2 str, project_id: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Delete all entries for a specific project. Default returns “not implemented” error.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§