applyDecay method

void applyDecay({
  1. double halfLifeHours = 24.0,
})

Applies Ebbinghaus temporal decay to all stored memories.

Memories whose strength falls below pruneThreshold are removed.

Implementation

void applyDecay({double halfLifeHours = 24.0}) {
  var pruned = 0;
  final toRemove = <String>[];

  for (final memory in _store.values) {
    memory.applyDecay(halfLifeHours: halfLifeHours);
    if (memory.strength < pruneThreshold) {
      toRemove.add(memory.id);
      pruned++;
    }
  }

  for (final id in toRemove) {
    _store.remove(id);
    _insertionOrder.remove(id);
  }

  if (pruned > 0) {
    _logger.debug('Episodic decay pruned $pruned weak memories');
  }
}