This project implements the Recursive Language Models (RLMs) paper for processing arbitrarily long contexts with language models.
Recursive Language Models
Alex L. Zhang, Tim Kraska, Omar Khattab
arXiv:2512.24601
https://arxiv.org/abs/2512.24601
Create a .env file in the project root:
cp .env.example .envEdit .env and add your Gemini API key:
GEMINI_API_KEY=your-api-key-here
Get your key at https://aistudio.google.com/apikey
source venv_rlm/bin/activatejupyter notebook RLM_demo.ipynbOr use JupyterLab:
jupyter labSelect the "Python (venv_rlm)" kernel when running the notebook.
rlm-implementation/
├── RLM_paper.pdf # The original RLM paper
├── RLM_demo.ipynb # Demo Jupyter notebook
├── README.md # This file
├── .env.example # Template for API keys
├── .env # Your API keys (create this)
├── data/
│ └── long_context.txt # Test document for RLM queries
├── logs/ # RLM trajectory logs
├── rlm/ # Official RLM repository (cloned)
│ ├── examples/ # Example scripts
│ ├── rlm/ # Core RLM package
│ ├── visualizer/ # Trajectory visualization tool
│ └── ...
└── venv_rlm/ # Python virtual environment
- Gemini 2.5 Flash (default) via Google AI API
- Can be changed to other Gemini models in the notebook
data/long_context.txt- A synthetic narrative document about "Dataville" (~2500 words)- Contains embedded facts, questions, and numerical data for Q&A testing
The RLM supports multiple environments:
| Environment | Description | Use Case |
|---|---|---|
local |
Python exec in host process | Development, testing |
docker |
Isolated Docker container | Safety-conscious usage |
modal |
Modal cloud sandboxes | Production, isolation |
prime |
Prime Intellect sandboxes | Production, isolation |
After running queries, log files are saved to ./logs/. To visualize:
cd rlm/visualizer
npm install
npm run devAccess the visualizer at http://localhost:3001
If you see "cannot import name 'RLM' from 'rlm'", ensure you're using the correct kernel:
- Select "Python (venv_rlm)" in Jupyter
The notebook will warn you if GEMINI_API_KEY is not set. Create a .env file with your key.
For large contexts, you may hit OpenAI rate limits. Consider using gpt-4o-mini for testing.
The RLM library is under MIT License. See rlm/LICENSE for details.