{"id":27151223,"url":"https://github.com/Agent-RL/ReSearch","last_synced_at":"2025-04-08T14:25:08.736Z","repository":{"id":284619098,"uuid":"942031817","full_name":"Agent-RL/ReSearch","owner":"Agent-RL","description":"ReSearch: Learning to Reason with Search for LLMs via Reinforcement Learning","archived":false,"fork":false,"pushed_at":"2025-03-26T19:28:47.000Z","size":2750,"stargazers_count":333,"open_issues_count":4,"forks_count":19,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-26T20:30:50.583Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Agent-RL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-03T13:12:19.000Z","updated_at":"2025-03-26T19:28:51.000Z","dependencies_parsed_at":"2025-03-26T20:42:02.236Z","dependency_job_id":null,"html_url":"https://github.com/Agent-RL/ReSearch","commit_stats":null,"previous_names":["agent-rl/research"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-RL%2FReSearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-RL%2FReSearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-RL%2FReSearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-RL%2FReSearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Agent-RL","download_url":"https://codeload.github.com/Agent-RL/ReSearch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247858223,"owners_count":21007888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-08T14:25:06.945Z","updated_at":"2025-04-08T14:25:08.730Z","avatar_url":"https://github.com/Agent-RL.png","language":"Python","funding_links":[],"categories":["Overview","A01_文本生成_文本对话","Reinforcement Learning","📄 Papers","RelatedRepos"],"sub_categories":["Agentic Applications","大语言对话模型及数据","Dynamic Multi‑Agent Workflow \u003ca id=\"dynamic-multi-agent-workflow\"\u003e\u003c/a\u003e","ReSearch","Advanced Reasoning for Agent"],"readme":"\u003cdiv align=\"center\"\u003e\n\n# ***ReSearch***: Learning to ***Re***ason with ***Search*** for LLMs via Reinforcement Learning\n\n[![Arxiv](https://img.shields.io/badge/paper-A82F27?style=for-the-badge\u0026logo=arxiv)](https://arxiv.org/abs/2503.19470) [![Model](https://img.shields.io/badge/model-4169E1?style=for-the-badge\u0026logo=huggingface)](https://huggingface.co/collections/agentrl/research-67e506a0311bea06dc54878b) \n\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./assets/intro_bar.png\" width=\"90%\" alt=\"Intro\" /\u003e\n\u003cimg src=\"./assets/method.png\" width=\"90%\" alt=\"Method\" /\u003e\n\u003c/p\u003e\n\nWe propose ***ReSearch***, a novel framework that trains LLMs to ***Re***ason with ***Search*** via reinforcement learning without using any supervised data on reasoning steps. Our approach treats search operations as integral components of the reasoning chain, where when and how to perform searches is guided by text-based thinking, and search results subsequently influence further reasoning.\n\n## 📰 News\n- **[2025-03-27]** 🤗 We release our trained models on [Hugging Face](https://huggingface.co/collections/agentrl/research-67e506a0311bea06dc54878b), please check it out! \n- **[2025-03-26]** 🎉 We release the paper, update the code and open-source the models.\n  - 📝 The **paper is released** on arXiv, more details and evaluation results can be found in our [paper](https://arxiv.org/abs/2503.19470).\n  - 🛠️ The **repository is updated** with the new implementation, especially the rollout with search during RL training. This version of implementation is based on the latest release of verl.\n- **[2025-03-03]** ✅ We have released the preview version of ReSearch implementation.\n\n## 📦 Installation\n\nWe recommend using conda to manage the environment. First create a conda environment and activate it.\n```bash\nconda create -n re-search python==3.10\nconda activate re-search\n```\nThen install dependencies, and our modified verl and flashrag packages  under ```src/``` will be installed in the editable mode.  Check out ```setup.py``` for details.\n```bash\npip3 install torch==2.4.0 --index-url https://download.pytorch.org/whl/cu124\npip3 install flash-attn --no-build-isolation\ngit clone https://github.com/Agent-RL/ReSearch.git\ncd ReSearch\npip3 install -e .\n```\nAs described in the [FlashRAG](https://github.com/RUC-NLPIR/FlashRAG?tab=readme-ov-file#wrench-installation), due to the incompatibility when installing faiss using pip, we need to use the following conda command to install faiss-gpu.\n```bash\nconda install -c pytorch -c nvidia faiss-gpu=1.8.0\n```\n\n## 🚀 Quick Start\n\n### Retriever Serving\n\nAs described in our paper, during model training and evaluation, search operation will be conducted in the rollout and inference process. In practice, we host a retriever service via FlashRAG and FastAPI. Hence, the search operation is standardized to be an API call. This serving can be used to decouple the search operation from the reinforcement learning process, making the training and evaluation more clear and flexible.\n\nBefore starting the retriever serving, you need download the [pre-indexed wikipedia](https://github.com/RUC-NLPIR/FlashRAG?tab=readme-ov-file#index), [wikipedia corpus and corresponding retriever models](https://github.com/RUC-NLPIR/FlashRAG/blob/main/docs/original_docs/reproduce_experiment.md#preliminary). More details can be found in the documentation of FlashRAG.\n\nFor starting the retriever serving, you need to first fill the `scripts/serving/retriever_config.yaml` with the correct path to the retrieval model, index, and corpus, and available GPU ids. Then, you can run the following command to start the retriever serving:\n```bash\ncd scripts/serving\npython retriever_serving.py \\\n    --config retriever_config.yaml \\\n    --num_retriever {num_retriever} \\  \n    --port {port}\n```\n\nThe started retriever serving will be used in the training and evaluation process in the following part.\n\n### Data Preparation\n\n*ReSearch* is trained on the training set of MuSiQue, and evaluated on the dev set of HotpotQA, 2WikiMultiHopQA, MuSiQue and Bamboogle. For downloading the datasets, please refer to the `data/download_dataset.sh` script.\n```bash\ncd data\nbash download_dataset.sh\n```\n\nFor preparing the training and validation data for following reinforcement learning, please run this script to parse the MuSiQue dataset to the parquet format.\n```bash\ncd data\npython prepare_musique.py\n```\n\n### Training\n\nOur training framework is based on [verl](https://github.com/volcengine/verl), a powerful reinforcement learning framework for LLMs. We deeply customize the verl code to fit our needs, and the modified version of verl is under the `src/verl` directory. The example of training scripts are under `scripts/train`.\n\n#### Single-node training\nHere is an example of training Qwen2.5-7B-Instruct with 4 GPUs locally. Note that the training script below **is just an example** for single-node training, using small batch size for quick start, and do not assure the training performance.\n```bash\ncd scripts/train\nbash train.sh \\\n    --train_batch_size 8 \\\n    --ppo_mini_batch_size 8 \\\n    --apply_chat True \\\n    --prompt_template_name re_search_template_sys \\\n    --actor_model_path {model/path/to/qwen2.5-7b-instruct} \\\n    --search_url {your-hosted-retriever-url} \\\n    --project_name {wandb-project-name} \\\n    --experiment_name {wandb-experiment-name} \\\n    --nnodes 1 \\\n    --n_gpus_per_node 4 \\\n    --save_freq 5 \\\n    --test_freq 5 \\\n    --total_epochs 2 \\\n    --wandb_api_key {your-wandb-api-key} \\\n    --save_path {path/to/save} \\\n    --train_files {path/to/train/parquet/data} \\\n    --test_files {path/to/test/parquet/data}\n```\n- For training base (pre-trained) models, please use `--apply_chat False` and `--prompt_template_name re_search_template`\n- For training instruction-tuned models, please use `--apply_chat True` and `--prompt_template_name re_search_template_sys`\n\n#### Multi-node training\n\nIf you want to **fully reproduce** the results in our paper, please refer to the multi-node training script in `scripts/train/train_multi_node.sh`, as well as the implementation details in our paper.\n\n### Evaluation\n\nWe recommend using [SGLang](https://docs.sglang.ai/) to serve the trained model. You can download our open-sourced models or trained your own models to conduct the evaluation. Here is an example of launching the model serving:\n```bash\npython3 -m sglang.launch_server \\\n        --served-model-name {trained/model/name} \\\n        --model-path {trained/model/path} \\\n        --tp 2 \\\n        --context-length 8192 \\\n        --enable-metrics \\\n        --dtype bfloat16 \\\n        --host 0.0.0.0 \\\n        --port 80 \\\n        --trust-remote-code \\\n        --disable-overlap \\\n        --disable-radix-cache\n```\n\nWe use [FlashRAG](https://github.com/RUC-NLPIR/FlashRAG) as the standard evaluation environment. Here is an example of evaluating the performance of ReSearch-Qwen-7B-Instruct on Bamboogle test set.\n```bash\ncd scripts/evaluation\npython run_eval.py \\\n    --config_path eval_config.yaml \\\n    --method_name research \\\n    --data_dir {root/path/to/evaluation/data} \\\n    --dataset_name bamboogle \\\n    --split test \\\n    --save_dir {your-save-dir} \\\n    --save_note research_qwen7b_ins\n    --sgl_remote_url {your-launched-sgl-url} \\\n    --remote_retriever_url {your-hosted-retriever-url} \\\n    --generator_model {your-local-model-path} \\\n    --apply_chat True\n```\n\nFor base model, please use `--apply_chat False` and for instruction-tuned model, please use `--apply_chat True`, for loading correct prompt template when conducting evaluation for *ReSearch* model. For more details about the configuration, please refer to the `scripts/evaluation/eval_config.yaml` file. \n\n## 🤝 Acknowledge\n\nThis training implementation is based on [verl](https://github.com/volcengine/verl) and the evaluation is based on [FlashRAG](https://github.com/RUC-NLPIR/FlashRAG). The serving of retriever is based on [FastAPI](https://github.com/fastapi/fastapi). The model serving is based on [SGLang](https://docs.sglang.ai/). *ReSearch* models are trained based on [Qwen2.5](https://qwenlm.github.io/blog/qwen2.5/). We sincerely appreciate their contributions to the open-source community.\n\n## 📚 Citation\n\nIf you find this work useful, please cite it as follows:\n```bibtex\n@misc{chen2025research\n  title={ReSearch: Learning to Reason with Search for LLMs via Reinforcement Learning}, \n  author={Mingyang Chen and Tianpeng Li and Haoze Sun and Yijie Zhou and Chenzheng Zhu and Haofen Wang and Jeff Z. Pan and Wen Zhang and Huajun Chen and Fan Yang and Zenan Zhou and Weipeng Chen},\n  year={2025},\n  eprint={2503.19470},\n  archivePrefix={arXiv},\n  primaryClass={cs.AI},\n  url={https://arxiv.org/abs/2503.19470}, \n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAgent-RL%2FReSearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAgent-RL%2FReSearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAgent-RL%2FReSearch/lists"}