Skip to main content

TwoTierMemory

Struct TwoTierMemory 

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

Two-tier memory: bounded short-term working store + decayed long-term store.

  • Writes (put) always land in the short tier.
  • get checks the short tier first, then the long tier.
  • search scores both tiers with the long-term weighted formula (so cross-tier ordering is on one scale), de-duplicating by key with the short tier preferred.
  • consolidate promotes qualifying short-term entries into long-term memory and removes them from the short tier.

Implementations§

Source§

impl TwoTierMemory

Source

pub fn new(short_capacity: usize) -> Self

Creates a two-tier store with default capacity/weights/scorer/policy.

Source

pub fn with_policy(self, policy: PromotionPolicy) -> Self

Replaces the promotion policy.

Source

pub fn short_term(&self) -> Arc<ShortTermMemory>

The short-term tier (direct access for seeding/tests).

Source

pub fn long_term(&self) -> Arc<LongTermMemory>

The long-term tier (direct access for seeding/tests).

Source

pub fn set_policy(&self, policy: PromotionPolicy)

Replaces the promotion policy at runtime.

Source

pub async fn consolidate_namespace( &self, namespace: &str, ) -> Result<Vec<String>, MemoryError>

Promotes qualifying short-term entries of one namespace into long-term memory, removing promoted entries from the short tier. Returns the promoted keys.

Source

pub async fn consolidate(&self) -> Result<Vec<String>, MemoryError>

Promotes qualifying entries across every short-term namespace.

Trait Implementations§

Source§

impl Debug for TwoTierMemory

Source§

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

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

impl MemoryStore for TwoTierMemory

Source§

fn put<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, item: MemoryItem, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes/updates an item in the namespace. Re-putting an existing key refreshes its content and access time.
Source§

fn get<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<MemoryItem>, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Exact key lookup (None when absent). Counts as an access.
Source§

fn search<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 MemoryQuery<'life2>, ) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryHit>, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Semantic recall, best score first, capped at query.k.
Source§

fn forget<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, namespace: &'life1 str, key: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Removes one entry; returns whether it existed.
Source§

fn clear_namespace<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Drops every entry in the namespace; returns the number removed.
Source§

fn len_namespace<'life0, 'life1, 'async_trait>( &'life0 self, namespace: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize, MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Number of entries stored under the namespace.

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.

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> 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 = !

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