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
impl Memory
pub fn builder( store: Arc<dyn MemoryStore>, embedder: Arc<dyn Embedder>, ) -> MemoryBuilder
Sourcepub fn new(
store: impl MemoryStore + 'static,
embedder: impl Embedder + 'static,
) -> Self
pub fn new( store: impl MemoryStore + 'static, embedder: impl Embedder + 'static, ) -> Self
Memory with the default scorer, retention and identity scopes.
pub fn store(&self) -> &Arc<dyn MemoryStore> ⓘ
pub fn embedder(&self) -> &Arc<dyn Embedder> ⓘ
pub fn extractor(&self) -> Option<&FactExtractor>
Sourcepub fn audience_for(&self, session_id: &str) -> RecallAudience
pub fn audience_for(&self, session_id: &str) -> RecallAudience
Who a session’s conversation reaches.
Sourcepub async fn remember(&self, fact: NewFact) -> Result<UpsertOutcome>
pub async fn remember(&self, fact: NewFact) -> Result<UpsertOutcome>
Store a fact now. See Memory::remember_at.
Sourcepub async fn remember_at(
&self,
fact: NewFact,
now: DateTime<Utc>,
) -> Result<UpsertOutcome>
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).
Sourcepub async fn remember_with(
&self,
fact: NewFact,
access: &FactAccess,
) -> Result<UpsertOutcome>
pub async fn remember_with( &self, fact: NewFact, access: &FactAccess, ) -> Result<UpsertOutcome>
Store a fact now, stating who may see it.
Sourcepub async fn forget(
&self,
scope: &str,
category: &str,
key: &str,
) -> Result<bool>
pub async fn forget( &self, scope: &str, category: &str, key: &str, ) -> Result<bool>
Supersede the active fact for this key. History is kept.
Sourcepub async fn facts(&self, scope: &str) -> Result<Vec<Fact>>
pub async fn facts(&self, scope: &str) -> Result<Vec<Fact>>
Active facts in a scope, most recently updated first.
Sourcepub async fn fact_history(
&self,
scope: &str,
category: &str,
key: &str,
) -> Result<Vec<Fact>>
pub async fn fact_history( &self, scope: &str, category: &str, key: &str, ) -> Result<Vec<Fact>>
Every version of a key, superseded ones included.
Sourcepub async fn recall_facts(
&self,
scope: &str,
query: &str,
limit: usize,
) -> Result<Vec<ScoredFact>>
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.
Sourcepub async fn recall_facts_for(
&self,
scope: &str,
query: &str,
limit: usize,
audience: &RecallAudience,
) -> Result<Vec<ScoredFact>>
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.
Sourcepub async fn add_episode(&self, episode: NewEpisode) -> Result<Episode>
pub async fn add_episode(&self, episode: NewEpisode) -> Result<Episode>
Store a private episode now.
Sourcepub async fn add_episode_with(
&self,
episode: NewEpisode,
access: &FactAccess,
) -> Result<Episode>
pub async fn add_episode_with( &self, episode: NewEpisode, access: &FactAccess, ) -> Result<Episode>
Store an episode now, stating who may see it.
Sourcepub async fn recall_episodes(
&self,
scope: &str,
query: &str,
limit: usize,
) -> Result<Vec<ScoredEpisode>>
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.
Sourcepub async fn recall_episodes_for(
&self,
scope: &str,
query: &str,
limit: usize,
audience: &RecallAudience,
) -> Result<Vec<ScoredEpisode>>
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.
Sourcepub async fn decay(&self, now: DateTime<Utc>) -> Result<DecayReport>
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.
pub async fn stats(&self) -> Result<MemoryStats>
Sourcepub async fn reembed_batch(
&self,
batch_size: usize,
cursor: Option<&ReembedCursor>,
) -> Result<ReembedReport>
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.
Sourcepub async fn ingest_turn(
&self,
session_id: &str,
run_id: Option<&str>,
messages: &[Message],
) -> Result<IngestReport>
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.
Sourcepub async fn summarize_session(
&self,
session_id: &str,
messages: &[Message],
receipts: &[Receipt],
) -> Result<(Episode, Usage)>
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.
Sourcepub async fn ingest_run(&self, outcome: &RunOutcome) -> Result<IngestReport>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Memory
impl !UnwindSafe for Memory
impl Forget for Memory
impl Freeze for Memory
impl Move for Memory
impl Send for Memory
impl Sync for Memory
impl Unpin for Memory
impl UnsafeUnpin for Memory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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