Spaces:
Sleeping
Sleeping
File size: 735 Bytes
ce45eb0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | """Recency decay + TTL — the MVP slice of the dual-engine memory model.
Basic engine: TTL + caps (deterministic). Adaptive engine [v1]: decay +
reinforcement + consolidation. This module provides the shared time math.
"""
from __future__ import annotations
import math
import time
from typing import Optional
from ..schema.item import ContextItem
def recency_decay(item: ContextItem, now: Optional[float] = None,
half_life_days: float = 30.0) -> float:
now = now if now is not None else time.time()
age_days = (now - item.created_at) / 86400.0
return math.pow(0.5, age_days / half_life_days)
def is_expired(item: ContextItem, now: Optional[float] = None) -> bool:
return not item.is_live(now)
|