Controlled benchmark for evaluating memory architectures in long-horizon LLM conversations.
Large Language Model (LLM) agents increasingly operate across long conversations, but maintaining factual consistency over time remains difficult.
This project investigates context collapse — the gradual degradation of factual recall as conversations become longer and memory systems compress, retrieve, or restructure context.
We benchmark four memory architectures under controlled conditions:
- Baseline Memory — Full conversation history
- Hierarchical Memory — Working + Episodic + Semantic memory
- RAG Memory — Retrieval-Augmented Generation using vector search
- Rolling Summary Memory — Incremental conversation summarization
The benchmark evaluates:
- Factual Retention Rate (FRR)
- Context efficiency
- Memory compression tradeoffs
- LLM call overhead
- Domain sensitivity
- Long-horizon conversational robustness
The implementation accompanies the research paper:
Context Collapse in Long-Horizon Agents: Benchmarking Hierarchical Memory against RAG and Summarization
- Hierarchical memory achieved 41.6% FRR
- Baseline retained 40.6% FRR
- Hierarchical memory reduced context usage by ~34.8%
- Rolling Summary reduced context size substantially but introduced additional degradation and higher API usage
- Medical conversations were significantly more fragile than Legal and Technical domains
- Strong evidence of primacy effects appeared across architectures
context_collapse/
│
├── analysis/ # Evaluation and statistical analysis
│ ├── compute_efficiency.py
│ ├── get_plot_data.py
│ ├── graphical_view.py
│ ├── judge.py
│ └── p_value.py
│
├── graphs/ # Generated figures
│ ├── plot_1_primacy_effect.png
│ ├── plot_2_efficiency_frontier.png
│ ├── plot_3_domain_heatmap.png
│ └── plot_4_memory_cost.png
│
├── llm/ # Azure OpenAI integration
│ ├── llm_azure.py
│ └── utils.py
│
├── memory_strategies/
│ ├── base.py
│ ├── baseline.py
│ ├── hierarchical.py
│ ├── rag.py
│ └── rolling_summary.py
│
├── results/
│ ├── histories/
│ ├── efficiency_table_*.csv
│ └── scored_results.csv
│
├── scripts/ # Conversation benchmark datasets
│ ├── all_legal.json
│ ├── all_medical.json
│ ├── all_tech.json
│ └── all_travel.json
│
├── run_benchmark.py
├── requirements.txt
└── paper.pdfStores the entire conversation history.
- No compression
- Maximum context growth
- Reference upper-bound for recall
Multi-layer memory architecture.
- Working Memory
- Episodic Memory
- Semantic Memory
- Controlled compression
- Fact preservation
- Structured memory updates
- Lower token usage
Retrieval-based memory using:
- ChromaDB
- Sentence Transformers
Combines:
- Semantic similarity
- Recency weighting
Continuously compresses dialogue into structured summaries.
Pros:
- Lower context size
Cons:
- Additional LLM calls
- Information loss accumulation
Benchmark scripts span four domains:
| Domain | Focus |
|---|---|
| Legal | Contracts, compliance |
| Medical | Healthcare facts |
| Tech | Technical configurations |
| Travel | Long conversational planning |
- Inject factual information early
- Continue conversation
- Ask delayed recall questions
- Retrieve memory context
- Evaluate correctness
- Repeat across strategies
Measures recall accuracy.
[ FRR = Correct\ Recall / Total\ Recall ]
Average factual retention across recall distances.
- Average context tokens
- LLM calls
- Compression overhead
Clone repository:
git clone https://github.com/ebaadraheem/context_collapse.git
cd context_collapseCreate environment:
python -m venv venvActivate:
Linux / macOS:
source venv/bin/activateWindows:
venv\Scripts\activateInstall dependencies:
pip install -r requirements.txtCreate .env
AZURE_OPENAI_ENDPOINT=
AZURE_OPENAI_KEY=
AZURE_DEPLOYMENT_NAME=Run default benchmark:
python run_benchmark.pyRun custom script folder:
python run_benchmark.py \
--scripts_dir scripts \
--output_suffix experiment_1Outputs:
results/
├── histories/
├── raw_results.csv
└── scored_results.csvCompute efficiency:
python analysis/compute_efficiency.py \
--scored results/scored_results.csv \
--history results/histories/Generate plots:
python analysis/graphical_view.pyCalculate significance:
python analysis/p_value.pyJudge responses:
python analysis/judge.py- Does compression improve factual retention?
- Does retrieval outperform summarization?
- How expensive is memory compression?
- Which domains collapse first?
- Can hierarchical memory replace full context?
Generated outputs include:
results/
graphs/
histories/Artifacts:
- Efficiency tables
- Recall statistics
- Token usage
- Visualization plots
The benchmark is designed for reproducible experimentation.
Includes:
- Fixed conversation scripts
- Controlled recall positions
- Consistent evaluation pipeline
- Deterministic benchmarking structure
If you use this repository:
@article{raheem2026contextcollapse,
title={Context Collapse in Long-Horizon Agents: Benchmarking Hierarchical Memory against RAG and Summarization},
author={Raheem, Ebaad and Naseer, Danish and Mustafa, Ghulam},
year={2026}
}- Multi-agent memory systems
- Agentic long-term planning
- Adaptive compression
- Memory-aware orchestration
- Production deployment benchmarks
This project is licensed under the MIT License — see the LICENSE file for details.
Ebaad Raheem Department of Information Technology University of the Punjab, Gujranwala Campus
If this project helps your work, consider starring the repository.