Memory

Struct Memory 

Source
pub struct Memory<L: LLMProvider, E: EmbeddingProvider, S: StorageBackend, V: VectorBackend> { /* private fields */ }
Expand description

Main interface for Umi memory system.

Orchestrates all components for a simple remember/recall API.

§Type Parameters

  • L: LLM provider for extraction, retrieval, evolution (SimLLMProvider for testing)
  • S: Storage backend for persistence (SimStorageBackend for testing)

§Example

use umi_memory::umi::{Memory, RememberOptions, RecallOptions};
use umi_memory::{SimLLMProvider, SimStorageBackend, SimConfig};

let llm = SimLLMProvider::with_seed(42);
let embedder = SimEmbeddingProvider::with_seed(42);
let vector = SimVectorBackend::new(42);
let storage = SimStorageBackend::new(SimConfig::with_seed(42));
let mut memory = Memory::new(llm, embedder, vector, storage);

// Store and retrieve memories
memory.remember("Alice works at Acme", RememberOptions::default()).await?;
let results = memory.recall("Alice", RecallOptions::default()).await?;

Implementations§

Source§

impl<L: LLMProvider + Clone, E: EmbeddingProvider + Clone, S: StorageBackend + Clone, V: VectorBackend + Clone> Memory<L, E, S, V>

Source

pub fn new(llm: L, embedder: E, vector: V, storage: S) -> Self

Create a new Memory with all components.

§Arguments
  • llm - LLM provider (cloned for each component)
  • embedder - Embedding provider (cloned for retriever)
  • vector - Vector backend for similarity search
  • storage - Storage backend (cloned for retriever)
Source

pub fn builder() -> MemoryBuilder<L, E, V, S>

Create a MemoryBuilder for constructing Memory with builder pattern.

§Example
let memory = Memory::builder()
    .with_llm(llm)
    .with_embedder(embedder)
    .with_vector(vector)
    .with_storage(storage)
    .build();
Source

pub async fn remember( &mut self, text: &str, options: RememberOptions, ) -> Result<RememberResult, MemoryError>

Store information in memory.

Extracts entities from text using LLM and stores them. Optionally detects evolution relationships with existing memories.

§Arguments
  • text - Text to remember
  • options - Remember options
§Returns

Ok(RememberResult) with stored entities and detected evolutions, Err(MemoryError) for validation errors.

§Graceful Degradation
  • If extraction fails, falls back to storing raw text as Note
  • If evolution detection fails, skips without error
Source

pub async fn recall( &self, query: &str, options: RecallOptions, ) -> Result<Vec<Entity>, MemoryError>

Retrieve memories matching query.

Uses DualRetriever for smart search:

  • Fast path: Direct search in storage
  • Deep path: LLM rewrites query into variations, merges results
§Arguments
  • query - Search query
  • options - Recall options
§Returns

Ok(Vec<Entity>) with matching entities, Err(MemoryError) for validation errors.

Source

pub async fn forget(&mut self, entity_id: &str) -> Result<bool, MemoryError>

Delete entity by ID.

§Arguments
  • entity_id - ID of entity to delete
§Returns

Ok(true) if deleted, Ok(false) if not found.

Source

pub async fn get(&self, entity_id: &str) -> Result<Option<Entity>, MemoryError>

Get entity by ID.

§Arguments
  • entity_id - Entity ID
§Returns

Ok(Some(Entity)) if found, Ok(None) otherwise.

Source

pub async fn count(&self) -> Result<usize, MemoryError>

Count total entities in storage.

Source

pub fn storage(&self) -> &S

Get reference to storage backend.

Source§

impl Memory<SimLLMProvider, SimEmbeddingProvider, SimStorageBackend, SimVectorBackend>

Source

pub fn sim(seed: u64) -> Self

Create a deterministic simulation Memory for testing.

All components (LLM, embedder, vector, storage) use the same seed for reproducible behavior.

TigerStyle: Convenient constructor for tests.

§Arguments
  • seed - Random seed for deterministic behavior
§Example
use umi_memory::umi::Memory;

let memory = Memory::sim(42);
// All operations will be deterministic with same seed
Source

pub fn sim_with_config(_seed: u64, _config: MemoryConfig) -> Self

Create a deterministic simulation Memory with custom configuration.

Combines the convenience of sim() with custom config.

TigerStyle: Convenient constructor for configured tests.

§Arguments
  • seed - Random seed for deterministic behavior
  • config - Custom configuration
§Example
use umi_memory::umi::{Memory, MemoryConfig};

let config = MemoryConfig::default().with_recall_limit(5);
let memory = Memory::sim_with_config(42, config);

Auto Trait Implementations§

§

impl<L, E, S, V> Freeze for Memory<L, E, S, V>
where S: Freeze, E: Freeze, V: Freeze, L: Freeze,

§

impl<L, E, S, V> RefUnwindSafe for Memory<L, E, S, V>

§

impl<L, E, S, V> Send for Memory<L, E, S, V>

§

impl<L, E, S, V> Sync for Memory<L, E, S, V>

§

impl<L, E, S, V> Unpin for Memory<L, E, S, V>
where S: Unpin, E: Unpin, V: Unpin, L: Unpin,

§

impl<L, E, S, V> UnwindSafe for Memory<L, E, S, V>

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