pub struct MemoryGraph { /* private fields */ }Expand description
In-process memory graph backed by a SQLite WAL database.
Implementations§
Source§impl MemoryGraph
impl MemoryGraph
Sourcepub fn add_node(&self, id: &str, kind: &str, data: Option<Value>) -> Result<()>
pub fn add_node(&self, id: &str, kind: &str, data: Option<Value>) -> Result<()>
Add or update a node. If a node with this id already exists it is overwritten
in place (kind, data, and updated_at are refreshed; created_at is preserved).
Sourcepub fn get_node(&self, id: &str) -> Result<Node>
pub fn get_node(&self, id: &str) -> Result<Node>
Retrieve a node by its ID.
Returns AgentDbError::NodeNotFound if no node with that ID exists.
Sourcepub fn delete_node(&self, id: &str) -> Result<()>
pub fn delete_node(&self, id: &str) -> Result<()>
Remove a node by its ID. Associated edges are also deleted via ON DELETE CASCADE.
Sourcepub fn add_edge(
&self,
src: &str,
dst: &str,
relation: &str,
weight: f64,
) -> Result<()>
pub fn add_edge( &self, src: &str, dst: &str, relation: &str, weight: f64, ) -> Result<()>
Add or update a directed edge src → dst with the given relation label and weight.
Both src and dst must already exist; returns AgentDbError::NodeNotFound otherwise.
If an edge with the same (src, dst, relation) triple already exists its weight is updated.
Sourcepub fn delete_edge(&self, src: &str, dst: &str, relation: &str) -> Result<()>
pub fn delete_edge(&self, src: &str, dst: &str, relation: &str) -> Result<()>
Remove the edge src → dst with the given relation.
Returns AgentDbError::EdgeNotFound if no such edge exists.
Sourcepub fn neighbors(
&self,
node_id: &str,
opts: TraversalOptions,
) -> Result<Vec<TraversalResult>>
pub fn neighbors( &self, node_id: &str, opts: TraversalOptions, ) -> Result<Vec<TraversalResult>>
Traverse the graph from node_id and return all reachable nodes within the
constraints defined by opts.
Uses a recursive Common Table Expression (CTE) for efficient SQLite-side traversal. Results are ordered by ascending depth, then descending edge weight.