Skip to main content

Memory

Struct Memory 

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

Long-term memory. Depends only on traits (MemoryStore, Embedder, Scorer), so every piece is swappable. Cheap to clone; clones share everything.

Implementations§

Source§

impl Memory

Source

pub fn builder( store: Arc<dyn MemoryStore>, embedder: Arc<dyn Embedder>, ) -> MemoryBuilder

Source

pub fn new( store: impl MemoryStore + 'static, embedder: impl Embedder + 'static, ) -> Self

Memory with the default scorer, retention and identity scopes.

Source

pub fn store(&self) -> &Arc<dyn MemoryStore> ⓘ

Source

pub fn embedder(&self) -> &Arc<dyn Embedder> ⓘ

Source

pub fn extractor(&self) -> Option<&FactExtractor>

Source

pub fn scope_for(&self, session_id: &str) -> String

The scope for a session id.

Source

pub fn audience_for(&self, session_id: &str) -> RecallAudience

Who a session’s conversation reaches.

Source

pub async fn remember(&self, fact: NewFact) -> Result<UpsertOutcome>

Store a fact now. See Memory::remember_at.

Source

pub async fn remember_at( &self, fact: NewFact, now: DateTime<Utc>, ) -> Result<UpsertOutcome>

Normalize, embed and upsert a private fact as of now. An embedding failure stores the fact without a vector (lexical recall still finds it).

Source

pub async fn remember_with( &self, fact: NewFact, access: &FactAccess, ) -> Result<UpsertOutcome>

Store a fact now, stating who may see it.

Source

pub async fn forget( &self, scope: &str, category: &str, key: &str, ) -> Result<bool>

Supersede the active fact for this key. History is kept.

Source

pub async fn facts(&self, scope: &str) -> Result<Vec<Fact>>

Active facts in a scope, most recently updated first.

Source

pub async fn fact_history( &self, scope: &str, category: &str, key: &str, ) -> Result<Vec<Fact>>

Every version of a key, superseded ones included.

Source

pub async fn recall_facts( &self, scope: &str, query: &str, limit: usize, ) -> Result<Vec<ScoredFact>>

The facts most relevant to query, best first, as the owner in a direct conversation sees them. Each returned fact’s recall count is incremented. An empty query returns the most recently updated facts.

Use Memory::recall_facts_for for anything that reaches a channel.

Source

pub async fn recall_facts_for( &self, scope: &str, query: &str, limit: usize, audience: &RecallAudience, ) -> Result<Vec<ScoredFact>>

Memory::recall_facts limited to what audience may see. Restricted facts are dropped before ranking, so they neither fill the limit nor gain recall counts.

Source

pub async fn add_episode(&self, episode: NewEpisode) -> Result<Episode>

Store a private episode now.

Source

pub async fn add_episode_with( &self, episode: NewEpisode, access: &FactAccess, ) -> Result<Episode>

Store an episode now, stating who may see it.

Source

pub async fn recall_episodes( &self, scope: &str, query: &str, limit: usize, ) -> Result<Vec<ScoredEpisode>>

The episodes most relevant to query, best first, as the owner in a direct conversation sees them. Recall counts of returned episodes are incremented.

Source

pub async fn recall_episodes_for( &self, scope: &str, query: &str, limit: usize, audience: &RecallAudience, ) -> Result<Vec<ScoredEpisode>>

Memory::recall_episodes limited to what audience may see.

Source

pub async fn decay(&self, now: DateTime<Utc>) -> Result<DecayReport>

Apply recall decay and retention as of now. Meant to run about once a day; each call is one decay step.

Source

pub async fn stats(&self) -> Result<MemoryStats>

Source

pub async fn reembed_batch( &self, batch_size: usize, cursor: Option<&ReembedCursor>, ) -> Result<ReembedReport>

Give up to batch_size records (at most MAX_REEMBED_BATCH) a vector from the current embedder, starting at cursor (None starts a pass). Facts come first, then episodes.

Call it again with ReembedReport::next until that is None. The cursor only keeps a pass moving past records that could not be updated; records already done stop being stale, so a pass restarted from None after a crash picks up what is left. An embedder failure is an error and changes nothing: retry with the same cursor.

Source

pub async fn ingest_turn( &self, session_id: &str, run_id: Option<&str>, messages: &[Message], ) -> Result<IngestReport>

Extract durable facts from the latest user turn of messages and store them with provenance. Needs a FactExtractor.

Source

pub async fn summarize_session( &self, session_id: &str, messages: &[Message], receipts: &[Receipt], ) -> Result<(Episode, Usage)>

Summarize a session into an Episode and store it. Needs an EpisodeSummarizer.

Source

pub async fn ingest_run(&self, outcome: &RunOutcome) -> Result<IngestReport>

Explicit alternative to crate::MemoryWriter: extract facts from the run’s latest user turn (with a FactExtractor) and, for a completed run, store an episode (with an EpisodeSummarizer).

Trait Implementations§

Source§

impl Clone for Memory

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Memory

§

impl !UnwindSafe for Memory

§

impl Forget for Memory

§

impl Freeze for Memory
where *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze,

§

impl Move for Memory

§

impl Send for Memory
where Arc<Inner>: Send,

§

impl Sync for Memory
where Arc<Inner>: Sync,

§

impl Unpin for Memory
where Arc<Inner>: Unpin,

§

impl UnsafeUnpin for Memory
where *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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