Skip to main content

Memory

Struct Memory 

Source
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

Source

pub fn capabilities(&self) -> MemoryCapabilities

Source

pub fn call(&self, op: &str, request: Value) -> Result<Value>

Runs one operation from its JSON request and returns its JSON response.

oprequestresponse
remembera 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]}
applyForgettingForgetOptionsForgetReport
consolidateConsolidateOptionsConsolidationReport

Errors that the caller can fix (bad fields, unknown ids, id conflicts) are MemoryErrors; anything else is an internal failure.

Source§

impl Memory

Source

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.

Source

pub fn try_summaries(&self, with_text: bool) -> Result<Vec<FactSummary>>

Source

pub fn apply_forgetting(&self, options: &ForgetOptions) -> Result<ForgetReport>

Forgets what the configured forgetting policy selects. With the default policy that is nothing.

Source

pub fn apply_forgetting_with( &self, policy: &dyn ForgettingPolicy, options: &ForgetOptions, ) -> Result<ForgetReport>

Source

pub fn consolidate( &self, options: &ConsolidateOptions, ) -> Result<ConsolidationReport>

Runs the configured consolidation policy. With the default policy that is nothing.

Source

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

Source

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.

Source

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

pub fn get(&self, id: &str) -> Result<Option<FactRecord>>

One stored fact, or none.

Source

pub fn history(&self, id: &str) -> Result<Vec<FactRecord>>

Every version of the fact id belongs to: it, what it superseded and what superseded it, in effect order, each with its status now.

Source§

impl Memory

Source

pub fn remember(&self, input: RememberInput) -> Result<Remembered>

Remembers one fact. See Memory::remember_many.

Source

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.

Source

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

Source

pub fn new(core: Arc<WarmCore>) -> Self

A memory over core with the default, do-nothing policies.

Source

pub fn with_config(core: Arc<WarmCore>, config: MemoryConfig) -> Result<Self>

Source

pub fn with_supersession(self, policy: Arc<dyn SupersessionPolicy>) -> Self

Replaces the supersession policy.

Source

pub fn with_recency(self, policy: Arc<dyn RecencyPolicy>) -> Self

Source

pub fn with_forgetting(self, policy: Arc<dyn ForgettingPolicy>) -> Self

Source

pub fn with_consolidation(self, policy: Arc<dyn ConsolidationPolicy>) -> Self

Source

pub fn with_entity_extractor(self, extractor: Arc<dyn EntityExtractor>) -> Self

Source

pub fn with_observer(self, observer: Arc<dyn MemoryObserver>) -> Self

Source

pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self

Replaces the clock, for deterministic ingest times.

Source

pub fn config(&self) -> &MemoryConfig

Source

pub fn core(&self) -> &Arc<WarmCore> ⓘ

The engine underneath, for documents, vectors and raw search. Facts are documents with the fact id as the document id.

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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