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.
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 |
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.
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
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.
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
All models and datasets are available on Hugging Face.
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},
}
We welcome contributions! Please feel free to submit issues and pull requests.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
For questions or collaborations, please contact:
Python
98.1%
Shell
1.6%
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.
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 |
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.
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
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.
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
All models and datasets are available on Hugging Face.
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},
}
We welcome contributions! Please feel free to submit issues and pull requests.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
For questions or collaborations, please contact:
Python
98.1%
Shell
1.6%