Skip to main content

LongTermMemory

Struct LongTermMemory 

Source
pub struct LongTermMemory { /* private fields */ }
Expand description

A persistent, graph-based Long-Term Memory store.

LTM is responsible for storing consolidated memories and the knowledge graph extracted from them. It uses indices for efficient querying.

Implementations§

Source§

impl LongTermMemory

Source

pub fn new(config: LtmConfig) -> Self

Creates a new, empty LongTermMemory with the given configuration.

Source

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

Stores a MemoryEntry in the LTM, typically after consolidation from STM.

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

A Result containing the MemoryId of the stored entry.

Source

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

Retrieves a MemoryEntry by its ID.

Source

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

Removes a MemoryEntry from the LTM.

Source

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

Queries the LTM for memories matching the given MemoryQuery.

Source

pub fn add_entity(&mut self, entity: Entity) -> Result<EntityId>

Adds a new Entity to the knowledge graph.

§Returns

A Result containing the EntityId of the newly added entity.

Source

pub fn get_entity(&self, id: &EntityId) -> Option<&Entity>

Retrieves an Entity by its ID from the knowledge graph.

Adds a new Link between two entities in the knowledge graph.

Retrieves all outgoing links from a given entity.

Retrieves all incoming links to a given entity.

Source

pub fn find_entities_by_type(&self, entity_type: &str) -> Vec<&Entity>

Finds all entities of a specific type.

Finds all entities related to a given entity (1-hop neighbors).

§Arguments
  • id - The EntityId of the starting entity.
  • relation - An optional Relation to filter the links by.
Source

pub fn traverse( &self, start: &EntityId, max_depth: usize, ) -> Vec<(&Entity, usize)>

Traverses the knowledge graph starting from a given entity (using BFS).

§Arguments
  • start - The EntityId to start the traversal from.
  • max_depth - The maximum depth to traverse.
§Returns

A vector of tuples, where each tuple contains a reference to an Entity and its depth from the starting entity.

Performs a semantic search over entities using embedding vectors.

§Arguments
  • query_embedding - The embedding vector to search with.
  • limit - The maximum number of results to return.
§Returns

A vector of tuples, where each tuple contains a reference to a matching Entity and its cosine similarity score. Returns an empty vector if embeddings are disabled.

Source

pub fn memory_count(&self) -> usize

Returns the number of memory entries stored in the LTM.

Source

pub fn entity_count(&self) -> usize

Returns the number of entities in the knowledge graph.

Returns the total number of links in the knowledge graph.

Source

pub fn memory_usage(&self) -> usize

Returns the estimated memory usage of the LTM in bytes.

Source

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

Clears all data from the LTM, including memories, entities, and links.

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.