pub struct MarkdownMemoryStore { /* private fields */ }Expand description
A store for managing memories in markdown format.
This store uses a single markdown file (.ralph/agent/memories.md) to persist
memories. The file format is human-readable and version-control friendly.
§Multi-loop Safety
All read operations use shared locks, and all write operations use exclusive locks. This ensures safe concurrent access from multiple Ralph loops running in worktrees.
Implementations§
Source§impl MarkdownMemoryStore
impl MarkdownMemoryStore
Sourcepub fn new(path: impl AsRef<Path>) -> Self
pub fn new(path: impl AsRef<Path>) -> Self
Creates a new store at the given path.
The path should point to a .md file (typically .ralph/agent/memories.md).
The file does not need to exist - it will be created when first written to.
Sourcepub fn with_default_path(root: impl AsRef<Path>) -> Self
pub fn with_default_path(root: impl AsRef<Path>) -> Self
Creates a store with the default path (.ralph/agent/memories.md) under the given root.
Sourcepub fn init(&self, force: bool) -> Result<()>
pub fn init(&self, force: bool) -> Result<()>
Initializes the memories file with an empty template.
If force is false and the file already exists, this returns an error.
Uses an exclusive lock to prevent concurrent writes.
Sourcepub fn load(&self) -> Result<Vec<Memory>>
pub fn load(&self) -> Result<Vec<Memory>>
Reads all memories from the file.
Returns an empty vector if the file doesn’t exist. Uses a shared lock to allow concurrent reads from multiple loops.
Sourcepub fn append(&self, memory: &Memory) -> Result<()>
pub fn append(&self, memory: &Memory) -> Result<()>
Appends a new memory to the file.
The memory is inserted into its appropriate section (based on type). If the file doesn’t exist, it’s created with the template first. Uses an exclusive lock to prevent concurrent writes.
Sourcepub fn delete(&self, id: &str) -> Result<bool>
pub fn delete(&self, id: &str) -> Result<bool>
Deletes a memory by ID.
Returns Ok(true) if the memory was found and deleted,
Ok(false) if the memory was not found.
Uses an exclusive lock to prevent concurrent writes.
Sourcepub fn get(&self, id: &str) -> Result<Option<Memory>>
pub fn get(&self, id: &str) -> Result<Option<Memory>>
Returns the memory with the given ID, if it exists.
Sourcepub fn search(&self, query: &str) -> Result<Vec<Memory>>
pub fn search(&self, query: &str) -> Result<Vec<Memory>>
Searches memories by query string.
Matches against content and tags (case-insensitive).
Sourcepub fn filter_by_type(&self, memory_type: MemoryType) -> Result<Vec<Memory>>
pub fn filter_by_type(&self, memory_type: MemoryType) -> Result<Vec<Memory>>
Filters memories by type.
Filters memories by tags (OR logic - matches if any tag matches).
Trait Implementations§
Source§impl Clone for MarkdownMemoryStore
impl Clone for MarkdownMemoryStore
Source§fn clone(&self) -> MarkdownMemoryStore
fn clone(&self) -> MarkdownMemoryStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more