Skip to main content

MemoryGraph

Struct MemoryGraph 

Source
pub struct MemoryGraph { /* private fields */ }
Expand description

In-process memory graph backed by a SQLite WAL database.

Implementations§

Source§

impl MemoryGraph

Source

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).

Source

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.

Source

pub fn delete_node(&self, id: &str) -> Result<()>

Remove a node by its ID. Associated edges are also deleted via ON DELETE CASCADE.

Source

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.

Source

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.

Source

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.

Source

pub fn nodes_by_kind(&self, kind: &str) -> Result<Vec<Node>>

Return all nodes whose kind field matches the given string.

Source

pub fn stats(&self) -> Result<(i64, i64)>

Return the total node and edge counts as (nodes, edges).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.