为应对这些挑战,本文提出了SEARCH-R1,一个新颖的强化学习(RL)框架,它通过以下创新使LLMs能够在其推理过程中自主地与搜索引擎进行交错式交互:
1. 分析了在LLM推理中应用强化学习以改进搜索引擎使用的挑战和视角。本文指出了将搜索引擎集成到RL框架中存在的三个关键挑战:框架集成与稳定性、多轮交错推理与搜索、以及奖励函数设计。
2. 提出了SEARCH-R1框架。这是一个支持LLM直接与搜索引擎进行rollout和优化的新颖RL框架。其核心特性包括:
* 检索Token屏蔽(Retrieved Token Masking):在计算RL损失时,仅考虑LLM生成的Token,忽略从搜索引擎检索到的Token,从而稳定训练过程。
* 多轮交错推理与搜索:模型能够通过生成特殊的<search>和</search> Token来多次调用搜索引擎,并将检索到的信息(包裹在<information>和</information>中)用于后续的逐步推理(包裹在<think>和</think>中),以解决复杂问题。
* 简单的结果导向奖励函数:采用简单的基于最终答案正确性的奖励函数,避免了设计复杂的过程奖励,并证明了其在搜索-推理场景中的有效性。
3. 进行了系统的实验验证。在七个问答数据集上进行的实验表明,SEARCH-R1的性能显著优于多种基线方法。在相同实验设置下,Qwen2.5-7B和Qwen2.5-3B模型相较于RAG基线分别取得了41%和20%的平均相对性能提升。此外,本文还提供了关于RL方法选择(PPO vs. GRPO)、不同LLM选择(基础模型 vs. 指令微调模型)以及响应长度动态变化的经验性见解。
A3 背景知识
2.1 大型语言模型与检索
尽管大型语言模型(LLMs)【60, A survey of large language models, 2023, arXiv】【45, Gemini 1.5: Unlocking multimodal understanding across millions of tokens of context, 2024, arXiv】【1, Gpt-4 technical report, 2023, arXiv】在推理【10, Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning, 2025, arXiv】和编码【9, Deepseek-coder: When the large language model meets programming–the rise of code intelligence, 2024, arXiv】方面展现出卓越的能力,但它们通常缺乏特定领域的知识【35, A study of generative large language model for medical research and healthcare, 2023, NPJ digital medicine】【29, Large language models in finance: A survey, 2023, Proceedings of the fourth ACM international conference on AI in finance】,并且容易产生幻觉【59, Siren’s song in the ai ocean: a survey on hallucination in large language models, 2023, arXiv】。为缓解这些限制,搜索引擎【61, Dense text retrieval based on pretrained language models: A survey, 2024, ACM Transactions on Information Systems】被广泛集成以提供外部信息。主要有两种集成方式:(1)检索增强生成(RAG)【7, Retrieval-augmented generation for large language models: A survey, 2023, arXiv】和(2)将搜索引擎视为工具【39, Toolformer: Language models can teach themselves to use tools, 2023, Advances in Neural Information Processing Systems】。RAG【26, Retrieval-augmented generation for knowledge-intensive nlp tasks, 2020, Advances in neural information processing systems】【58, Inference scaling for long-context retrieval augmented generation, 2024, arXiv】【53, Rag-gym: Optimizing reasoning and search agents with process supervision, 2025, arXiv】通常遵循检索和序贯生成的流程,搜索引擎根据输入查询获取相关信息,然后与查询拼接后输入LLM。然而,这可能面临检索到不相关信息【18, Long-context llms meet rag: Overcoming challenges for long inputs in rag, 2024, The Thirteenth International Conference on Learning Representations】和无法提供足够有用上下文【17, Active retrieval augmented generation, 2023, Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing】的挑战。另一种方法是“搜索即工具”,通过提示或微调使LLM与搜索引擎交互。IRCoT【46, Interleaving retrieval with chain-of-thought reasoning for knowledge-intensive multi-step questions, 2022a, arXiv】和ReAct【56, React: Synergizing reasoning and acting in language models, 2023, International Conference on Learning Representations (ICLR)】使用提示引导迭代推理和搜索引擎调用,而Toolformer【39, Toolformer: Language models can teach themselves to use tools, 2023, Advances in Neural Information Processing Systems】则利用监督微调来增强搜索能力。然而,这些方法依赖于高质量的标注轨迹,难以大规模获取。最近的研究【10, Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning, 2025, arXiv】表明,RL仅用结果奖励就能使LLM发展出高级推理技能,但其在搜索引擎调用场景中的潜力仍未被充分探索。
2.2 大型语言模型与强化学习
强化学习(RL)【20, Reinforcement learning: A survey, 1996, Journal of artificial intelligence research】是一种学习范式,代理通过与环境交互并以奖励形式接收反馈来学习做出序贯决策,旨在最大化长期累积奖励【44, Reinforcement learning, 1999, Journal of Cognitive Neuroscience】。Ouyang等人【33, Training language models to follow instructions with human feedback, 2022, Advances in neural information processing systems】通过基于人类反馈的强化学习(RLHF)【22, A survey of reinforcement learning from human feedback, 2023, arXiv】将RL引入LLM调优。该方法首先使用人类偏好数据【25, Rewardbench: Evaluating reward models for language modeling, 2024, arXiv】训练一个奖励模型,然后该模型通过RL(通常是近端策略优化,PPO)来指导策略LLM的调优。然而,PPO涉及多轮LLM优化,实现起来具有挑战性。为了简化基于RL的调优,直接优化方法如直接偏好优化(DPO)【38, Direct preference optimization: Your language model is secretly a reward model, 2023, Advances in Neural Information Processing Systems】和SimPO【32, Simpo: Simple preference optimization with a reference-free reward, 2024, Advances in Neural Information Processing Systems】被提出。LeRet【14, Grounding by trying: Llms with reinforcement learning-enhanced retrieval, 2024, arXiv】也采用了类似方法,训练LLM探索多样化查询以增强信息检索效果。虽然这些方法计算效率高,但存在离策略问题【34, Iterative reasoning preference optimization, 2024, Advances in Neural Information Processing Systems】,且性能不总能与纯RL方法相媲美。替代方案包括组相对策略优化(GRPO)【42, Deepseekmath: Pushing the limits of mathematical reasoning in open language models, 2024, arXiv】,它通过从组得分中估计基线来消除对评论家模型的需求;以及RLOO【2, Back to basics: Revisiting reinforce style optimization for learning from human feedback in llms, 2024, arXiv】,它引入了一个简化的REINFORCE风格【51, Simple statistical gradient-following algorithms for connectionist reinforcement learning, 1992, Machine learning】优化框架。尽管取得了这些进展,但RL在LLM驱动的搜索引擎交互和推理中的应用在很大程度上仍未被探索。
A2 方法细节
3.1 包含搜索引擎的强化学习
RL目标函数: 我们将利用搜索引擎R的RL目标函数公式化如下:
其中,$ \pi_{\theta} $是策略LLM,$ \pi_{\text{ref}} $是参考LLM,$ r_{\phi} $是奖励函数,$ D_{\text{KL}} $是KL散度度量。$ x $表示从数据集D中抽取的输入样本,$ y $表示与搜索引擎调用结果交错生成的输出,从参考策略$ \pi_{\text{ref}}(y | x) $中采样并从搜索引擎R中检索。与先前主要依赖策略LLM$ \pi_{\theta}(\cdot | x) $生成rollout序列的RL方法【38, Direct preference optimization: Your language model is secretly a reward model, 2023, Advances in Neural Information Processing Systems】【33, Training language models to follow instructions with human feedback, 2022, Advances in neural information processing systems】不同,我们的框架通过$ \pi_{\theta}(\cdot | x; R) $显式地融入了交错检索的推理,这可以看作是$ \pi_{\theta}(\cdot | x) \mathbb{N} R $,其中$ \mathbb{N} $表示交错的检索与推理。这使得在需要外部信息检索的推理密集型任务中能进行更有效的决策。rollout过程的图示和公式1的解释在3.2节和附录A中提供。我们的方法建立在两种成熟的策略梯度RL方法之上:近端策略优化(PPO)【41, Proximal policy optimization algorithms, 2017】和组相对策略优化(GRPO)【42, Deepseekmath: Pushing the limits of mathematical reasoning in open language models, 2024, arXiv】【10, Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning, 2025, arXiv】,利用它们各自的优势来优化检索增强的推理。
基于结果的奖励函数: 奖励函数作为主要的训练信号,指导RL中的优化过程。为了训练SEARCH-R1,我们采用了一个基于规则的奖励系统,该系统仅包含最终结果奖励,用于评估模型响应的正确性。例如,在事实推理任务中,可以使用基于规则的标准(如精确字符串匹配)来评估正确性:
其中$ a_{\text{pred}} $是从响应y中提取的最终答案,$ a_{\text{gold}} $是基准答案。与Guo等人【10, Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning, 2025, arXiv】不同,我们没有引入格式奖励,因为我们学习到的模型已经表现出很强的结构遵循能力。我们将更复杂的格式奖励的探索留给未来的工作。此外,我们遵循Guo等人【10】的做法,避免训练神经奖励模型。这个决定是出于LLM在大规模RL中对特定奖励形式的敏感性,以及重新训练这些模型所带来的额外计算成本和复杂性。
A4 实验环境与结果
实验环境
数据集: 在七个基准数据集上评估SEARCH-R1,分为两类:(1) 通用问答: NQ【24, Natural questions: a benchmark for question answering research, 2019, Transactions of the Association for Computational Linguistics】、TriviaQA【19, Triviaqa: A large scale distantly supervised challenge dataset for reading comprehension, 2017, arXiv】和PopQA【31, When not to trust language models: Investigating effectiveness and limitations of parametric and non-parametric memories, 2022, arXiv】。(2) 多跳问答: HotpotQA【55, Hotpotqa: A dataset for diverse, explainable multi-hop question answering, 2018, arXiv】、2WikiMultiHopQA【12, Constructing a multi-hop qa dataset for comprehensive evaluation of reasoning steps, 2020, arXiv】、Musique【47, Musique: Multihop questions via single-hop question composition, 2022b, Transactions of the Association for Computational Linguistics】和Bamboogle【36, Measuring and narrowing the compositionality gap in language models, 2022, arXiv】。训练数据由NQ和HotpotQA的训练集合并而成。
图2:(a) PPO vs. GRPO:GRPO通常收敛更快,但在训练一定步数后可能表现出不稳定性,而PPO提供更稳定的优化但收敛速度较慢。(b) 基础 vs. 指令微调LLM研究:指令微调的LLM收敛更快,但两种模型的最终性能非常相似。(c) 响应长度研究:响应长度在整个训练过程中呈现出减少-增加-稳定的趋势,与LLM的整体性能轨迹一致。(d) 有效搜索次数研究:随着训练的进行,LLM学会了更多地调用搜索。
经典RL框架: 训练LLM的经典RL框架公式如下【38, Direct preference optimization: Your language model is secretly a reward model, 2023, Advances in Neural Information Processing Systems】【33, Training language models to follow instructions with human feedback, 2022, Advances in neural information processing systems】:
其中x是提示,y是策略模型$ \pi_{\theta} $生成的响应,$ \pi_{\text{ref}} $是参考模型。$ r_{\phi}(x, y) $量化响应质量,KL散度项约束更新后的策略接近参考模型以保证稳定性。 扩展RL框架: 然而,该公式假设整个输出序列y完全由策略LLM生成,这在我们的设定中不成立。为适应内部推理和外部信息检索的混合行为,我们将RL目标扩展以包含外部搜索引擎R:
在这个修正的目标中,轨迹$ y \sim \pi_{\theta}(\cdot | x; R) $包含了交错的推理步骤和检索内容,反映了LLM与搜索引擎之间的多轮交互。KL散度是在给定提示和检索增强上下文的联合响应分布上计算的,确保学习到的策略即使在存在外部信息时也与参考模型保持一致。
B 实验设置
基线说明: 最近的一些工作如Re2G【8, Re2g: Retrieve, rerank, generate, 2022, arXiv】和RetroLLM【27, Retrollm: Empowering large language models to retrieve fine-grained evidence within generation, 2024, arXiv】探索了复杂的RAG流程,但它们依赖任务特定的工程或重型流程,限制了通用性。本文关注更轻量和通用的方法,因此未将它们作为直接基线。
💬 评论讨论
欢迎在这里分享您的想法和见解!