Skip to content

feat(memory): Ebbinghaus eviction policy with two-phase SQLite+Qdrant sweep#1194

Merged
bug-ops merged 4 commits intomainfrom
feat/m29/memory-eviction
Mar 4, 2026
Merged

feat(memory): Ebbinghaus eviction policy with two-phase SQLite+Qdrant sweep#1194
bug-ops merged 4 commits intomainfrom
feat/m29/memory-eviction

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 4, 2026

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.

  • EvictionPolicy trait in eviction.rs with score(entry: &MemoryEntry) -> f64
  • EbbinghausPolicy: exp(-t / (S * ln(1 + n))) decay based on recency, access frequency, and creation time
  • SQLite migration 020: adds deleted_at, last_accessed, access_count, qdrant_cleaned columns
  • All existing SELECT queries updated with AND deleted_at IS NULL (soft-delete filter)
  • Two-phase sweep: SQLite soft-delete first (immediate, crash-safe), Qdrant removal second (best-effort, retried on next sweep)
  • Background sweep loop with CancellationToken (tokio-util) for clean shutdown
  • Eviction disabled by default (max_entries = 0 = unlimited); opt-in via [memory.eviction] config

Config

[memory.eviction]
policy = "ebbinghaus"   # only supported policy
max_entries = 10000     # 0 = disabled (default)
sweep_interval_secs = 3600

Test plan

  • cargo nextest run --config-file .github/nextest.toml --workspace --lib --bins — all tests pass
  • cargo +nightly fmt --check passes
  • cargo clippy --workspace -- -D warnings passes

Closes #1160

@github-actions github-actions bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate dependencies Dependency updates enhancement New feature or request size/XL Extra large PR (500+ lines) labels Mar 4, 2026
@bug-ops bug-ops force-pushed the feat/m29/memory-eviction branch from c0e1eb0 to 2a744c2 Compare March 4, 2026 16:05
@github-actions github-actions bot removed the llm zeph-llm crate (Ollama, Claude) label Mar 4, 2026
@bug-ops bug-ops force-pushed the feat/m29/memory-eviction branch 2 times, most recently from 1ae8432 to abbf113 Compare March 4, 2026 17:02
bug-ops added 3 commits March 4, 2026 18:28
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)
@bug-ops bug-ops force-pushed the feat/m29/memory-eviction branch from abbf113 to 81e734d Compare March 4, 2026 17:28
@bug-ops bug-ops enabled auto-merge (squash) March 4, 2026 18:00
@bug-ops bug-ops merged commit 824a727 into main Mar 4, 2026
25 checks passed
@bug-ops bug-ops deleted the feat/m29/memory-eviction branch March 4, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate dependencies Dependency updates documentation Improvements or additions to documentation enhancement New feature or request memory zeph-memory crate (SQLite) rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[M-1.1] Memory eviction policy (FadeMem / Ebbinghaus)

1 participant