Skip to main content

Self-improving memory store for LLM agents: hybrid retrieval, clustered retrieval-induced forgetting, optional LLM enrichment

Project description

lethe

Λήθη: the ancient Greek personification of forgetfulness, and one of the five rivers of the underworld.

A memory store for LLM agents that gets better the more you use it. Hybrid BM25 + dense retrieval, cross-encoder reranking, clustered retrieval-induced forgetting (RIF), and optional LLM enrichment at write time.

Most memory tools are static caches - you put strings in, you get strings back by similarity, and the retrieval function never changes. lethe is different: every retrieval teaches it which entries are chronic distractors for which kinds of queries, and it quietly suppresses them over time. No fine-tuning, no extra LLM calls - just bookkeeping inspired by how human memory actually works (Anderson, 1994).

Install and quick start

As a Claude Code plugin (recommended for daily use)

/plugin marketplace add teimurjan/lethe
/plugin install lethe

What happens after install:

  • Every session is summarized into .lethe/memory/YYYY-MM-DD.md per project. Plain markdown, edit by hand if you want.
  • Claude sees recent memory at session start and calls the recall skill when a past session in this project would help.
  • For cross-repo context, the recall-global skill searches every registered project at once (uses lethe search --all under the hood).

Update: uv tool install --upgrade lethe-memory && /reload-plugins

See plugins/claude-code/README.md for the full hook table, config knobs, and debugging.

As a CLI

uv tool install lethe-memory
lethe --version

lethe index                                     # reindex .lethe/memory
lethe search "your query" --top-k 5             # single project
lethe search "your query" --all --top-k 5       # all registered projects
lethe projects list
lethe status

Interactive TUI

lethe TUI

uv tool install --force 'lethe-memory[tui]'
# or, if lethe is already installed as a uv tool:
uv tool install --force --reinstall --with textual lethe-memory

lethe tui

uv tool install does not read [project.optional-dependencies] from extras syntax unless quoted; the --with textual form is the reliable fallback. Keys inside the TUI: ↑↓ nav, search/open, Esc back, Ctrl+Q quit. Type anywhere to jump focus to the search box.

As a Python library

pip install lethe-memory
from lethe import MemoryStore
from sentence_transformers import SentenceTransformer, CrossEncoder

store = MemoryStore(
    "./my_memories",
    bi_encoder=SentenceTransformer("all-MiniLM-L6-v2"),
    cross_encoder=CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2"),
)

store.add("I prefer window seats on flights", session_id="trip")
store.add("My wife needs aisle seats", session_id="trip")
store.add("I work at Google as a software engineer", session_id="work")

results = store.retrieve("What are my travel preferences?", k=5)
for entry_id, content, score in results:
    print(f"  [{score:.1f}] {content}")

store.save()
store.close()

Benchmark

Numbers on the full 199,509-turn LongMemEval S corpus, turn-level retrieval, NDCG@10, no leakage. Most memory-tool benchmarks use ~50 sessions at session granularity - a ~2000× easier task. Those 99% numbers don't translate to this setup.

Stage NDCG@10 Relative gain notes
Hybrid BM25 + vector (RRF) 0.241 basic retrieval (most popular)
+ cross-encoder reranking 0.382 +59% semantic reranking on the hybrid pool
+ clustered+gap RIF (checkpoint 13) 0.342¹ +3.4%¹ retrieval-induced forgetting (30 clusters, gap formula)
+ LLM enrichment, on covered queries 0.473² +20–25%² Haiku write-time enrichment on the 75 queries where the answer turn was enriched

¹ Measured on the RIF benchmark pipeline (RRF-truncation, 500-query full eval, 5000-step burn-in; benchmarks/run_rif_clustered.py). Matched no-RIF baseline on this pipeline = 0.331, so RIF delivers +3.4% / +1.1pp NDCG and +4.9% Recall@30. The +3.4% is smaller than the +6.5% measured on the previous lower().split() tokenizer — the stronger BM25 baseline leaves RIF less signal to recover, but the mechanism is still net-positive. Absolute NDCG under RIF moved from 0.315 → 0.342 with the tokenizer upgrade. See BENCHMARKS.md for the live numbers.

