pub struct Memory { /* private fields */ }Expand description
The memory API over one engine.
Safe to share across threads. Policy plans use revision-conditional commits; reads retry
when their document and policy snapshots differ. Persistent commits are serialized.
Several Memory values over one core stay correct: each notices the others’ writes by
the store revision and rebuilds its index, at the cost of one scan.
Implementations§
Source§impl Memory
impl Memory
pub fn capabilities(&self) -> MemoryCapabilities
Sourcepub fn call(&self, op: &str, request: Value) -> Result<Value>
pub fn call(&self, op: &str, request: Value) -> Result<Value>
Runs one operation from its JSON request and returns its JSON response.
| op | request | response |
|---|---|---|
remember | a RememberInput, or {"facts": [..]} | {"remembered": [Remembered]} |
recall | {"query", ..RecallOptions} | {"results": [Recalled]} |
explain | {"query", "id", ..RecallOptions} | {"explanation": Explanation} |
forget | {"scope": ForgetScope, ..ForgetOptions} | ForgetReport |
get | {"id"} | {"fact": FactRecord or null} |
history | {"id"} | {"history": [FactRecord]} |
applyForgetting | ForgetOptions | ForgetReport |
consolidate | ConsolidateOptions | ConsolidationReport |
Errors that the caller can fix (bad fields, unknown ids, id conflicts) are
MemoryErrors; anything else is an internal failure.
Source§impl Memory
impl Memory
Sourcepub fn summaries(&self, with_text: bool) -> Vec<FactSummary>
pub fn summaries(&self, with_text: bool) -> Vec<FactSummary>
Every stored fact as a maintenance policy sees it, ordered by id. Plain documents
(without memory fields) are not facts and are left out.
Panics when concurrent writes prevent a coherent snapshot; use Self::try_summaries
to handle that retryable failure.
pub fn try_summaries(&self, with_text: bool) -> Result<Vec<FactSummary>>
Sourcepub fn apply_forgetting(&self, options: &ForgetOptions) -> Result<ForgetReport>
pub fn apply_forgetting(&self, options: &ForgetOptions) -> Result<ForgetReport>
Forgets what the configured forgetting policy selects. With the default policy that is nothing.
pub fn apply_forgetting_with( &self, policy: &dyn ForgettingPolicy, options: &ForgetOptions, ) -> Result<ForgetReport>
Sourcepub fn consolidate(
&self,
options: &ConsolidateOptions,
) -> Result<ConsolidationReport>
pub fn consolidate( &self, options: &ConsolidateOptions, ) -> Result<ConsolidationReport>
Runs the configured consolidation policy. With the default policy that is nothing.
Sourcepub fn consolidate_with(
&self,
policy: &dyn ConsolidationPolicy,
options: &ConsolidateOptions,
) -> Result<ConsolidationReport>
pub fn consolidate_with( &self, policy: &dyn ConsolidationPolicy, options: &ConsolidateOptions, ) -> Result<ConsolidationReport>
Writes each planned summary as a fact that supersedes its sources, so the sources stay
as history. Sources are removed only when the action asks and allow_destructive is
set. Summary ids derive from their sources, so repeating a run adds nothing.
Source§impl Memory
impl Memory
Sourcepub fn recall(
&self,
query: &str,
options: &RecallOptions,
) -> Result<Vec<Recalled>>
pub fn recall( &self, query: &str, options: &RecallOptions, ) -> Result<Vec<Recalled>>
Facts relevant to query, best first.
By default only facts that are current now are returned, ranked as document search
ranks them. options selects history, an as_of or known_at time, a subject or
entities, and per-result explanations.
Sourcepub fn explain(
&self,
query: &str,
id: &str,
options: &RecallOptions,
) -> Result<Explanation>
pub fn explain( &self, query: &str, id: &str, options: &RecallOptions, ) -> Result<Explanation>
Why id does or does not come back for query: its lexical and semantic scores,
matched terms, recency and validity adjustments and supersession chain.
The rank is among the ranked candidates with history included, so it can differ from
the position in a current-only recall. A fact outside the candidates is still
explained, with retrieved: false.
Source§impl Memory
impl Memory
Sourcepub fn remember(&self, input: RememberInput) -> Result<Remembered>
pub fn remember(&self, input: RememberInput) -> Result<Remembered>
Remembers one fact. See Memory::remember_many.
Sourcepub fn remember_many(
&self,
inputs: Vec<RememberInput>,
) -> Result<Vec<Remembered>>
pub fn remember_many( &self, inputs: Vec<RememberInput>, ) -> Result<Vec<Remembered>>
Remembers facts in one atomic transaction: every fact is stored or none is. Later
inputs see earlier ones for supersession. Retrying a call is safe: a fact whose id and
content already match is reported with created: false and stored once. Without an
explicit id the id is a hash of the content, so a retried call is still idempotent.
Sourcepub fn forget(
&self,
scope: &ForgetScope,
options: &ForgetOptions,
) -> Result<ForgetReport>
pub fn forget( &self, scope: &ForgetScope, options: &ForgetOptions, ) -> Result<ForgetReport>
Removes facts. Idempotent: repeating a call removes nothing more. Removal is one journal transaction per 4096 facts, so a crash between transactions leaves a prefix removed and the same call finishes the rest.
Without include_chain only the matched facts go, and a removed successor makes its
predecessor current again. Deleted text stays in the append-only journal until the
store compacts. The text segment is zeroed and synced once before this returns; purge
then compacts and overwrites what the compaction replaced.
Source§impl Memory
impl Memory
Sourcepub fn new(core: Arc<WarmCore>) -> Self
pub fn new(core: Arc<WarmCore>) -> Self
A memory over core with the default, do-nothing policies.
pub fn with_config(core: Arc<WarmCore>, config: MemoryConfig) -> Result<Self>
Sourcepub fn with_supersession(self, policy: Arc<dyn SupersessionPolicy>) -> Self
pub fn with_supersession(self, policy: Arc<dyn SupersessionPolicy>) -> Self
Replaces the supersession policy.
pub fn with_recency(self, policy: Arc<dyn RecencyPolicy>) -> Self
pub fn with_forgetting(self, policy: Arc<dyn ForgettingPolicy>) -> Self
pub fn with_consolidation(self, policy: Arc<dyn ConsolidationPolicy>) -> Self
pub fn with_entity_extractor(self, extractor: Arc<dyn EntityExtractor>) -> Self
pub fn with_observer(self, observer: Arc<dyn MemoryObserver>) -> Self
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
Replaces the clock, for deterministic ingest times.
pub fn config(&self) -> &MemoryConfig
Auto Trait Implementations§
impl !Freeze for Memory
impl !RefUnwindSafe for Memory
impl !UnwindSafe 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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.