pub struct FileMemory { /* private fields */ }Expand description
JSONL-backed memory store.
Implementations§
Source§impl FileMemory
impl FileMemory
Sourcepub fn open(path: impl Into<PathBuf>) -> Result<Self, MemoryError>
pub fn open(path: impl Into<PathBuf>) -> Result<Self, MemoryError>
Open (or create) the JSONL file at path. Creates parent directories
as needed. Does not fail if the file is empty or absent.
Sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Path to the underlying JSONL file. Handy for tests and for logging
“memory:
Sourcepub fn compact(&self) -> Result<u32, MemoryError>
pub fn compact(&self) -> Result<u32, MemoryError>
Rewrite the file dropping every entry whose expires_ms <= now.
Use this as a periodic janitor (cron) to keep the file from
accumulating stale rows; recall already filters at read time, so
compact is purely a disk-space concern.
Returns how many entries were removed.
Sourcepub fn delete_by_id(&self, id: &str) -> Result<bool, MemoryError>
pub fn delete_by_id(&self, id: &str) -> Result<bool, MemoryError>
Delete one entry by id. Reads the file, drops the matching row,
rewrites. Returns true if a row was actually removed.
Sourcepub fn delete_all(&self) -> Result<u32, MemoryError>
pub fn delete_all(&self) -> Result<u32, MemoryError>
Drop every entry. Equivalent to rm <path>; touch <path> but holds
the write lock so no concurrent append races.
Trait Implementations§
Source§impl Memory for FileMemory
impl Memory for FileMemory
Source§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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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.Source§fn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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.Auto Trait Implementations§
impl !Freeze for FileMemory
impl RefUnwindSafe for FileMemory
impl Send for FileMemory
impl Sync for FileMemory
impl Unpin for FileMemory
impl UnsafeUnpin for FileMemory
impl UnwindSafe for FileMemory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more