Skip to main content

MemoryBackend

Trait MemoryBackend 

Source
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§

Source

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.

Source

fn get(&self, id: &str, memory_type: MemoryType) -> Result<Option<MemoryEntry>>

Retrieve a single memory by ID and type.

Source

fn get_by_id(&self, id: &str) -> Result<Option<MemoryEntry>>

Retrieve a single memory by ID (searches all types).

Source

fn forget(&self, id: &str, memory_type: MemoryType) -> Result<bool>

Delete a memory entry. Returns true if it existed.

Source

fn list( &self, memory_type: MemoryType, limit: usize, ) -> Result<Vec<MemoryEntry>>

List memories of a given type, most recent first.

Source

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).

Source

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.

Source

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.

Source

fn blend_into_prompt( &self, memories: &[MemoryEntry], system_prompt: &str, ) -> String

Blend recalled memories into the system prompt.

Source

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.

Source

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.

Source

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".

Implementors§