pub struct MemoryGraph {
pub inner: StableGraph<MemNode, MemEdge>,
/* private fields */
}Expand description
The memory graph. Nodes are entries, edges are relationships.
Fields§
§inner: StableGraph<MemNode, MemEdge>Implementations§
Source§impl MemoryGraph
impl MemoryGraph
pub fn new() -> Self
Sourcepub fn partition_of(&self, nix: NodeIndex) -> Partition
pub fn partition_of(&self, nix: NodeIndex) -> Partition
Partition a node belongs to. Returns Partition::Project for any node
not explicitly assigned (the legacy default).
Sourcepub fn insert_partitioned(
&mut self,
node: MemNode,
partition: Partition,
) -> NodeIndex
pub fn insert_partitioned( &mut self, node: MemNode, partition: Partition, ) -> NodeIndex
Insert a node into the given Partition. For Project, equivalent
to insert. For Foreign, enforces idempotency by (repo, commit, key)
— re-inserting the same triple returns the existing NodeIndex
rather than creating a duplicate.
Sourcepub fn insert_foreign(
&mut self,
source_repo: impl Into<String>,
commit: impl Into<String>,
node: MemNode,
) -> NodeIndex
pub fn insert_foreign( &mut self, source_repo: impl Into<String>, commit: impl Into<String>, node: MemNode, ) -> NodeIndex
Convenience: insert a node under Partition::Foreign { source_repo, commit }.
Sourcepub fn link(
&mut self,
from: NodeIndex,
to: NodeIndex,
kind: EdgeKind,
weight: f32,
)
pub fn link( &mut self, from: NodeIndex, to: NodeIndex, kind: EdgeKind, weight: f32, )
Add a typed edge between two nodes.
Sourcepub fn supersede(
&mut self,
new_nix: NodeIndex,
old_fact_id: &str,
) -> HashSet<NodeIndex>
pub fn supersede( &mut self, new_nix: NodeIndex, old_fact_id: &str, ) -> HashSet<NodeIndex>
Supersede: mark old as FactSuperseded, add Supersedes edge, and cascade invalidation to any Conclusions citing this premise.
Sourcepub fn get_by_fact_id(&self, fact_id: &str) -> Option<(NodeIndex, &MemNode)>
pub fn get_by_fact_id(&self, fact_id: &str) -> Option<(NodeIndex, &MemNode)>
Lookup by fact_id.
Sourcepub fn valid_facts(&self) -> Vec<(NodeIndex, &MemNode)>
pub fn valid_facts(&self) -> Vec<(NodeIndex, &MemNode)>
Get all valid fact nodes.
Sourcepub fn constraints(&self) -> Vec<(NodeIndex, &MemNode)>
pub fn constraints(&self) -> Vec<(NodeIndex, &MemNode)>
Get all constraint fact nodes.
Sourcepub fn retrieve_ppr(
&self,
seeds: &[NodeIndex],
seed_weights: Option<&[f32]>,
damping: f32,
max_results: usize,
) -> Vec<RetrievalHit>
pub fn retrieve_ppr( &self, seeds: &[NodeIndex], seed_weights: Option<&[f32]>, damping: f32, max_results: usize, ) -> Vec<RetrievalHit>
Personalized PageRank retrieval from seed nodes (HippoRAG-inspired).
PPR propagates relevance from seed nodes through the graph with a damping factor that controls the balance between following edges and teleporting back to seeds. Converges to a stationary distribution in ~10-20 iterations.
Results are filtered to seeds’ partitions by default. Use
retrieve_ppr_cross_partition to traverse across the Project/Foreign
boundary.
Sourcepub fn retrieve_ppr_cross_partition(
&self,
seeds: &[NodeIndex],
seed_weights: Option<&[f32]>,
damping: f32,
max_results: usize,
) -> Vec<RetrievalHit>
pub fn retrieve_ppr_cross_partition( &self, seeds: &[NodeIndex], seed_weights: Option<&[f32]>, damping: f32, max_results: usize, ) -> Vec<RetrievalHit>
Like retrieve_ppr, but does NOT filter by partition — foreign nodes
can be reached from project seeds and vice versa. Caller opts in.
Sourcepub fn retrieve(
&self,
seeds: &[NodeIndex],
max_hops: usize,
max_results: usize,
decay: f32,
min_activation: f32,
) -> Vec<RetrievalHit>
pub fn retrieve( &self, seeds: &[NodeIndex], max_hops: usize, max_results: usize, decay: f32, min_activation: f32, ) -> Vec<RetrievalHit>
Legacy spreading activation retrieval from seed nodes.
Results are filtered to seeds’ partitions by default. Use
retrieve_cross_partition for opt-in cross-partition traversal.
Sourcepub fn retrieve_cross_partition(
&self,
seeds: &[NodeIndex],
max_hops: usize,
max_results: usize,
decay: f32,
min_activation: f32,
) -> Vec<RetrievalHit>
pub fn retrieve_cross_partition( &self, seeds: &[NodeIndex], max_hops: usize, max_results: usize, decay: f32, min_activation: f32, ) -> Vec<RetrievalHit>
Cross-partition variant of retrieve.
Sourcepub fn find_seeds_weighted(
&self,
query: &str,
max_seeds: usize,
) -> (Vec<NodeIndex>, Vec<f32>)
pub fn find_seeds_weighted( &self, query: &str, max_seeds: usize, ) -> (Vec<NodeIndex>, Vec<f32>)
Find seed nodes by keyword matching with IDF-weighted scores.
Returns (seeds, weights) where weights incorporate corpus IDF (term rarity),
stemming, synonym expansion, and content-type-aware tokenization.
Use the weights as seed_weights in retrieve_ppr().
Sourcepub fn find_seeds(&self, query: &str, max_seeds: usize) -> Vec<NodeIndex>
pub fn find_seeds(&self, query: &str, max_seeds: usize) -> Vec<NodeIndex>
Find seed nodes by keyword matching (unweighted, backward compat).
Sourcepub fn total_tokens(&self) -> usize
pub fn total_tokens(&self) -> usize
Total token count across all valid nodes.
Sourcepub fn valid_fact_count(&self) -> usize
pub fn valid_fact_count(&self) -> usize
Count of valid fact nodes.
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
Sourcepub fn gc_superseded(&mut self, max_depth: usize) -> usize
pub fn gc_superseded(&mut self, max_depth: usize) -> usize
Garbage-collect superseded/deprecated nodes beyond a retention depth.
Walks Supersedes chains from each FactSuperseded/SkillDeprecated node.
If the node is more than max_depth hops from any active (non-superseded)
ancestor, it is removed. Returns the number of nodes removed.
Sourcepub fn prune_expired(&mut self, now: DateTime<Utc>)
pub fn prune_expired(&mut self, now: DateTime<Utc>)
Remove expired environment nodes.
Sourcepub fn remove_conversation_nodes(&mut self, to_remove: &[NodeIndex])
pub fn remove_conversation_nodes(&mut self, to_remove: &[NodeIndex])
Remove a set of conversation/summary nodes and repair the temporal chain. After removal, re-links surviving conversation+summary nodes with TemporalNext edges.
pub fn clear(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MemoryGraph
impl RefUnwindSafe for MemoryGraph
impl Send for MemoryGraph
impl Sync for MemoryGraph
impl Unpin for MemoryGraph
impl UnsafeUnpin for MemoryGraph
impl UnwindSafe for MemoryGraph
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> 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