Skip to main content

MemoryGraph

Struct MemoryGraph 

Source
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

Source

pub fn new() -> Self

Source

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

Source

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.

Source

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

Source

pub fn insert(&mut self, node: MemNode) -> NodeIndex

Insert a node and index it.

Add a typed edge between two nodes.

Source

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.

Source

pub fn get_by_fact_id(&self, fact_id: &str) -> Option<(NodeIndex, &MemNode)>

Lookup by fact_id.

Source

pub fn valid_facts(&self) -> Vec<(NodeIndex, &MemNode)>

Get all valid fact nodes.

Source

pub fn constraints(&self) -> Vec<(NodeIndex, &MemNode)>

Get all constraint fact nodes.

Source

pub fn nodes_by_layer(&self, layer: Layer) -> Vec<(NodeIndex, &MemNode)>

Get nodes by layer.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn find_seeds(&self, query: &str, max_seeds: usize) -> Vec<NodeIndex>

Find seed nodes by keyword matching (unweighted, backward compat).

Source

pub fn total_tokens(&self) -> usize

Total token count across all valid nodes.

Source

pub fn valid_fact_count(&self) -> usize

Count of valid fact nodes.

Source

pub fn node_count(&self) -> usize

Source

pub fn edge_count(&self) -> usize

Source

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.

Source

pub fn prune_expired(&mut self, now: DateTime<Utc>)

Remove expired environment nodes.

Source

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.

Source

pub fn clear(&mut self)

Trait Implementations§

Source§

impl Default for MemoryGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,