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
impl LongTermMemory
Sourcepub fn new(config: LtmConfig) -> Self
pub fn new(config: LtmConfig) -> Self
Creates a new, empty LongTermMemory with the given configuration.
Sourcepub fn store(&mut self, entry: MemoryEntry) -> Result<MemoryId>
pub fn store(&mut self, entry: MemoryEntry) -> Result<MemoryId>
Sourcepub fn get(&self, id: &MemoryId) -> Result<Option<MemoryEntry>>
pub fn get(&self, id: &MemoryId) -> Result<Option<MemoryEntry>>
Retrieves a MemoryEntry by its ID.
Sourcepub fn query(&self, query: &MemoryQuery) -> Result<Vec<MemoryResult>>
pub fn query(&self, query: &MemoryQuery) -> Result<Vec<MemoryResult>>
Queries the LTM for memories matching the given MemoryQuery.
Sourcepub fn add_entity(&mut self, entity: Entity) -> Result<EntityId>
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.
Sourcepub fn get_entity(&self, id: &EntityId) -> Option<&Entity>
pub fn get_entity(&self, id: &EntityId) -> Option<&Entity>
Retrieves an Entity by its ID from the knowledge graph.
Sourcepub fn add_link(&mut self, link: Link) -> Result<()>
pub fn add_link(&mut self, link: Link) -> Result<()>
Adds a new Link between two entities in the knowledge graph.
Sourcepub fn get_links_from(&self, id: &EntityId) -> Vec<&Link>
pub fn get_links_from(&self, id: &EntityId) -> Vec<&Link>
Retrieves all outgoing links from a given entity.
Sourcepub fn get_links_to(&self, id: &EntityId) -> Vec<&Link>
pub fn get_links_to(&self, id: &EntityId) -> Vec<&Link>
Retrieves all incoming links to a given entity.
Sourcepub fn find_entities_by_type(&self, entity_type: &str) -> Vec<&Entity>
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- TheEntityIdof the starting entity.relation- An optionalRelationto filter the links by.
Sourcepub fn semantic_search(
&self,
query_embedding: &Embedding,
limit: usize,
) -> Vec<(&Entity, f32)>
pub fn semantic_search( &self, query_embedding: &Embedding, limit: usize, ) -> Vec<(&Entity, f32)>
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.
Sourcepub fn memory_count(&self) -> usize
pub fn memory_count(&self) -> usize
Returns the number of memory entries stored in the LTM.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Returns the number of entities in the knowledge graph.
Sourcepub fn link_count(&self) -> usize
pub fn link_count(&self) -> usize
Returns the total number of links in the knowledge graph.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Returns the estimated memory usage of the LTM in bytes.