pub struct GraphManager { /* private fields */ }Expand description
Owns a CsrGraph and provides high-level graph operations.
All methods take &self — internal RwLock handles concurrency.
Implementations§
Source§impl GraphManager
impl GraphManager
Sourcepub fn open(dir: &Path) -> MenteResult<Self>
pub fn open(dir: &Path) -> MenteResult<Self>
Open a directory-backed graph manager.
Loads the last snapshot (graph.json) if present, replays the edge log
(edges.jsonl) on top of it, and keeps the log open for appending, so
graph mutations are crash-durable between snapshots.
Sourcepub fn save(&self, dir: &Path) -> MenteResult<()>
pub fn save(&self, dir: &Path) -> MenteResult<()>
Save a graph snapshot to the given directory and truncate the edge log.
Sourcepub fn load(dir: &Path) -> MenteResult<Self>
pub fn load(dir: &Path) -> MenteResult<Self>
Load the graph snapshot from the given directory (no durability log).
Prefer open(), which also replays and maintains the edge log.
Sourcepub fn add_memory(&self, id: MemoryId)
pub fn add_memory(&self, id: MemoryId)
Register a memory node in the graph.
Sourcepub fn remove_memory(&self, id: MemoryId)
pub fn remove_memory(&self, id: MemoryId)
Remove a memory node and all its edges.
Sourcepub fn add_relationship(&self, edge: &MemoryEdge) -> MenteResult<()>
pub fn add_relationship(&self, edge: &MemoryEdge) -> MenteResult<()>
Add a relationship (edge) between two memory nodes.
Sourcepub fn get_context_subgraph(
&self,
center: MemoryId,
depth: usize,
) -> (Vec<MemoryId>, Vec<MemoryEdge>)
pub fn get_context_subgraph( &self, center: MemoryId, depth: usize, ) -> (Vec<MemoryId>, Vec<MemoryEdge>)
Extract a context subgraph around a center node.
Sourcepub fn propagate_belief_change(
&self,
id: MemoryId,
new_confidence: f32,
) -> Vec<(MemoryId, f32)>
pub fn propagate_belief_change( &self, id: MemoryId, new_confidence: f32, ) -> Vec<(MemoryId, f32)>
Propagate a confidence change through the graph.
Sourcepub fn find_all_contradictions(&self, id: MemoryId) -> Vec<MemoryId>
pub fn find_all_contradictions(&self, id: MemoryId) -> Vec<MemoryId>
Find all nodes that contradict the given node.
Sourcepub fn strengthen_edge(&self, source: MemoryId, target: MemoryId, delta: f32)
pub fn strengthen_edge(&self, source: MemoryId, target: MemoryId, delta: f32)
Strengthen an edge weight (Hebbian learning: neurons that fire together wire together).
Sourcepub fn read_graph(&self) -> RwLockReadGuard<'_, CsrGraph>
pub fn read_graph(&self) -> RwLockReadGuard<'_, CsrGraph>
Access the underlying graph for read-only traversals.
Returns a read guard — hold it only briefly to avoid blocking writers.
Sourcepub fn graph(&self) -> RwLockReadGuard<'_, CsrGraph>
pub fn graph(&self) -> RwLockReadGuard<'_, CsrGraph>
Alias for read_graph() — backward compatible access to the CsrGraph.