pub struct EpisodicMemory<V>{ /* private fields */ }Expand description
Time-ordered append-only episode store keyed by Namespace.
Implementations§
Source§impl<V> EpisodicMemory<V>
impl<V> EpisodicMemory<V>
Sourcepub fn new(store: Arc<dyn Store<Vec<Episode<V>>>>, namespace: Namespace) -> Self
pub fn new(store: Arc<dyn Store<Vec<Episode<V>>>>, namespace: Namespace) -> Self
Build an episodic memory over store scoped to namespace.
Sourcepub async fn append(
&self,
ctx: &ExecutionContext,
payload: V,
) -> Result<EpisodeId>
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.
Sourcepub async fn append_at(
&self,
ctx: &ExecutionContext,
payload: V,
timestamp: DateTime<Utc>,
) -> Result<EpisodeId>
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.
Sourcepub async fn append_record(
&self,
ctx: &ExecutionContext,
episode: Episode<V>,
) -> Result<()>
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.
Sourcepub async fn all(&self, ctx: &ExecutionContext) -> Result<Vec<Episode<V>>>
pub async fn all(&self, ctx: &ExecutionContext) -> Result<Vec<Episode<V>>>
Read every episode in chronological order. Empty namespaces
return Ok(vec![]).
Sourcepub async fn recent(
&self,
ctx: &ExecutionContext,
n: usize,
) -> Result<Vec<Episode<V>>>
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.
Sourcepub async fn range(
&self,
ctx: &ExecutionContext,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<Vec<Episode<V>>>
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.
Sourcepub async fn since(
&self,
ctx: &ExecutionContext,
start: DateTime<Utc>,
) -> Result<Vec<Episode<V>>>
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.
Sourcepub async fn count(&self, ctx: &ExecutionContext) -> Result<usize>
pub async fn count(&self, ctx: &ExecutionContext) -> Result<usize>
Total stored episode count.
Sourcepub async fn prune_older_than(
&self,
ctx: &ExecutionContext,
ttl: Duration,
) -> Result<usize>
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).
Sourcepub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>
pub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>
Drop every episode in this namespace.