pub trait MemoryBackend: Send + Sync {
// Required methods
fn remember<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get(
&self,
id: &str,
memory_type: MemoryType,
) -> Result<Option<MemoryEntry>>;
fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>>;
fn forget(&self, id: &str, memory_type: MemoryType) -> Result<bool>;
fn list(
&self,
memory_type: MemoryType,
limit: usize,
) -> Result<Vec<MemoryEntry>>;
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn recall_with_rerank<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn blend_into_prompt(
&self,
memories: &[MemoryEntry],
system_prompt: &str,
) -> String;
fn is_duplicate<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn remember_unique<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn list_by_tier(
&self,
tier: MemoryTier,
limit: usize,
) -> Result<Vec<MemoryEntry>>;
}Expand description
Storage backend strategy for memory CRUD.
Implementors provide the core read/write operations. The trait is
dyn-compatible (no generics) so MemoryManager can hold
Option<Arc<dyn MemoryBackend>>.
Required Methods§
Sourcefn remember<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remember<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store a memory entry. Returns the entry ID.
Sourcefn get(&self, id: &str, memory_type: MemoryType) -> Result<Option<MemoryEntry>>
fn get(&self, id: &str, memory_type: MemoryType) -> Result<Option<MemoryEntry>>
Retrieve a single memory by ID and type.
Sourcefn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>>
fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>>
Retrieve a single memory by ID (searches all types).
Sourcefn forget(&self, id: &str, memory_type: MemoryType) -> Result<bool>
fn forget(&self, id: &str, memory_type: MemoryType) -> Result<bool>
Delete a memory entry. Returns true if it existed.
Sourcefn list(
&self,
memory_type: MemoryType,
limit: usize,
) -> Result<Vec<MemoryEntry>>
fn list( &self, memory_type: MemoryType, limit: usize, ) -> Result<Vec<MemoryEntry>>
List memories of a given type, most recent first.
Sourcefn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
memory_type: Option<MemoryType>,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Search memories by query (semantic + keyword hybrid).
Sourcefn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Recall relevant memories for a query.
Sourcefn recall_with_rerank<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn recall_with_rerank<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
max_recall: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Recall with Flash Attention re-ranking.
Sourcefn blend_into_prompt(
&self,
memories: &[MemoryEntry],
system_prompt: &str,
) -> String
fn blend_into_prompt( &self, memories: &[MemoryEntry], system_prompt: &str, ) -> String
Blend recalled memories into the system prompt.
Sourcefn is_duplicate<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn is_duplicate<'life0, 'life1, 'async_trait>(
&'life0 self,
content: &'life1 str,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if a memory entry with identical content already exists.
Sourcefn remember_unique<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remember_unique<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store a memory entry only if no duplicate content exists.
Sourcefn list_by_tier(
&self,
tier: MemoryTier,
limit: usize,
) -> Result<Vec<MemoryEntry>>
fn list_by_tier( &self, tier: MemoryTier, limit: usize, ) -> Result<Vec<MemoryEntry>>
List memories by tier.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".