Skip to main content

Module forgetting

Module forgetting 

Source
Expand description

Forgetting sweep — SleepGate (#2397).

Inspired by sleep-dependent memory consolidation: a background sweep periodically downscales all non-consolidated message importance scores (synaptic downscaling), restores recently-accessed messages (selective replay), then prunes messages whose scores fall below forgetting_floor (targeted forgetting).

§Algorithm

  1. Synaptic downscaling — multiply all active, non-consolidated importance scores by (1.0 - decay_rate) in a single batch UPDATE.
  2. Selective replay — undo the current sweep’s decay for messages accessed within replay_window_hours or with access_count >= replay_min_access_count.
  3. Targeted forgetting — soft-delete messages below forgetting_floor that are not protected by recent access or high access count.

All three phases run inside a single SQLite transaction to prevent intermediate state from being visible to concurrent readers (WAL readers see the pre-transaction snapshot until commit).

§Interaction with consolidation

Forgetting only targets non-consolidated messages (consolidated = 0). Consolidation merge transactions re-check deleted_at IS NULL before writing, so messages deleted by forgetting are safely skipped during the next consolidation sweep.

§No LLM calls

Pure SQL arithmetic — no *_provider field needed.

Structs§

ForgettingConfig
Runtime config for the forgetting sweep (#2397).
ForgettingResult
Outcome of a single forgetting sweep.

Functions§

run_forgetting_sweep
Execute one full forgetting sweep (SleepGate).
start_forgetting_loop
Start the background forgetting loop (SleepGate).