v3/docs/adr/ADR-365-recurrence-gated-memory-consolidation.md
Status: Proposed
Authors: claude (dream-cycle agent, 2026-07-13)
Date: 2026-07-13
References: Dream Cycle issue 2026-07-13; RecMem (Dai et al., May 2026); SelfMem (Yang et al., July 2026)
AgentDB currently triggers memory consolidation eagerly: after every N writes, the DISTILL step runs a full LLM pass over the memory namespace to compact and re-rank entries. This has two costs:
The 2026 paper "RecMem: Recurrence-based Memory Consolidation" (Dai et al., May 15 2026, Grade A) demonstrates that consolidation triggered only when sustained semantic cluster activity exceeds a configurable threshold reduces token cost by 87% while exceeding eager-consolidation accuracy on recall benchmarks. The key insight: most writes to a namespace do not meaningfully shift the semantic distribution — consolidation is only valuable when cluster centroids have drifted enough to require re-ranking.
Additionally, "SelfMem" (Yang et al., July 2026, Grade A) demonstrates that an RL layer self-optimizing retrieval parameters (k, ef_search, relevance threshold) per namespace using verdict signals from the existing JUDGE step yields a +48.7% BEAM score improvement at 100K token scale. The feedback loop already exists in Ruflo's RETRIEVE→JUDGE pipeline; wiring it back to retrieval configuration is the missing piece.
Replace the eager N-write consolidation trigger in AgentDB with a recurrence-gated trigger:
Cluster-activity monitor: After each write batch, compute the cosine shift of the top-K cluster centroids versus their last-consolidation snapshot. Consolidation fires only when the mean centroid shift exceeds a configurable threshold CONSOLIDATION_DRIFT_THRESHOLD (default: 0.12) sustained over CONSOLIDATION_SUSTAIN_WRITES consecutive batches (default: 8).
RL retrieval policy layer (phase 2): Wire JUDGE step verdicts (success/failure per retrieval) back to a per-namespace bandit that tunes ef_search, k, and min_relevance_score. This is additive — does not require changing the HNSW index structure.
Backward compatibility: The existing CONSOLIDATION_INTERVAL config key remains supported as a hard ceiling (consolidation always fires if N writes have elapsed, regardless of drift). Default ceiling: 500 writes (up from current 50).
query path — no new index structures needed.memory_policies namespace (persistent across sessions via existing AgentDB persistence).scripts/benchmark-intelligence.mjs must show ≥50% reduction in consolidation LLM calls on the N=20k fixture before merging. Grade A target.Positive:
CONSOLIDATION_INTERVAL ceiling preserves safety netNegative / Risks:
CONSOLIDATION_DRIFT_THRESHOLD requires calibration per workload; wrong value delays needed consolidation