pub struct MemoryGraphEngine { /* private fields */ }Expand description
Thread-safe graph engine backed by a SQLite database.
Implementations§
Source§impl MemoryGraphEngine
impl MemoryGraphEngine
Sourcepub fn open(path: &str) -> Result<Self, Error>
pub fn open(path: &str) -> Result<Self, Error>
Open (or create) a graph database at the given path.
Pass ":memory:" for an ephemeral in-process database.
Sourcepub fn upsert_edge(&self, edge: &GraphEdge) -> Result<(), Error>
pub fn upsert_edge(&self, edge: &GraphEdge) -> Result<(), Error>
Upsert a single directed edge (idempotent).
Sourcepub fn remove_memory(&self, memory_id: &str) -> Result<(), Error>
pub fn remove_memory(&self, memory_id: &str) -> Result<(), Error>
Delete all edges involving a memory (used when a memory is forgotten).
Sourcepub fn get_edges(&self, memory_id: &str) -> Vec<GraphEdge>
pub fn get_edges(&self, memory_id: &str) -> Vec<GraphEdge>
Return all edges incident to a memory (both outbound and inbound).
Sourcepub fn traverse(
&self,
root_id: &str,
max_depth: u32,
namespace: &str,
) -> Vec<GraphNode>
pub fn traverse( &self, root_id: &str, max_depth: u32, namespace: &str, ) -> Vec<GraphNode>
BFS traversal starting from root_id up to max_depth.
Returns nodes in BFS order, each annotated with depth and incoming edges.
Sourcepub fn shortest_path(
&self,
from_id: &str,
to_id: &str,
namespace: &str,
) -> Option<Vec<String>>
pub fn shortest_path( &self, from_id: &str, to_id: &str, namespace: &str, ) -> Option<Vec<String>>
BFS shortest path between two memories.
Returns the sequence of memory IDs from from_id to to_id, inclusive.
Returns None if no path exists.
Sourcepub fn export(&self, namespace: &str) -> GraphExport
pub fn export(&self, namespace: &str) -> GraphExport
Export all edges in a namespace.
Sourcepub fn insert_audit_event(&self, event: &AuditEventInsert) -> Result<(), Error>
pub fn insert_audit_event(&self, event: &AuditEventInsert) -> Result<(), Error>
Insert a business-event audit record.
Sourcepub fn query_audit_events(
&self,
agent_id: Option<&str>,
event_type: Option<&str>,
from_ts: Option<u64>,
to_ts: Option<u64>,
limit: usize,
) -> Vec<AuditEvent>
pub fn query_audit_events( &self, agent_id: Option<&str>, event_type: Option<&str>, from_ts: Option<u64>, to_ts: Option<u64>, limit: usize, ) -> Vec<AuditEvent>
Query audit events with optional filters.
Uses always-bound params with IS-NULL guards so the query is pre-compiled once and indexes are still usable for the common single-filter case.
Sourcepub fn build_edges_for_new_memory(
&self,
new_id: &str,
new_embedding: &[f32],
new_tags: &[String],
new_created_at: u64,
namespace: &str,
existing: &[(String, Vec<f32>, Vec<String>, u64)],
)
pub fn build_edges_for_new_memory( &self, new_id: &str, new_embedding: &[f32], new_tags: &[String], new_created_at: u64, namespace: &str, existing: &[(String, Vec<f32>, Vec<String>, u64)], )
Build edges for a newly stored memory.
This is called from store_memory inside a tokio::spawn so it does
not block the HTTP response. It computes:
related_toedges for all existing memories with cosine ≥ 0.85shares_entityedges for memories sharing at least oneentity:*tagprecedesedges when memory A was stored before memory B and they also qualify asrelated_to
Trait Implementations§
Source§impl Clone for MemoryGraphEngine
impl Clone for MemoryGraphEngine
Source§fn clone(&self) -> MemoryGraphEngine
fn clone(&self) -> MemoryGraphEngine
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MemoryGraphEngine
impl RefUnwindSafe for MemoryGraphEngine
impl Send for MemoryGraphEngine
impl Sync for MemoryGraphEngine
impl Unpin for MemoryGraphEngine
impl UnsafeUnpin for MemoryGraphEngine
impl UnwindSafe for MemoryGraphEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more