Skip to main content

EpisodicMemory

Struct EpisodicMemory 

Source
pub struct EpisodicMemory<V>
where V: Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
{ /* private fields */ }
Expand description

Time-ordered append-only episode store keyed by Namespace.

Implementations§

Source§

impl<V> EpisodicMemory<V>
where V: Clone + Serialize + DeserializeOwned + Send + Sync + 'static,

Source

pub fn new(store: Arc<dyn Store<Vec<Episode<V>>>>, namespace: Namespace) -> Self

Build an episodic memory over store scoped to namespace.

Source

pub const fn namespace(&self) -> &Namespace

Borrow the bound namespace.

Source

pub async fn append( &self, ctx: &ExecutionContext, payload: V, ) -> Result<EpisodeId>

Append a fresh episode timestamped at Utc::now(). Returns the id so the caller can correlate with audit / external systems.

Source

pub async fn append_at( &self, ctx: &ExecutionContext, payload: V, timestamp: DateTime<Utc>, ) -> Result<EpisodeId>

Append at a caller-supplied timestamp. Use when backfilling from an external ledger or replaying historical events. The new entry is binary-inserted so the stored vector stays in non-decreasing timestamp order.

Source

pub async fn append_record( &self, ctx: &ExecutionContext, episode: Episode<V>, ) -> Result<()>

Append a fully-formed Episode. Use when the caller is migrating records minted elsewhere (a UUID + timestamp pair already exists). The entry is inserted at the correct position to preserve chronological order.

Source

pub async fn all(&self, ctx: &ExecutionContext) -> Result<Vec<Episode<V>>>

Read every episode in chronological order. Empty namespaces return Ok(vec![]).

Source

pub async fn recent( &self, ctx: &ExecutionContext, n: usize, ) -> Result<Vec<Episode<V>>>

Most-recent-first slice of up to n episodes. n = 0 returns an empty vector.

Source

pub async fn range( &self, ctx: &ExecutionContext, start: DateTime<Utc>, end: DateTime<Utc>, ) -> Result<Vec<Episode<V>>>

Episodes whose timestamp falls in the inclusive range [start, end]. Order is chronological. start > end returns an empty vector rather than erroring — the question “what happened between two timestamps?” is well-defined even when the answer is empty.

Source

pub async fn since( &self, ctx: &ExecutionContext, start: DateTime<Utc>, ) -> Result<Vec<Episode<V>>>

Episodes whose timestamp is greater than or equal to start. Order is chronological.

Source

pub async fn count(&self, ctx: &ExecutionContext) -> Result<usize>

Total stored episode count.

Source

pub async fn prune_older_than( &self, ctx: &ExecutionContext, ttl: Duration, ) -> Result<usize>

Drop every episode older than ttl. Returns the removal count so callers can log or expose pruning metrics. Atomic per-thread (single read-modify-write under one store key, matching crate::EntityMemory::prune_older_than).

Source

pub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>

Drop every episode in this namespace.

Auto Trait Implementations§

§

impl<V> Freeze for EpisodicMemory<V>

§

impl<V> !RefUnwindSafe for EpisodicMemory<V>

§

impl<V> Send for EpisodicMemory<V>

§

impl<V> Sync for EpisodicMemory<V>

§

impl<V> Unpin for EpisodicMemory<V>

§

impl<V> UnsafeUnpin for EpisodicMemory<V>

§

impl<V> !UnwindSafe for EpisodicMemory<V>

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: 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: 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<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