Skip to main content

SessionRecallTracker

Struct SessionRecallTracker 

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

v0.7.0 (issue #518) — process-global tracker mapping session_id to its FIFO ring buffer of recently-accessed memory ids.

The tracker is consulted by apply_session_recency_boost after the rerank stage of handle_recall (MCP) and recall_response (HTTP). Each call:

  1. Reads the per-session set BEFORE assembling the boost so the candidates already touched in this session lift in rank.
  2. Appends every recall hit’s id INTO the per-session ring (FIFO eviction past SESSION_RECENT_CAP) so subsequent recalls in the same session reuse the new context.

The tracker uses a single Mutex because contention is dominated by the per-recall work itself (FTS + semantic + rerank), making the lock-acquire/-release cost noise; the implementation can swap to per-shard locking if a future profile shows otherwise.

Implementations§

Source§

impl SessionRecallTracker

Source

pub fn new() -> Self

Construct an empty tracker. Test code uses this directly; the production code path goes through the process-global global_session_recall_tracker accessor below.

Source

pub fn recent_ids(&self, session_id: &str) -> HashSet<String>

Return the set of recently-accessed memory ids for session_id, or an empty set if the session is unknown. Used by the rerank boost to decide which candidates to lift.

v0.7.0 #1091 — kept for the public API contract (test code + callers outside the hot path use it). The boost site apply_session_recency_boost now uses SessionRecallTracker::with_recent_ids to avoid the per-recall HashSet allocation.

Source

pub fn with_recent_ids<R>( &self, session_id: &str, f: impl FnOnce(&dyn Fn(&str) -> bool) -> R, ) -> R

v0.7.0 #1091 — allocation-free per-id membership lookup against the per-session ring. Used by apply_session_recency_boost to apply the +0.05 boost without cloning the 50-deep ring into a fresh HashSet<String> on every recall.

The callback is invoked once with a membership predicate that owns the inner mutex guard for its lifetime. Returns the closure’s result (typically a Vec<(Memory, f64)> of boosted candidates). The membership predicate is O(N) per id over the ring (capped at SESSION_RECENT_CAP = 50); the closure is expected to call it K times for a K-result recall, giving O(K*N) total — same complexity as the pre-#1091 path that also did a HashSet build (O(N) construct) + K lookups (O(1) each = O(K)).

Source

pub fn record(&self, session_id: &str, ids: impl IntoIterator<Item = String>)

Record the ids of memories returned by the just-completed recall into the per-session ring. FIFO eviction past SESSION_RECENT_CAP keeps the per-session set bounded.

Duplicate ids (a memory recalled twice in the same session) move to the front of the ring so the eviction rule keeps the most-recently-touched ids in the set.

Source

pub fn session_count(&self) -> usize

Diagnostic: number of tracked sessions. Used by tests and the /metrics surface (future).

Trait Implementations§

Source§

impl Debug for SessionRecallTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SessionRecallTracker

Source§

fn default() -> SessionRecallTracker

Returns the “default value” for a type. Read more

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> ErasedDestructor for T
where T: 'static,

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

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

Source§

fn vzip(self) -> V

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