R3-RAG: Learning Step-by-Step Reasoning and Retrieval for LLMs via Reinforcement Learning
October 5, 2025 ยท View on GitHub
๐ Overview
R3-RAG is a novel framework that uses Reinforcement learning to teach LLMs how to Reason and Retrieve step by step. Unlike traditional RAG methods that rely on human-designed workflows, R3-RAG enables models to autonomously learn optimal reasoning-retrieval strategies through reinforcement learning with both outcome and process rewards.
Key Features
- ๐ฅ Autonomous Learning: Uses RL to learn reasoning-retrieval strategies instead of relying on fixed human-designed workflows
- ๐ฏ Dual Reward System: Combines outcome rewards (answer correctness) with process rewards (document relevance)
- ๐ Strong Performance: Achieves significant improvements over state-of-the-art iterative RAG methods
- ๐ Transferable: Works across different retrievers (E5, BGE, BM25) with consistent performance
- ๐ Comprehensive: Evaluated on multiple multi-hop QA datasets (HotpotQA, 2WikiMultiHopQA, MuSiQue)
๐ Main Results
Our method significantly outperforms existing baselines across three multi-hop QA datasets:
| Methods | Retriever | HotpotQA | 2WikiMultiHopQA | MuSiQue | Average |
|---|---|---|---|---|---|
| Llama-3.1-8B | |||||
| CoT | - | 39.2 | 28.8 | 14.0 | 27.3 |
| RAG with CoT | E5 | 53.3 | 32.9 | 16.3 | 34.2 |
| IRCoT | E5 | 52.8 | 40.6 | 16.7 | 36.7 |
| R3-RAG | E5 | 64.4 | 61.0 | 32.2 | 52.6 |
| R3-RAG | BGE | 65.3 | 62.1 | 33.8 | 53.8 |
| Qwen2.5-7B | |||||
| CoT | - | 34.0 | 31.1 | 12.7 | 25.9 |
| RAG with CoT | E5 | 52.4 | 33.5 | 16.9 | 34.3 |
| IRCoT | E5 | 48.4 | 35.8 | 13.5 | 32.6 |
| R3-RAG | E5 | 65.5 | 62.3 | 33.6 | 53.8 |
| R3-RAG | BGE | 66.4 | 63.0 | 34.8 | 54.8 |
๐ Quick Start
Environment Setup
We recommend setting up three separate conda environments to avoid dependency conflicts:
-
FlashRAG Environment (for retrieval tools): Please refer to FlashRAG to set up the environment.
-
LLaMA-Factory Environment (for cold start training): Please refer to LLaMA-Factory to set up the environment.
-
OpenRLHF Environment (for RL training): Please refer to OpenRLHF to set up the environment, then install our modified openrlhf code in this repository.
Model Download
Download our pre-trained models from Hugging Face:
# Cold start models
git clone https://huggingface.co/Yuan-Li-FNLP/R3-RAG-CS-Llama
git clone https://huggingface.co/Yuan-Li-FNLP/R3-RAG-CS-Qwen
# Full R3-RAG models
git clone https://huggingface.co/Yuan-Li-FNLP/R3-RAG-Llama
git clone https://huggingface.co/Yuan-Li-FNLP/R3-RAG-Qwen
Quick Demo
Experience R3-RAG with our visualization interface:
# First, start the server
cd startup
bash server.sh
# Then, start the visualization interface
bash startup_visualize.sh
Make sure to configure the model paths and parameters in the startup scripts before running.
๐ Repository Structure
R3-RAG/
โโโ benchmark/ # Evaluation scripts and benchmarks
โ โโโ evaluate.py # Main evaluation script
โ โโโ metrics/ # Evaluation metrics implementation
โ โโโ datasets/ # Dataset loading and processing
โโโ data/ # Cold start data construction
โ โโโ build_coldstart_data.py # Generate high-quality cold start trajectories
โ โโโ data_processing/ # Data preprocessing utilities
โ โโโ templates/ # Prompt templates for data generation
โโโ startup/ # Demo and visualization scripts
โ โโโ server.sh # Start the server
โ โโโ startup_visualize.sh # Start visualization interface
โ โโโ demo_config.py # Configuration for demo
โโโ tool/ # Retrieval tools and services
โ โโโ retrieval/ # Retrieval tool implementations
โ โโโ vllm_service/ # VLLM service code
โ โโโ utils/ # Utility functions
โโโ train/ # Training frameworks
โ โโโ llamafactory/ # SFT training with LLaMA-Factory
โ โ โโโ sft_training.py # Cold start SFT training script
โ โ โโโ configs/ # Training configurations
โ โโโ openrlhf/ # RLHF training with OpenRLHF
โ โโโ rl_training.py # Reinforcement learning training
โ โโโ reward_models/ # Reward model implementations
โ โโโ configs/ # RL training configurations
โโโ README.md # This file
โโโ LICENSE # License file
๐ค Available Models and Data
Models
- R3-RAG-CS-Llama: Cold start model based on Llama-3.1-8B
- R3-RAG-CS-Qwen: Cold start model based on Qwen2.5-7B
- R3-RAG-Llama: Full R3-RAG model based on Llama-3.1-8B
- R3-RAG-Llama-ORM: R3-RAG model with outcome reward only
- R3-RAG-Qwen: Full R3-RAG model based on Qwen2.5-7B
Datasets
- R3-RAG-ColdStartTrainingData: High-quality cold start training trajectories
- R3-RAG-RLTrainingData: Reinforcement learning training data
All models and datasets are available on Hugging Face.
๐ Citation
If you find our work helpful, please consider citing:
@misc{li2025r3raglearningstepbystepreasoning,
title={R3-RAG: Learning Step-by-Step Reasoning and Retrieval for LLMs via Reinforcement Learning},
author={Yuan Li and Qi Luo and Xiaonan Li and Bufan Li and Qinyuan Cheng and Bo Wang and Yining Zheng and Yuxin Wang and Zhangyue Yin and Xipeng Qiu},
year={2025},
eprint={2505.23794},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2505.23794},
}
๐ค Contributing
We welcome contributions! Please feel free to submit issues and pull requests.
๐ License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
๐ Acknowledgments
- FlashRAG for retrieval framework
- LLaMA-Factory for training framework
- OpenRLHF for reinforcement learning framework
๐ Contact
For questions or collaborations, please contact:
- Yuan Li: liyuan24@m.fudan.edu.cn
- Xipeng Qiu: xpqiu@fudan.edu.cn