arXiv:2605.12975cs.AI2026-05被引 2

用可执行代码重构多跳问答,让推理过程透明可控。

Retrieval is Cheap, Show Me the Code: Executable Multi-Hop Reasoning for Retrieval-Augmented Generation

论文配图:Retrieval is Cheap, Show Me the Code: Executable Multi-Hop Reasoning for Retrieval-Augmented Generation
图 1 · 摘自论文原文
  • 将多跳推理转为可运行的Python程序,中间状态显式暴露
  • 在5个基准上超越强基线,尤其在复杂组合题上提升显著
  • 无需额外训练即可实现自动修复与动态检索,适合追求可解释性的研究者

检索增强生成(RAG)已成为知识密集型问答的标准方法,但现有系统在多跳问题上仍脆弱,因需串联多个检索与推理步骤。主要挑战包括:推理以自由文本形式表达,中间状态隐含;检索查询易偏离目标实体;错误由同一模型检测,自省信号不可靠且无依据。我们观察到多跳问答本质上是逐步计算过程,与代码专用语言模型的训练方式高度契合。因此提出 exttt{PyRAG} 框架,将多跳 RAG 重构成程序合成与执行任务。相比自由文本推理轨迹, exttt{PyRAG} 将推理过程表示为对检索与问答工具的可执行 Python 程序,显式暴露中间状态,通过执行获得确定性反馈,并生成可检查的完整推理轨迹。该框架还支持无需额外训练的编译器级自修复与执行驱动的自适应检索。在五个问答基准(PopQA、HotpotQA、2WikiMultihopQA、MuSiQue、Bamboogle)上的实验表明, exttt{PyRAG} 在无需训练和强化学习训练设置下均持续优于强基线,尤其在组合型多跳数据集上提升显著。代码、数据与模型已公开于 https://github.com/GasolSun36/PyRAG。

原文摘要 · Abstract (English)

Retrieval-Augmented Generation (RAG) has become a standard approach for knowledge-intensive question answering, but existing systems remain brittle on multi-hop questions, where solving the task requires chaining multiple retrieval and reasoning steps. Key challenges are that current methods represent reasoning through free-form natural language, where intermediate states are implicit, retrieval queries can drift from intended entities, and errors are detected by the same model that produces them making self-reflection an unreliable, ungrounded signal. We observe that multi-hop question answering is a typical form of step-by-step computation, and that this structured process aligns closely with how code-specialized language models are trained to operate. Motivated by this, we introduce \pyrag, a framework that reformulates multi-hop RAG as program synthesis and execution. Instead of free-form reasoning trajectories, \pyrag represents the reasoning process as an executable Python program over retrieval and QA tools, exposing intermediate states as variables, producing deterministic feedback through execution, and yielding an inspectable trace of the entire reasoning process. This formulation further enables compiler-grounded self-repair and execution-driven adaptive retrieval without any additional training. Experiments on five QA benchmarks (PopQA, HotpotQA, 2WikiMultihopQA, MuSiQue, and Bamboogle) show that \pyrag consistently outperforms strong baselines under both training-free and RL-trained settings, with especially large gains on compositional multi-hop datasets. Our code, data and models are publicly available at https://github.com/GasolSun36/PyRAG.

多跳推理代码生成RAG可解释性

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。