feat(memory): Ebbinghaus eviction policy with two-phase SQLite+Qdrant sweep#1194
Merged
feat(memory): Ebbinghaus eviction policy with two-phase SQLite+Qdrant sweep#1194
Conversation
c0e1eb0 to
2a744c2
Compare
1ae8432 to
abbf113
Compare
Adds SQLite migration 020 with soft-delete columns (deleted_at, last_accessed, access_count, qdrant_cleaned), EvictionPolicy trait, EbbinghausPolicy scoring (exp(-t/(S*ln(1+n)))), and a background sweep loop that soft-deletes low-scoring entries then marks Qdrant vectors as cleaned in a crash-safe second phase. Eviction is disabled by default (max_entries = 0).
…ction cancellation - Add AND deleted_at IS NULL to all SELECT queries in messages.rs so soft-deleted rows are never visible to the application (FIX-2) - Add tracing::warn! and TODO comment in run_eviction_phase2 to clarify that Qdrant vector removal is not yet wired (MVP) and must happen before mark_qdrant_cleaned() in the future (FIX-3) - Accept CancellationToken in start_eviction_loop and use tokio::select! so the sweep loop stops cleanly on SemanticMemory drop (FIX-4)
abbf113 to
81e734d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements task 1.1 from the infrastructure hardening roadmap (epic #1159).
Previously memory grew unbounded. This adds a principled eviction subsystem based on Ebbinghaus forgetting curves.
EvictionPolicytrait ineviction.rswithscore(entry: &MemoryEntry) -> f64EbbinghausPolicy:exp(-t / (S * ln(1 + n)))decay based on recency, access frequency, and creation timedeleted_at,last_accessed,access_count,qdrant_cleanedcolumnsAND deleted_at IS NULL(soft-delete filter)CancellationToken(tokio-util) for clean shutdownmax_entries = 0= unlimited); opt-in via[memory.eviction]configConfig
Test plan
cargo nextest run --config-file .github/nextest.toml --workspace --lib --bins— all tests passcargo +nightly fmt --checkpassescargo clippy --workspace -- -D warningspassesCloses #1160