pub struct DecayEngine {
pub config: DecayConfig,
}Expand description
Importance Decay Engine that runs as a background task.
Fields§
§config: DecayConfigImplementations§
Source§impl DecayEngine
impl DecayEngine
Sourcepub fn new(config: DecayConfig) -> Self
pub fn new(config: DecayConfig) -> Self
Create a new DecayEngine with the given configuration.
Sourcepub fn calculate_decay(
&self,
current_importance: f32,
hours_elapsed: f64,
memory_type: &MemoryType,
access_count: u32,
) -> f32
pub fn calculate_decay( &self, current_importance: f32, hours_elapsed: f64, memory_type: &MemoryType, access_count: u32, ) -> f32
Calculate decayed importance for a single memory.
Memory type determines base decay speed:
- Working: 3× faster (temporary by design)
- Episodic: 1× normal (events fade naturally)
- Semantic: 0.5× slower (knowledge persists)
- Procedural: 0.3× slower (skills are durable)
Usage pattern shields from decay (diminishing returns). Never-accessed memories fade 50% faster.
Sourcepub fn access_boost(current_importance: f32) -> f32
pub fn access_boost(current_importance: f32) -> f32
Calculate access boost for a memory that was just recalled. Scales with current importance — valuable memories get bigger boosts.
Sourcepub async fn apply_decay(&self, storage: &Arc<dyn VectorStorage>) -> DecayResult
pub async fn apply_decay(&self, storage: &Arc<dyn VectorStorage>) -> DecayResult
Apply decay to all memories across all agent namespaces.
Iterates all namespaces prefixed with _dakera_agent_, loads memories,
applies decay based on time since last access, and removes memories
below the minimum importance threshold.
Sourcepub fn spawn(
config: Arc<RwLock<DecayConfig>>,
interval_secs: u64,
storage: Arc<dyn VectorStorage>,
metrics: Arc<BackgroundMetrics>,
) -> JoinHandle<()>
pub fn spawn( config: Arc<RwLock<DecayConfig>>, interval_secs: u64, storage: Arc<dyn VectorStorage>, metrics: Arc<BackgroundMetrics>, ) -> JoinHandle<()>
Spawn the decay engine as a background tokio task.
Takes a shared Arc<RwLock<DecayConfig>> so that config changes made at
runtime via PUT /admin/decay/config take effect without a server restart.
Each loop iteration re-reads the config before running, so strategy/half-life
changes apply on the next cycle.
Auto Trait Implementations§
impl Freeze for DecayEngine
impl RefUnwindSafe for DecayEngine
impl Send for DecayEngine
impl Sync for DecayEngine
impl Unpin for DecayEngine
impl UnsafeUnpin for DecayEngine
impl UnwindSafe for DecayEngine
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 more