Skip to main content

MemoryGraph

Struct MemoryGraph 

Source
pub struct MemoryGraph {
    pub entries: HashMap<String, MemoryEntry>,
}
Expand description

In-memory graph of memory entries keyed by ID.

Fields§

§entries: HashMap<String, MemoryEntry>

Implementations§

Source§

impl MemoryGraph

Source

pub fn new() -> Self

Create an empty memory graph.

Source

pub fn load(path: &Path) -> Self

Load a graph from a JSON file. Returns an empty graph if the file is missing or unparseable, so a missing/corrupt store never blocks startup.

Source

pub fn save(&self, path: &Path) -> Result<()>

Persist the graph to a JSON file (creating parent directories).

Source

pub fn insert(&mut self, entry: MemoryEntry)

Insert a memory entry into the graph.

Source

pub fn remember_keyed(&mut self, entry: MemoryEntry)

Insert an entry, deterministically superseding any active entry with the same key (latest-wins). Superseded entries are kept (active=false) for audit/restore — never hard-deleted. Unkeyed entries just insert.

Source

pub fn list_all(&self) -> Vec<&MemoryEntry>

All entries (including inactive/superseded), newest first — for /memory --all and recovery.

Source

pub fn restore(&mut self, id: &str) -> bool

Reactivate a previously superseded/deactivated entry by id. Clears its superseded_by link. Returns true if the entry existed.

Source

pub fn get_mut(&mut self, id: &str) -> Option<&mut MemoryEntry>

Get a mutable reference to a memory entry by ID.

Source

pub fn forget(&mut self, id: &str) -> bool

Permanently remove a memory entry by ID. Returns true if one was removed.

Source

pub fn deactivate(&mut self, id: &str) -> bool

Soft-deactivate a memory entry by ID (marks inactive, keeps for audit). Returns true if the entry existed and was active.

Source

pub fn prune(&mut self, max_entries: usize)

Bound the graph: drop expired entries first, then (if still over max_entries) the lowest effective-confidence ones, until at the cap. Keeps long-term memory and disk usage bounded on small servers.

Source

pub fn search(&self, query: &str, limit: usize) -> Vec<&MemoryEntry>

Search active entries by lexical relevance (TF-IDF/BM25-lite over content+tags) blended with effective confidence, then truncate to limit. Dep-free (no vector store) — fits resource-constrained hosts. Multi-word / partial-overlap queries recall far better than a whole-query substring match. Falls back to whole-query substring for very short queries.

Source

pub fn linked(&self, id: &str) -> Vec<&MemoryEntry>

Return all entries directly linked to the given entry.

Source

pub fn supersede(&mut self, old_id: &str, new_id: &str)

Replace an old entry with a new one and create a bidirectional link.

Source

pub fn decay_all(&mut self, amount: f32)

Decay confidence of all active entries by amount.

Source

pub fn prune_inactive(&mut self) -> usize

Remove inactive entries that have not been accessed in 30 days.

Source

pub fn neighbors(&self, id: &str, max_hops: usize) -> Vec<&MemoryEntry>

BFS traversal of reinforcement-related entries up to max_hops hops.

Source

pub fn search_by_tag(&self, tag: &str) -> Vec<&MemoryEntry>

Search entries whose category or trust matches the given tag string.

Source

pub fn prune_stale(&mut self, max_age_days: u64) -> usize

Remove external-trust entries not accessed within max_age_days.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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