Skip to main content

IneruMemory

Struct IneruMemory 

Source
pub struct IneruMemory {
    pub stm: ShortTermMemory,
    pub ltm: LongTermMemory,
    /* private fields */
}
Expand description

The main interface for the Ineru memory system.

This struct integrates a ShortTermMemory (STM) and a LongTermMemory (LTM) to provide a comprehensive, neural-inspired memory solution for AI agents.

Fields§

§stm: ShortTermMemory

The fast, volatile, and bounded Short-Term Memory.

§ltm: LongTermMemory

The persistent, graph-based Long-Term Memory.

Implementations§

Source§

impl IneruMemory

Source

pub fn new(config: MemoryConfig) -> Self

Creates a new IneruMemory system with the given configuration.

§Arguments
  • config - The MemoryConfig that defines the behavior and capacity of the STM, LTM, and consolidation process.
Source

pub fn iot_mode() -> Self

Creates a new IneruMemory system with defaults optimized for IoT devices.

This configuration prioritizes a low memory footprint.

Source

pub fn agent_mode() -> Self

Creates a new IneruMemory system with defaults optimized for general AI agents.

This configuration provides a balanced trade-off between performance and memory usage.

Source

pub fn remember(&mut self, entry: MemoryEntry) -> Result<MemoryId>

Stores a new MemoryEntry in the Short-Term Memory.

All memories begin their lifecycle in the STM. They may be moved to LTM later during consolidation if they are deemed important.

§Arguments
  • entry - The MemoryEntry to store.
§Returns

A Result containing the unique MemoryId assigned to the new entry.

Source

pub fn remember_important( &mut self, entry: MemoryEntry, importance: f32, ) -> Result<MemoryId>

Stores a new MemoryEntry with an explicit importance score.

§Arguments
  • entry - The MemoryEntry to store.
  • importance - A float score determining the entry’s importance. Higher values make it more likely to be consolidated into LTM.
§Returns

A Result containing the unique MemoryId assigned to the new entry.

Source

pub fn recall(&self, query: &MemoryQuery) -> Result<Vec<MemoryResult>>

Recalls a list of memories that match a given MemoryQuery.

This method searches both STM and LTM, combining the results and sorting them by relevance.

§Arguments
  • query - The MemoryQuery to execute.
§Returns

A Result containing a vector of MemoryResult structs, sorted by relevance.

Source

pub fn recall_text(&self, query_text: &str) -> Result<Vec<MemoryResult>>

Recalls memories based on a semantic text query.

A shorthand for creating a MemoryQuery::text and calling recall.

§Arguments
  • query_text - The text to search for.
Source

pub fn recall_tagged(&self, tags: &[&str]) -> Result<Vec<MemoryResult>>

Recalls memories based on a set of semantic tags.

A shorthand for creating a MemoryQuery::tags and calling recall.

§Arguments
  • tags - A slice of string slices, where each string is a tag to query.
Source

pub fn recall_recent(&self, count: usize) -> Result<Vec<MemoryResult>>

Recalls the count most recent memories from STM.

Source

pub fn consolidate(&mut self) -> Result<usize>

Runs the consolidation process, moving important memories from STM to LTM.

This process identifies important entries in STM based on criteria defined in the ConsolidationConfig and transfers them to LTM for long-term storage.

This should be called periodically (e.g., every few minutes or on idle).

§Returns

A Result containing the number of entries that were successfully consolidated.

Source

pub fn consolidate_memory(&mut self, id: &MemoryId) -> Result<()>

Forces a specific memory entry to be consolidated from STM to LTM.

If the memory exists in STM, it will be moved to LTM and removed from STM.

§Arguments
  • id - The MemoryId of the entry to consolidate.
Source

pub fn get(&self, id: &MemoryId) -> Result<Option<MemoryEntry>>

Retrieves a MemoryEntry by its ID from either STM or LTM.

It checks STM first, then LTM.

§Arguments
  • id - The MemoryId of the entry to retrieve.
§Returns

A Result containing an Option<MemoryEntry>. Returns Some(entry) if found, None otherwise.

Source

pub fn forget(&mut self, id: &MemoryId) -> Result<()>

Forgets a memory, removing it from both STM and LTM.

§Arguments
  • id - The MemoryId of the entry to remove.
Source

pub fn decay(&mut self) -> Result<()>

Applies a decay factor to memories in STM, reducing their importance over time.

This helps ensure that only persistently important memories are consolidated.

Source

pub fn prune_stm(&mut self) -> Result<usize>

Prunes the STM if it has exceeded its configured capacity.

This removes the least important entries until the memory is within its limit.

§Returns

A Result containing the number of entries pruned.

Source

pub fn stats(&self) -> MemoryStats

Gathers and returns statistics about the current state of the memory system.

Source

pub fn clear(&mut self) -> Result<()>

Clears all memories from both STM and LTM.

Source§

impl IneruMemory

Source

pub fn export_snapshot(&self) -> Result<Vec<u8>>

Exports the current memory state as a JSON byte vector.

Source

pub fn import_snapshot(data: &[u8]) -> Result<Self>

Imports a memory state from a JSON byte slice.

Source

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

Saves the current memory state to a file (with fsync for durability).

Source

pub fn load_from_file(path: &Path) -> Result<Self>

Loads a memory state from a file.

Trait Implementations§

Source§

impl Default for IneruMemory

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