pub struct MemoryGraph {
pub entries: HashMap<String, MemoryEntry>,
}Expand description
In-memory graph of memory entries keyed by ID.
Fields§
§entries: HashMap<String, MemoryEntry>Implementations§
Source§impl MemoryGraph
impl MemoryGraph
Sourcepub fn load(path: &Path) -> Self
pub fn load(path: &Path) -> Self
Load a graph from a JSON file. Returns an empty graph if the file is missing or unparseable, so a missing/corrupt store never blocks startup.
Sourcepub fn save(&self, path: &Path) -> Result<()>
pub fn save(&self, path: &Path) -> Result<()>
Persist the graph to a JSON file (creating parent directories).
Sourcepub fn insert(&mut self, entry: MemoryEntry)
pub fn insert(&mut self, entry: MemoryEntry)
Insert a memory entry into the graph.
Sourcepub fn remember_keyed(&mut self, entry: MemoryEntry)
pub fn remember_keyed(&mut self, entry: MemoryEntry)
Insert an entry, deterministically superseding any active entry with
the same key (latest-wins). Superseded entries are kept (active=false)
for audit/restore — never hard-deleted. Unkeyed entries just insert.
Sourcepub fn list_all(&self) -> Vec<&MemoryEntry>
pub fn list_all(&self) -> Vec<&MemoryEntry>
All entries (including inactive/superseded), newest first — for
/memory --all and recovery.
Sourcepub fn restore(&mut self, id: &str) -> bool
pub fn restore(&mut self, id: &str) -> bool
Reactivate a previously superseded/deactivated entry by id. Clears its
superseded_by link. Returns true if the entry existed.
Sourcepub fn get_mut(&mut self, id: &str) -> Option<&mut MemoryEntry>
pub fn get_mut(&mut self, id: &str) -> Option<&mut MemoryEntry>
Get a mutable reference to a memory entry by ID.
Sourcepub fn forget(&mut self, id: &str) -> bool
pub fn forget(&mut self, id: &str) -> bool
Permanently remove a memory entry by ID. Returns true if one was removed.
Sourcepub fn deactivate(&mut self, id: &str) -> bool
pub fn deactivate(&mut self, id: &str) -> bool
Soft-deactivate a memory entry by ID (marks inactive, keeps for audit). Returns true if the entry existed and was active.
Sourcepub fn prune(&mut self, max_entries: usize)
pub fn prune(&mut self, max_entries: usize)
Bound the graph: drop expired entries first, then (if still over
max_entries) the lowest effective-confidence ones, until at the cap.
Keeps long-term memory and disk usage bounded on small servers.
Sourcepub fn search(&self, query: &str, limit: usize) -> Vec<&MemoryEntry>
pub fn search(&self, query: &str, limit: usize) -> Vec<&MemoryEntry>
Search active entries by lexical relevance (TF-IDF/BM25-lite over
content+tags) blended with effective confidence, then truncate to
limit. Dep-free (no vector store) — fits resource-constrained hosts.
Multi-word / partial-overlap queries recall far better than a whole-query
substring match. Falls back to whole-query substring for very short queries.
Sourcepub fn linked(&self, id: &str) -> Vec<&MemoryEntry>
pub fn linked(&self, id: &str) -> Vec<&MemoryEntry>
Return all entries directly linked to the given entry.
Sourcepub fn supersede(&mut self, old_id: &str, new_id: &str)
pub fn supersede(&mut self, old_id: &str, new_id: &str)
Replace an old entry with a new one and create a bidirectional link.
Sourcepub fn prune_inactive(&mut self) -> usize
pub fn prune_inactive(&mut self) -> usize
Remove inactive entries that have not been accessed in 30 days.
Sourcepub fn neighbors(&self, id: &str, max_hops: usize) -> Vec<&MemoryEntry>
pub fn neighbors(&self, id: &str, max_hops: usize) -> Vec<&MemoryEntry>
BFS traversal of reinforcement-related entries up to max_hops hops.
Sourcepub fn search_by_tag(&self, tag: &str) -> Vec<&MemoryEntry>
pub fn search_by_tag(&self, tag: &str) -> Vec<&MemoryEntry>
Search entries whose category or trust matches the given tag string.
Sourcepub fn prune_stale(&mut self, max_age_days: u64) -> usize
pub fn prune_stale(&mut self, max_age_days: u64) -> usize
Remove external-trust entries not accessed within max_age_days.