pub struct AgentMemory { /* private fields */ }Expand description
Unified memory interface for AI agents.
Provides access to three memory subsystems:
semantic: Long-term knowledge (vector storage; graph linkage planned)episodic: Event timeline with temporal contextprocedural: Learned patterns and action sequences
§Enhanced Features
- TTL management for automatic expiration
- Snapshot/restore for state persistence
- Temporal indexing for efficient time-based queries
- Configurable eviction policies
Implementations§
Source§impl AgentMemory
impl AgentMemory
Sourcepub fn new(db: Arc<Database>) -> Result<Self, AgentMemoryError>
pub fn new(db: Arc<Database>) -> Result<Self, AgentMemoryError>
Creates a new AgentMemory instance from a Database.
Initializes or connects to the three memory subsystem collections:
_semantic_memory: For knowledge facts_episodic_memory: For event timeline_procedural_memory: For learned patterns
Uses the default embedding dimension (384).
§Errors
Returns an error when one of the underlying memory subsystems cannot be initialized.
Sourcepub fn with_dimension(
db: Arc<Database>,
dimension: usize,
) -> Result<Self, AgentMemoryError>
pub fn with_dimension( db: Arc<Database>, dimension: usize, ) -> Result<Self, AgentMemoryError>
Creates a new AgentMemory with a custom embedding dimension.
§Errors
Returns an error when one of the underlying memory subsystems cannot be initialized.
Sourcepub fn with_eviction_config(self, config: EvictionConfig) -> Self
pub fn with_eviction_config(self, config: EvictionConfig) -> Self
Configures eviction policies for automatic memory cleanup.
Sourcepub fn with_snapshots(self, snapshot_dir: &str, max_snapshots: usize) -> Self
pub fn with_snapshots(self, snapshot_dir: &str, max_snapshots: usize) -> Self
Enables snapshot management with a storage directory.
§Arguments
snapshot_dir- Directory path for storing snapshotsmax_snapshots- Maximum number of snapshots to retain
Sourcepub fn semantic(&self) -> &SemanticMemory
pub fn semantic(&self) -> &SemanticMemory
Returns a reference to the semantic memory subsystem.
Sourcepub fn episodic(&self) -> &EpisodicMemory
pub fn episodic(&self) -> &EpisodicMemory
Returns a reference to the episodic memory subsystem.
Sourcepub fn procedural(&self) -> &ProceduralMemory
pub fn procedural(&self) -> &ProceduralMemory
Returns a reference to the procedural memory subsystem.
Sourcepub fn set_semantic_ttl(&self, id: u64, ttl_seconds: u64)
pub fn set_semantic_ttl(&self, id: u64, ttl_seconds: u64)
Sets TTL for a semantic memory entry (in-memory only; lost on restart).
Use Self::set_semantic_ttl_durable to persist the expiry.
Sourcepub fn set_episodic_ttl(&self, id: u64, ttl_seconds: u64)
pub fn set_episodic_ttl(&self, id: u64, ttl_seconds: u64)
Sets TTL for an episodic memory entry (in-memory only; lost on restart).
Use Self::set_episodic_ttl_durable to persist the expiry.
Sourcepub fn set_procedural_ttl(&self, id: u64, ttl_seconds: u64)
pub fn set_procedural_ttl(&self, id: u64, ttl_seconds: u64)
Sets TTL for a procedural memory entry (in-memory only; lost on restart).
Use Self::set_procedural_ttl_durable to persist the expiry.
Sourcepub fn set_semantic_ttl_durable(
&self,
id: u64,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn set_semantic_ttl_durable( &self, id: u64, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Durably sets the TTL of an existing semantic fact: the expiry is
persisted to the reserved _veles_expires_at payload field and
survives a restart.
§Errors
Returns NotFound when no fact with id exists, or
CollectionError when persistence fails.
Sourcepub fn set_episodic_ttl_durable(
&self,
id: u64,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn set_episodic_ttl_durable( &self, id: u64, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Durably sets the TTL of an existing episodic event: the expiry is
persisted to the reserved _veles_expires_at payload field and
survives a restart.
§Errors
Returns NotFound when no event with id exists, or
CollectionError when persistence fails.
Sourcepub fn set_procedural_ttl_durable(
&self,
id: u64,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn set_procedural_ttl_durable( &self, id: u64, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Durably sets the TTL of an existing procedure: the expiry is
persisted to the reserved _veles_expires_at payload field and
survives a restart.
§Errors
Returns NotFound when no procedure with id exists, or
CollectionError when persistence fails.
Sourcepub fn auto_expire(&self) -> Result<ExpireResult, AgentMemoryError>
pub fn auto_expire(&self) -> Result<ExpireResult, AgentMemoryError>
Performs automatic expiration of entries that have exceeded their TTL.
This method should be called periodically to clean up expired entries. It also handles consolidation of old episodic memories to semantic memory based on the configured eviction policy.
§Returns
Statistics about the expiration operation.
§Errors
Returns an error when consolidation operations fail.
Sourcepub fn evict_low_confidence_procedures(
&self,
min_confidence: f32,
) -> Result<usize, AgentMemoryError>
pub fn evict_low_confidence_procedures( &self, min_confidence: f32, ) -> Result<usize, AgentMemoryError>
Sourcepub fn snapshot(&self) -> Result<u64, AgentMemoryError>
pub fn snapshot(&self) -> Result<u64, AgentMemoryError>
Sourcepub fn load_latest_snapshot(&self) -> Result<u64, AgentMemoryError>
pub fn load_latest_snapshot(&self) -> Result<u64, AgentMemoryError>
Sourcepub fn load_snapshot_version(
&self,
version: u64,
) -> Result<(), AgentMemoryError>
pub fn load_snapshot_version( &self, version: u64, ) -> Result<(), AgentMemoryError>
Loads a specific snapshot version.
§Errors
Returns an error when snapshot manager is not configured, loading fails, or state restoration fails.
Sourcepub fn list_snapshot_versions(&self) -> Result<Vec<u64>, AgentMemoryError>
pub fn list_snapshot_versions(&self) -> Result<Vec<u64>, AgentMemoryError>
Lists all available snapshot versions.
§Errors
Returns an error when snapshot manager is not configured or listing fails.
Sourcepub fn query_semantic(
&self,
sql: &str,
params: &HashMap<String, Value>,
) -> Result<Vec<SearchResult>, AgentMemoryError>
pub fn query_semantic( &self, sql: &str, params: &HashMap<String, Value>, ) -> Result<Vec<SearchResult>, AgentMemoryError>
Executes a VelesQL query against the semantic memory collection.
Delegates to Collection::execute_query_str on the _semantic_memory
collection. Use standard VelesQL syntax including WHERE vector NEAR $v,
payload filters, ORDER BY, and WITH options. TTL-expired entries are
filtered from the results, matching the native query APIs.
§Errors
Returns an error if the collection is missing or the query fails.
Sourcepub fn query_episodic(
&self,
sql: &str,
params: &HashMap<String, Value>,
) -> Result<Vec<SearchResult>, AgentMemoryError>
pub fn query_episodic( &self, sql: &str, params: &HashMap<String, Value>, ) -> Result<Vec<SearchResult>, AgentMemoryError>
Executes a VelesQL query against the episodic memory collection.
Delegates to Collection::execute_query_str on the _episodic_memory
collection. Supports payload field filters like WHERE timestamp > N,
ORDER BY timestamp DESC, and similarity search via NEAR. TTL-expired
entries are filtered from the results, matching the native query APIs.
§Errors
Returns an error if the collection is missing or the query fails.
Sourcepub fn query_procedural(
&self,
sql: &str,
params: &HashMap<String, Value>,
) -> Result<Vec<SearchResult>, AgentMemoryError>
pub fn query_procedural( &self, sql: &str, params: &HashMap<String, Value>, ) -> Result<Vec<SearchResult>, AgentMemoryError>
Executes a VelesQL query against the procedural memory collection.
Delegates to Collection::execute_query_str on the _procedural_memory
collection. Supports payload field filters like WHERE confidence > 0.7,
ORDER BY confidence DESC, and scan queries. TTL-expired entries are
filtered from the results, matching the native query APIs.
§Errors
Returns an error if the collection is missing or the query fails.
Auto Trait Implementations§
impl !Freeze for AgentMemory
impl !RefUnwindSafe for AgentMemory
impl !UnwindSafe for AgentMemory
impl Send for AgentMemory
impl Sync for AgentMemory
impl Unpin for AgentMemory
impl UnsafeUnpin for AgentMemory
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);