# 检索廉价，代码为王：基于可执行程序的多跳推理检索增强生成

- 来源：HuggingFace Daily Papers（社区热门论文）
- 发布时间：2026-05-13 08:00
- AIHOT 分数：72
- AIHOT 标记：精选
- AIHOT 链接：https://aihot.news/items/cmp509d4w0a9tsljx6hcg0fl1
- 原文链接：https://arxiv.org/abs/2605.12975

## 精选理由

把多跳RAG变成可执行的Python程序，中间状态全透明，实验在五个数据集上都压住了基线，做检索增强的值得看一眼。

## AI 摘要

针对多跳检索增强生成（RAG）中推理过程隐式、检索漂移及错误难以自查的问题，研究团队提出PyRAG框架，将多跳推理任务重构为程序合成与执行过程。该框架将推理步骤编写为可执行的Python程序，通过显式调用检索与问答工具实现多步计算，使中间状态变量化、反馈确定化，并生成完整可检查的推理轨迹。该方法无需额外训练即可支持基于编译器的自我修复与执行驱动的自适应检索。在PopQA、HotpotQA等五个问答基准测试中，PyRAG在无需训练和强化学习训练两种设定下均显著优于基线模型，尤其在组合式多跳数据集上提升显著。相关资源已开源。

## 正文

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.