² Single measurement: LongMemEval S, Claude Haiku write-time enrichment (gist + anticipated queries + entities + temporal markers concatenated to each chunk before embed/index), evaluated on the 75/500 queries whose answer-relevant turn was in the enriched subset. Covered-bucket NDCG@10 moved 0.390 (RIF alone) → 0.473 (+21.3% rel, +8.3pp abs); diluted across all 500 queries that's +1.2pp. Measured on the previous BM25 tokenizer — on the current regex tokenizer the lift is expected to land somewhere in the 15–25% band, since better BM25 closes some of the vocabulary-mismatch gap enrichment was filling (same "smaller relative gain on a stronger baseline" effect we saw with RIF). Numbers will also vary with model choice (Haiku vs Sonnet vs Opus), corpus domain, and how well the base retriever already covers the vocabulary. Raw table: BENCHMARKS_RIF_ENRICHED.md.

Scope. The RIF gain is workload-specific. The mechanism targets the chronic-false-positive pattern in a single user's long-term conversation memory. On NFCorpus (a non-conversational medical IR benchmark) it doesn't transfer: three of four variants significantly regress. We diagnose this in the arXiv paper (corpus saturation + workload mismatch) and scope the claim to long-term conversational memory. Use lethe for what it's good at; don't expect it to help on general ad-hoc retrieval.

Full methodology in BENCHMARKS.md. 18 checkpoints (11 failed or null) in RESEARCH_JOURNEY.md. Statistical rigor and the NFCorpus replication in arxiv/paper.tex.

How it works

ARCHITECTURE.md - pipeline diagram, RIF formula, storage layers, entry lifecycle, cross-project search.

RESEARCH_JOURNEY.md - 18 checkpoints from biology-inspired mutation (all failed) through cognitive-science RIF (+6.5% on conversational memory, does not generalize to ad-hoc IR) to LLM enrichment (+21% on covered queries) and statistical rigor with a second-dataset replication.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lethe_memory-0.6.0.tar.gz (6.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lethe_memory-0.6.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

lethe_memory-0.6.0-cp39-abi3-macosx_11_0_arm64.whl (20.3 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file lethe_memory-0.6.0.tar.gz.

File metadata

  • Download URL: lethe_memory-0.6.0.tar.gz
  • Upload date:
  • Size: 6.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lethe_memory-0.6.0.tar.gz
Algorithm Hash digest
SHA256 da361e7a6e9639e2bde4d5f7035cd377481a495e643df024f9b46e64d5338bef
MD5 6aa077cac8f29bac30af2f6164454fed
BLAKE2b-256 ae82357ef9359bdc83f346fd53a7a10be0fd67a31e4574712e0724d850d89495

See more details on using hashes here.

Provenance

The following attestation bundles were made for lethe_memory-0.6.0.tar.gz:

Publisher: release-please.yml on teimurjan/lethe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lethe_memory-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: lethe_memory-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lethe_memory-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9746c61f0d9feacd16ba05fc8bceed7d94ff89ffae97e9cb09d9534d963bf09
MD5 7a40adefccdd1564f3a7a692fa7ea109
BLAKE2b-256 4b7faf06cd8a485e951d8f8f535345e784be106e0237a7b490952d3da87c7d09

See more details on using hashes here.

Provenance

The following attestation bundles were made for lethe_memory-0.6.0-py3-none-any.whl:

Publisher: release-please.yml on teimurjan/lethe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lethe_memory-0.6.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lethe_memory-0.6.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fe44b05ab04cc2f8a1ea64133d2778d264fca7a7b8b37fb5271dcd372d8b3c3
MD5 fd5790bd0f3e731549937a775a0e9416
BLAKE2b-256 c7b44ea41dc909f51fad6f19886845be5debee88ce43b5fa7477d8bc5d8d0cf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lethe_memory-0.6.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-pypi.yml on teimurjan/lethe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page