MemorySession

Struct MemorySession 

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

Everything scoped to one logical conversation.

Implementations§

Source§

impl MemorySession

Source

pub fn session_id(&self) -> &SessionId

The logical conversation this session represents.

Source

pub fn ledger(&self) -> &Arc<InMemorySessionLedger>

The candidate ledger.

Source

pub fn retriever(&self) -> &Arc<LocalMemoryRetriever>

The retriever serving this session.

Source

pub fn memory_map(&self) -> String

The vocabulary a model needs in order to fill recall_context’s about and attribute fields.

Put this in the system instruction. Without it a model names the right predicate 2% of the time, which is below the 8% at which filtering starts paying for itself; with it, 69%. It is a few hundred tokens and bounded by the user’s vocabulary rather than by how much they have accumulated — 282 tokens at 16,000 records. See crate::retrieval::vocabulary.

Recomputed only when the canonical index has moved, so calling this every turn is cheap.

Source

pub fn config(&self) -> &MemoryRuntimeConfig

The runtime configuration this session was opened with.

Source

pub fn begin_turn(&self, turn_id: TurnId) -> u64

Freeze the prepared snapshot for a turn that is starting.

Everything the model is answered with for this turn comes from the snapshot taken here, so a retrieval landing mid-response cannot change what B appears to remember halfway through a sentence.

Source

pub fn current_turn(&self) -> TurnId

The turn currently in flight.

Source

pub fn active_snapshot(&self) -> PreparedMemorySnapshot

The snapshot the current turn is being answered from.

Source

pub fn prepared_snapshot(&self) -> PreparedMemorySnapshot

The most recently prepared snapshot, whether or not a turn is using it.

Source

pub fn generation(&self) -> &GenerationGuard

The generation guard, for cancelling stale speculative work.

Source

pub async fn prepare( &self, turn_id: TurnId, transcript: &str, ) -> Result<PreparedMemorySnapshot, MemoryError>

Prepare context speculatively from a transcript.

Publishes the resulting snapshot only if the conversation has not moved on since the work started.

Source

pub async fn recall(&self, query: &str, turn_id: TurnId) -> Value

Serve a recall_context tool call.

Reads the frozen snapshot when it plainly covers the query, and otherwise runs a live local search and fuses the snapshot into it. The search is bounded and never reaches the network.

The fusion is the part worth explaining. satisfies decides the fast path by word overlap between the question and the prepared statements — which is the right test for “can I skip the search entirely” and the wrong one for “is this snapshot any good”. Measured against snapshots that already contained the answer, it refused 65 of 93 paraphrased questions, and refused hardest exactly where speculation is most valuable: 0 of 6 asked in-situ, 1 of 20 needing a step of inference. Every one of those refusals threw away a correct answer and replaced it with a lexical search that could not find one.

So a refusal no longer discards the snapshot; it demotes it to one ranking among two. That also gives the speculative path somewhere to deliver: it runs with a 100 ms semantic budget where this path has 10, so a remote backend’s results reach the model here or nowhere.

Source

pub async fn recall_scoped( &self, query: &str, turn_id: TurnId, scope: RecallScope, about: Option<String>, attribute: Option<String>, ) -> Value

Serve a recall_context tool call restricted to a scope or narrowed by the caller’s about/attribute hints.

An unrestricted, unhinted recall may be answered from the frozen snapshot. Anything else runs a live local search, because the snapshot was prepared speculatively and knows neither the restriction nor the hints — serving it would answer a different question quickly.

The hints only ever reorder. See RetrievalPlan::subject_hint for why they must not do more than that.

Source

pub async fn observe_final_transcript( &self, turn_id: TurnId, transcript: &str, ) -> Result<Vec<LedgerOutcome>, MemoryError>

Record a finalized user turn: durable evidence, then extraction.

The transcript event is appended before extraction runs, so a crash between the two loses an extraction that can be retried rather than the evidence itself.

Source

pub async fn on_turn_complete( &self, turn_id: TurnId, ) -> Result<Vec<ScheduledWork>, MemoryError>

Complete a turn and run whatever the cadence says is now due.

Source

pub fn is_idle(&self) -> bool

Whether the session has been idle long enough to seal.

Source

pub async fn finish(&self) -> Result<ReconciliationReport, MemoryError>

Seal the session and reconcile its evidence into canonical memory.

Idempotent by session id: reconciling twice commits once.

Source

pub async fn apply_explicit_command( &self, intent: MutationIntent, statement: &str, turn_id: TurnId, ) -> Result<Value, MemoryError>

Apply an explicit memory command from the user.

Explicit intent takes effect in the conversation immediately and commits durably afterwards. The durable event is appended before the overlay is touched, so the engine never tells a user their correction was recorded when it was not.

Source

pub fn known_predicates(&self) -> Vec<String>

The predicate names this user’s corpus already uses.

Offered to the extraction model so a correction lands on the predicate it is correcting. Reconciliation matches on subject and predicate; a model free to name each fact afresh writes dietary_preference in one session and dietary_identity in the next, and “actually I’m pescatarian now” becomes a second active record rather than superseding the first. This is the entity table’s trick applied to predicates: the vocabulary comes from the corpus.

Bounded, because it goes in a prompt. Session candidates come first — a correction usually chases something said minutes ago.

Source

pub fn known_values(&self) -> Vec<(CanonicalPredicate, Value)>

The predicate/value pairs memory can currently assert.

Session facts shadow canonical ones: something the user said this conversation is a better answer than something recalled from months ago.

Source

pub fn known_statements(&self) -> Vec<String>

Every statement currently retrievable, canonical and provisional.

Source

pub fn pending_explicit_commands(&self) -> Vec<MutationIntent>

Everything the user has explicitly asked to be remembered this session.

Auto Trait Implementations§

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.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,