Skip to main content

MemoryStore

Trait MemoryStore 

Source
pub trait MemoryStore: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn ingest<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        role: &'life1 str,
        content: &'life2 str,
        token_count: usize,
    ) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn search<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
        limit: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryHit>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_context<'life0, 'async_trait>(
        &'life0 self,
        max_tokens: usize,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_context_entries<'life0, 'async_trait>(
        &'life0 self,
        max_tokens: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn compact<'life0, 'life1, 'async_trait>(
        &'life0 self,
        summarizer: &'life1 dyn Summarizer,
    ) -> Pin<Box<dyn Future<Output = Result<CompactionStats>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn message_count<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn summary_count<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn flush<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Core memory storage trait.

Implementations must be Send + Sync for sharing across async tasks. The trait abstracts over storage backends (SQLite, in-memory, remote) while ensuring consistent behavior for compaction and retrieval.

Required Methods§

Source

fn name(&self) -> &str

Return the human-readable name of this memory backend.

Source

fn ingest<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, role: &'life1 str, content: &'life2 str, token_count: usize, ) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Ingest a new message into the store.

Called synchronously on the message processing path. Implementations should avoid blocking I/O where possible.

Source

fn search<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryHit>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Full-text search across all stored messages and summaries.

Returns up to limit results ordered by relevance score.

Source

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

Generate context string for agent bootstrap.

Returns a formatted string of recent messages and summaries, respecting max_tokens budget. Used for system prompt injection.

Source

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

Get recent context entries for the agent.

Returns the most recent entries up to max_tokens budget.

Source

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

Run compaction if thresholds are exceeded.

Compresses older messages into summaries using the configured summarization backend. Safe to call frequently; returns early if no compaction needed.

Source

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

Return total message count (including compacted).

Source

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

Return total summary count.

Provided Methods§

Source

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

Flush any buffered data to persistent storage.

Implementors§