pub struct EpisodicMemory { /* private fields */ }Expand description
Episodic memory for storing event timelines with temporal context.
Records events with timestamps, descriptions, and embeddings. Supports similarity-based retrieval and time-range queries.
Implementations§
Source§impl EpisodicMemory
impl EpisodicMemory
Sourcepub fn new_from_db(
db: Arc<Database>,
dimension: usize,
) -> Result<Self, AgentMemoryError>
pub fn new_from_db( db: Arc<Database>, dimension: usize, ) -> Result<Self, AgentMemoryError>
Creates or opens the episodic memory collection.
§Errors
Returns an error when collection creation/opening fails or dimensions mismatch.
Sourcepub fn collection_name(&self) -> &str
pub fn collection_name(&self) -> &str
Returns the name of the underlying VelesDB collection.
Sourcepub fn record(
&self,
event_id: u64,
description: &str,
timestamp: i64,
embedding: Option<&[f32]>,
) -> Result<(), AgentMemoryError>
pub fn record( &self, event_id: u64, description: &str, timestamp: i64, embedding: Option<&[f32]>, ) -> Result<(), AgentMemoryError>
Stores an event in episodic memory.
§Errors
Returns an error when the embedding dimension is invalid, when the collection is unavailable, or when storage upsert fails.
Sourcepub fn record_with_ttl(
&self,
event_id: u64,
description: &str,
timestamp: i64,
embedding: Option<&[f32]>,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn record_with_ttl( &self, event_id: u64, description: &str, timestamp: i64, embedding: Option<&[f32]>, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Stores an event and assigns a TTL for automatic expiration.
A ttl_seconds of 0 means “expire immediately”: rather than persisting
a live point that lingers until the next auto_expire, the event is
eagerly removed (and any pre-existing point for event_id deleted),
harmonising the behaviour with SemanticMemory::store_with_ttl. The
embedding is still dimension-validated so callers get the same error
contract as a real record.
The expiry is persisted as a reserved _veles_expires_at (epoch
seconds) payload field, so the TTL survives a process restart: the
in-memory map is rebuilt from payloads when the collection is reopened.
§Errors
Returns the same errors as Self::record.
Sourcepub fn set_ttl_durable(
&self,
event_id: u64,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn set_ttl_durable( &self, event_id: u64, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Durably sets (or refreshes) the TTL of an existing event.
Unlike AgentMemory::set_episodic_ttl (in-memory map only, lost on
restart), this persists the expiry to the reserved _veles_expires_at
payload field, so it survives a restart. A ttl_seconds of 0 expires
the event immediately.
§Errors
Returns NotFound when no event with event_id exists, or
CollectionError when persistence fails.
Sourcepub fn relate(
&self,
from_id: u64,
to_id: u64,
rel_type: &str,
properties: Option<&Map<String, Value>>,
) -> Result<u64, AgentMemoryError>
pub fn relate( &self, from_id: u64, to_id: u64, rel_type: &str, properties: Option<&Map<String, Value>>, ) -> Result<u64, AgentMemoryError>
Relates two live events with a typed, durable graph edge (e.g.
CAUSED, FOLLOWED); see SemanticMemory::relate for semantics.
§Errors
Returns NotFound when either endpoint is missing or expired, or
CollectionError when the edge write fails.
Sourcepub fn relations(&self, id: u64) -> Result<Vec<GraphEdge>, AgentMemoryError>
pub fn relations(&self, id: u64) -> Result<Vec<GraphEdge>, AgentMemoryError>
Returns the outgoing relations of an event.
§Errors
Returns CollectionError when the collection cannot be resolved.
Sourcepub fn unrelate(&self, edge_id: u64) -> Result<bool, AgentMemoryError>
pub fn unrelate(&self, edge_id: u64) -> Result<bool, AgentMemoryError>
Removes a relation edge created by Self::relate.
§Errors
Returns CollectionError when the collection cannot be resolved.
Sourcepub fn recent(
&self,
limit: usize,
since_timestamp: Option<i64>,
) -> Result<Vec<(u64, String, i64)>, AgentMemoryError>
pub fn recent( &self, limit: usize, since_timestamp: Option<i64>, ) -> Result<Vec<(u64, String, i64)>, AgentMemoryError>
Returns recent events, optionally filtered by a lower timestamp bound.
§Errors
Returns an error when the collection is unavailable.
Sourcepub fn older_than(
&self,
timestamp: i64,
limit: usize,
) -> Result<Vec<(u64, String, i64)>, AgentMemoryError>
pub fn older_than( &self, timestamp: i64, limit: usize, ) -> Result<Vec<(u64, String, i64)>, AgentMemoryError>
Sourcepub fn recall_similar(
&self,
query_embedding: &[f32],
k: usize,
) -> Result<Vec<(u64, String, i64, f32)>, AgentMemoryError>
pub fn recall_similar( &self, query_embedding: &[f32], k: usize, ) -> Result<Vec<(u64, String, i64, f32)>, AgentMemoryError>
Retrieves the k most similar episodic events to a query embedding.
§Errors
Returns an error when the embedding dimension is invalid, when the collection is unavailable, or when vector search fails.
Sourcepub fn get_with_embedding(
&self,
id: u64,
) -> Result<Option<(String, i64, Vec<f32>)>, AgentMemoryError>
pub fn get_with_embedding( &self, id: u64, ) -> Result<Option<(String, i64, Vec<f32>)>, AgentMemoryError>
Retrieves an event with its embedding payload.
§Errors
Returns an error when the collection is unavailable.
Sourcepub fn delete(&self, id: u64) -> Result<(), AgentMemoryError>
pub fn delete(&self, id: u64) -> Result<(), AgentMemoryError>
Deletes an episodic event by id.
§Errors
Returns an error when the collection is unavailable or delete fails.
Sourcepub fn serialize(&self) -> Result<Vec<u8>, AgentMemoryError>
pub fn serialize(&self) -> Result<Vec<u8>, AgentMemoryError>
Serializes episodic points in temporal-order id set.
§Errors
Returns an error when the collection is unavailable or JSON encoding fails.
Sourcepub fn deserialize(&self, data: &[u8]) -> Result<(), AgentMemoryError>
pub fn deserialize(&self, data: &[u8]) -> Result<(), AgentMemoryError>
Replaces episodic storage with previously serialized points.
§Errors
Returns an error when JSON decoding fails, collection access fails, or persistence operations fail.
Auto Trait Implementations§
impl !Freeze for EpisodicMemory
impl !RefUnwindSafe for EpisodicMemory
impl !UnwindSafe for EpisodicMemory
impl Send for EpisodicMemory
impl Sync for EpisodicMemory
impl Unpin for EpisodicMemory
impl UnsafeUnpin for EpisodicMemory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);