pub struct ProceduralMemory { /* private fields */ }Expand description
Procedural memory for storing learned action sequences with confidence scoring.
Stores procedures as embedding vectors with associated metadata. Supports confidence-based recall, reinforcement learning, and TTL expiration.
§ACT-R activation decay
When built with with_activation_decay, the
confidence returned by recall is modulated by the ACT-R
base-level power-law formula: c × max(1, t_days)^(-d) where d is the
decay exponent (Anderson 1996, default ≈ 0.5). The stored value is
unchanged — decay is applied read-only at retrieval time.
Implementations§
Source§impl ProceduralMemory
impl ProceduralMemory
Sourcepub fn collection_name(&self) -> &str
pub fn collection_name(&self) -> &str
Returns the name of the underlying VelesDB collection.
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 procedural memory.
§Errors
Returns an error when collection creation/opening fails or dimensions mismatch.
Sourcepub fn with_reinforcement_strategy(
self,
strategy: Arc<dyn ReinforcementStrategy>,
) -> Self
pub fn with_reinforcement_strategy( self, strategy: Arc<dyn ReinforcementStrategy>, ) -> Self
Overrides the default reinforcement strategy with a custom implementation.
Sourcepub fn with_activation_decay(self, decay_exponent: f32) -> Self
pub fn with_activation_decay(self, decay_exponent: f32) -> Self
Enables ACT-R base-level activation decay at recall time.
When set, the confidence returned by recall is
multiplied by max(1, t_days)^(-decay_exponent) where t_days is the
number of days since the procedure was last reinforced.
The stored confidence is not modified — decay is applied read-only.
ACT-R recommends decay_exponent ≈ 0.5 (Anderson 1996).
Sourcepub fn learn(
&self,
procedure_id: u64,
name: &str,
steps: &[String],
embedding: Option<&[f32]>,
confidence: f32,
) -> Result<(), AgentMemoryError>
pub fn learn( &self, procedure_id: u64, name: &str, steps: &[String], embedding: Option<&[f32]>, confidence: f32, ) -> Result<(), AgentMemoryError>
Learns a procedure and stores it in memory.
§Errors
Returns an error when embedding dimension is invalid, the collection is unavailable, or persistence fails.
Sourcepub fn learn_with_ttl(
&self,
procedure_id: u64,
name: &str,
steps: &[String],
embedding: Option<&[f32]>,
confidence: f32,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn learn_with_ttl( &self, procedure_id: u64, name: &str, steps: &[String], embedding: Option<&[f32]>, confidence: f32, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Learns a procedure and assigns a TTL for auto-expiration.
A ttl_seconds of 0 means “expire immediately”: the procedure is
eagerly removed (and any pre-existing point for procedure_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 learn.
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::learn.
Sourcepub fn set_ttl_durable(
&self,
procedure_id: u64,
ttl_seconds: u64,
) -> Result<(), AgentMemoryError>
pub fn set_ttl_durable( &self, procedure_id: u64, ttl_seconds: u64, ) -> Result<(), AgentMemoryError>
Durably sets (or refreshes) the TTL of an existing procedure.
Unlike AgentMemory::set_procedural_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 procedure immediately.
§Errors
Returns NotFound when no procedure with procedure_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 procedures with a typed, durable graph edge (e.g.
DEPENDS_ON, REFINES); 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 a procedure.
§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 recall(
&self,
query_embedding: &[f32],
k: usize,
min_confidence: f32,
) -> Result<Vec<ProcedureMatch>, AgentMemoryError>
pub fn recall( &self, query_embedding: &[f32], k: usize, min_confidence: f32, ) -> Result<Vec<ProcedureMatch>, AgentMemoryError>
Recalls matching procedures by vector similarity.
When ACT-R activation decay is configured via
with_activation_decay, the returned
confidence reflects power-law decay since last use without modifying
the stored value.
§Errors
Returns an error when embedding dimension is invalid, collection access fails, or vector search fails.
Sourcepub fn reinforce(
&self,
procedure_id: u64,
success: bool,
) -> Result<(), AgentMemoryError>
pub fn reinforce( &self, procedure_id: u64, success: bool, ) -> Result<(), AgentMemoryError>
Reinforces a stored procedure using the configured strategy.
§Errors
Returns an error when procedure retrieval or update fails.
Sourcepub fn reinforce_with_strategy(
&self,
procedure_id: u64,
success: bool,
strategy: &dyn ReinforcementStrategy,
) -> Result<(), AgentMemoryError>
pub fn reinforce_with_strategy( &self, procedure_id: u64, success: bool, strategy: &dyn ReinforcementStrategy, ) -> Result<(), AgentMemoryError>
Reinforces a stored procedure using a custom strategy.
§Errors
Returns an error when procedure retrieval or update fails.
Sourcepub fn list_all(&self) -> Result<Vec<ProcedureMatch>, AgentMemoryError>
pub fn list_all(&self) -> Result<Vec<ProcedureMatch>, AgentMemoryError>
Sourcepub fn serialize(&self) -> Result<Vec<u8>, AgentMemoryError>
pub fn serialize(&self) -> Result<Vec<u8>, AgentMemoryError>
Serializes all procedures into snapshot bytes.
§Errors
Returns an error when collection access or JSON encoding fails.
Sourcepub fn deserialize(&self, data: &[u8]) -> Result<(), AgentMemoryError>
pub fn deserialize(&self, data: &[u8]) -> Result<(), AgentMemoryError>
Replaces procedural memory state from serialized snapshot bytes.
§Errors
Returns an error when JSON decoding fails, collection access fails, or persistence operations fail.
Auto Trait Implementations§
impl !Freeze for ProceduralMemory
impl !RefUnwindSafe for ProceduralMemory
impl !UnwindSafe for ProceduralMemory
impl Send for ProceduralMemory
impl Sync for ProceduralMemory
impl Unpin for ProceduralMemory
impl UnsafeUnpin for ProceduralMemory
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);