pub trait Memory: Send + Sync {
// Required methods
fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}Expand description
The open-memory primitive.
Implementations:
- File-backed JSONL ([
harness_context::FileMemory]) — append-only, keyword recall, no extra deps. Default for the bundled examples. - Future: SQLite, sled, Postgres, vector-DB-backed semantic recall. Plug in by implementing this trait; nothing else in the framework changes.
Required Methods§
Sourcefn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, MemoryError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, MemoryError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Return up to k entries most relevant to query, ordered by
descending relevance. The query is typically the current task
description; backends choose how to score (keyword, embedding, BM25…).
Returning an empty Vec is fine and must not be treated as an error.
Sourcefn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Persist entry. The backend assigns the id field; callers may
leave it empty. Implementations must be safe to call concurrently
from multiple tasks.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".