# E2-Mem
### An Episodic-Event Hierarchical Memory Framework for Long-Term Web-Based LLM Agents
[](#paper-results)
[](#quick-start)
[](#paper-results)
[](https://github.com/jianminYa/e2mem/actions/workflows/ci.yml)
[](LICENSE)
[Interactive demo](https://jianminya.github.io/e2mem/) · [Paper results](docs/PAPER_RESULTS.md) · [Reproduction guide](REPRODUCING.md) · [Architecture](docs/architecture.md)
E2-Mem organizes long conversations as an **episode–event hierarchy**: episodes preserve local conversational context, while child events retain fine-grained, answer-supporting evidence. At query time it retrieves episodes with hybrid lexical–semantic search, expands their events, and reranks the evidence before answer generation.
## Overview
### Memory construction
Conversation sessions are chunked into local segments. An LLM extracts episode summaries and their child events; SQLite stores the hierarchy, while Redis and Qdrant provide lexical and semantic episode indexes.
### Hierarchical retrieval
The query path first recalls candidate episodes, then expands and reranks child events to form a compact, evidence-grounded answer context.
## Demo
The fully static browser demo compares recorded E2-Mem and Mem0 retrieval traces for ten curated questions from one complete LoCoMo conversation. It exposes the episode-to-child-event hierarchy, ranked atomic memories, source-turn provenance, and recorded answers without making API calls. The cases explain retrieval mechanisms; aggregate results remain in the paper tables.
## Paper results
All values below are the **paper-reported results** from the accepted manuscript. The benchmark scope is the 10-conversation LoCoMo set, Categories 1–4, with 1,540 questions. Fresh model calls can drift; see [Reproducing the results](REPRODUCING.md) for the clean-clone validation and protocol notes.
### Overall answer quality — Table 1
| Method | F1 | BLEU-1 | LLM Judge | Avg. answer tokens |
|---|---:|---:|---:|---:|
| Mem0 top30 | 0.4224 | 0.3429 | 0.5922 | 5.67 |
| A-Mem* | 0.4047 | 0.3321 | 0.6110 | 4.58 |
| REMem-S* | 0.4607 | 0.3616 | 0.6675 | 5.13 |
| **E2-Mem** | **0.4767** | **0.3941** | **0.7409** | 5.20 |
`*` denotes the answer-token-aligned variants used for the controlled comparison in the paper.
### Evidence retrieval — Table 2
| Method | Hit@k | Recall@k | Last-rank score | All-hit rate |
|---|---:|---:|---:|---:|
| Mem0 top30 | 0.8097 | 0.7386 | 0.2838 | 0.6708 |
| **E2-Mem** | **0.8987** | **0.8274** | **0.4124** | **0.7559** |
### E2-Mem by question type — Table 3
| Metric | Multi-hop | Temporal | Open domain | Single-hop |
|---|---:|---:|---:|---:|
| F1 | 35.74 | **56.85** | 26.34 | 50.61 |
| BLEU-1 | 25.27 | **44.45** | 21.09 | 44.31 |
| LLM Judge | 64.89 | **76.01** | 42.71 | **80.02** |
The complete comparison tables, retrieval-cost boundary, and ablation notes are in [docs/PAPER_RESULTS.md](docs/PAPER_RESULTS.md). Machine-readable reference values live in [`experiments/locomo/expected_results.json`](experiments/locomo/expected_results.json).
## Quick start
The full paper pipeline targets Linux, Python 3.12, Redis 8.0.2, and Qdrant 1.19.0. Docker is the simplest way to start the two local services.
```bash
git clone https://github.com/jianminYa/e2mem.git
cd e2mem
./scripts/setup.sh
conda activate e2mem # or: source .venv/bin/activate
cp .env.example .env
# Add your OpenAI-compatible API key/base URL to .env.
./scripts/start_services.sh
python -m e2mem.download_locomo
python -m e2mem.repro_doctor --mode from-scratch
```
Run a low-cost, one-conversation pipeline check first:
```bash
./scripts/run_smoke.sh
```
Then reproduce every E2-Mem experiment in Tables 1–5:
```bash
export BATCH_NAME=tri_h1_episode_hier_fixed_v2_full10
export RUN_DIR="$PWD/results/reproduction_$(date -u +%Y%m%dT%H%M%SZ)"
./scripts/reproduce_all.sh
```
The stages are resumable and can be run independently. See [REPRODUCING.md](REPRODUCING.md) for environment variables, output files, expected API cost behavior, exact commands, and the distinction between paper-reported and fresh-run results.
## Reproduction coverage
| Paper table | E2-Mem output | Entry point |
|---|---|---|
| Table 1 | Overall F1, BLEU-1, LLM-Judge, answer tokens | `scripts/reproduce_table1_table3.sh` |
| Table 2 | Event-level gold evidence retrieval | `scripts/reproduce_table2.sh` |
| Table 3 | Answer quality by question type | `scripts/reproduce_table1_table3.sh` |
| Table 4 | Retrieval latency and answer-time memory tokens | `scripts/reproduce_table4.sh` |
| Table 5 | Full, Qdrant-only, and episode-only ablations | `scripts/reproduce_table5.sh` |
Reproduction of A-Mem, Mem0, REMem, and Zep/Graphiti is intentionally outside this release.
## Repository layout
```text
e2mem/ Core construction, indexing, retrieval, and evaluation code
configs/paper/ Reviewer-readable paper configurations
experiments/locomo/ Executable configs, manifest, and expected paper values
scripts/ Setup, smoke test, and Tables 1–5 entry points
tests/ Unit and protocol-invariant tests
docs/demo/ Recorded LoCoMo retrieval comparison demo
assets/ Paper architecture figures and README media
```
## Citation
Please cite the WISE 2026 paper **“E²-Mem: An Episodic-Event Hierarchical Memory Framework for Long-Term Web-Based LLM Agents.”** Proceedings metadata and the final author-formatted BibTeX will be added when publicly available.
## License and data
The code is released under the [MIT License](LICENSE). LoCoMo is downloaded from its pinned upstream commit at setup time and remains subject to the upstream CC BY-NC 4.0 license. LoCoMo-derived fields embedded in the recorded demo remain under CC BY-NC 4.0; see [`docs/demo/DATA_LICENSE.md`](docs/demo/DATA_LICENSE.md).