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: ShortTermMemoryThe fast, volatile, and bounded Short-Term Memory.
ltm: LongTermMemoryThe persistent, graph-based Long-Term Memory.
Implementations§
Source§impl IneruMemory
impl IneruMemory
Sourcepub fn new(config: MemoryConfig) -> Self
pub fn new(config: MemoryConfig) -> Self
Creates a new IneruMemory system with the given configuration.
§Arguments
config- TheMemoryConfigthat defines the behavior and capacity of the STM, LTM, and consolidation process.
Sourcepub fn iot_mode() -> Self
pub fn iot_mode() -> Self
Creates a new IneruMemory system with defaults optimized for IoT devices.
This configuration prioritizes a low memory footprint.
Sourcepub fn agent_mode() -> Self
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.
Sourcepub fn remember(&mut self, entry: MemoryEntry) -> Result<MemoryId>
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- TheMemoryEntryto store.
§Returns
A Result containing the unique MemoryId assigned to the new entry.
Sourcepub fn remember_important(
&mut self,
entry: MemoryEntry,
importance: f32,
) -> Result<MemoryId>
pub fn remember_important( &mut self, entry: MemoryEntry, importance: f32, ) -> Result<MemoryId>
Stores a new MemoryEntry with an explicit importance score.
§Arguments
entry- TheMemoryEntryto 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.
Sourcepub fn recall(&self, query: &MemoryQuery) -> Result<Vec<MemoryResult>>
pub fn recall(&self, query: &MemoryQuery) -> Result<Vec<MemoryResult>>
Sourcepub fn recall_text(&self, query_text: &str) -> Result<Vec<MemoryResult>>
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.
Sourcepub fn recall_tagged(&self, tags: &[&str]) -> Result<Vec<MemoryResult>>
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.
Sourcepub fn recall_recent(&self, count: usize) -> Result<Vec<MemoryResult>>
pub fn recall_recent(&self, count: usize) -> Result<Vec<MemoryResult>>
Recalls the count most recent memories from STM.
Sourcepub fn consolidate(&mut self) -> Result<usize>
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.
Sourcepub fn consolidate_memory(&mut self, id: &MemoryId) -> Result<()>
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- TheMemoryIdof the entry to consolidate.
Sourcepub fn forget(&mut self, id: &MemoryId) -> Result<()>
pub fn forget(&mut self, id: &MemoryId) -> Result<()>
Forgets a memory, removing it from both STM and LTM.
§Arguments
id- TheMemoryIdof the entry to remove.
Sourcepub fn decay(&mut self) -> Result<()>
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.
Sourcepub fn prune_stm(&mut self) -> Result<usize>
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.
Sourcepub fn stats(&self) -> MemoryStats
pub fn stats(&self) -> MemoryStats
Gathers and returns statistics about the current state of the memory system.
Source§impl IneruMemory
impl IneruMemory
Sourcepub fn export_snapshot(&self) -> Result<Vec<u8>>
pub fn export_snapshot(&self) -> Result<Vec<u8>>
Exports the current memory state as a JSON byte vector.
Sourcepub fn import_snapshot(data: &[u8]) -> Result<Self>
pub fn import_snapshot(data: &[u8]) -> Result<Self>
Imports a memory state from a JSON byte slice.
Sourcepub fn save_to_file(&self, path: &Path) -> Result<()>
pub fn save_to_file(&self, path: &Path) -> Result<()>
Saves the current memory state to a file (with fsync for durability).
Sourcepub fn load_from_file(path: &Path) -> Result<Self>
pub fn load_from_file(path: &Path) -> Result<Self>
Loads a memory state from a file.