Retrieval is Cheap, Show Me the Code: Executable Multi-Hop Reasoning for Retrieval-Augmented Generation
Jiashuo Sun, Jimeng Shi, Yixuan Xie, Saizhuo Wang, Jash Rajesh Parekh, Pengcheng Jiang, Zhiyi Shi, Jiajun Fan, Qinglong Zheng, Peiran Li, Shaowen Wang, Ge Liu, Jiawei Han
arXiv:2605.12975 · 2026-05-14 공개 · arXiv · PDF
retrieval-augmented language-models multi-hop-reasoning program-synthesis executable-code qa-benchmarks compiler-grounded self-repair
Abstract
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 / 멀티홉 추론]** 멀티홉 RAG를 자유 자연어 추론 대신 실행 가능한 Python 프로그램 합성·실행으로 재정식화한 PyRAG 프레임워크 제안.
🎯 핵심 기여도
- 멀티홉 QA에서 자유 자연어 추론의 구조적 취약성(암묵적 중간 상태, 의도와 다른 검색, 자기 자신을 검증하는 unreliable self-reflection)을 진단.
- retrieval·QA 도구 위에서 동작하는 실행 가능한 Python 프로그램으로 추론 과정을 표현하는 PyRAG 설계.
- 변수로 노출되는 중간 상태, 실행 기반 결정론적 피드백, 검사 가능한 trace로 reasoning을 투명·재현 가능하게 변환.
- compiler-grounded self-repair와 execution-driven adaptive retrieval을 추가 학습 없이 가능케 함.
💡 핵심 아이디어
멀티홉 QA는 본질적으로 단계적 계산이며, 코드 특화 LLM의 학습 분포와 정확히 일치한다. 따라서 reasoning을 code synthesis & execution으로 다루면 중간 상태가 명시적이고, 오류는 실행으로 결정론적으로 검출되며, 자기 검증의 신뢰성 문제가 컴파일러·실행기로 외주된다.
🔬 기술적 접근법
- **모델/방법론**: 코드 특화 LLM이 retrieval·QA 도구를 호출하는 Python 프로그램을 생성, 실행기에서 단계별로 수행.
- **핵심 기법**: 중간 상태를 변수로 노출하는 program-as-reasoning, 실행 피드백 기반 compiler-grounded self-repair, 실행 흐름에 따라 retrieval을 조정하는 execution-driven adaptive retrieval, training-free와 RL-trained 두 설정 모두 지원.
📊 주요 결과
- PopQA, HotpotQA, 2WikiMultihopQA, MuSiQue, Bamboogle 다섯 벤치마크에서 강력한 베이스라인 일관 능가.
- compositional 멀티홉 데이터셋(MuSiQue, 2Wiki)에서 특히 큰 격차.
- training-free 설정에서도 RL-trained 베이스라인과 경쟁력 있는 성능.
💭 의의 및 한계
**의의**: 자유 텍스트 reasoning의 구조적 한계를 우회하는 일반적 program-grounded RAG 패러다임 제시. **한계**: 도구·API 인터페이스 정의가 필요하고, 매우 비형식적·창의적 추론 태스크에는 적합도가 떨어질 수 있음.
🚀 실용적 활용
- 사실 검증·연구 자동화·법률·금융 QA 등 검사 가능한 추론이 중요한 도메인의 RAG 백엔드.
- 멀티홉 검색·QA 도구를 결합하는 에이전트 프레임워크의 reasoning layer.
- 디버깅·감사 가능한 RAG 시스템을 요구하는 규제·기업 환경.