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는 본질적으로 단계적 계산이며, 코드 특화 LLM의 학습 분포와 정확히 일치한다. 따라서 reasoning을 code synthesis & execution으로 다루면 중간 상태가 명시적이고, 오류는 실행으로 결정론적으로 검출되며, 자기 검증의 신뢰성 문제가 컴파일러·실행기로 외주된다.

🔬 기술적 접근법

📊 주요 결과

💭 의의 및 한계

**의의**: 자유 텍스트 reasoning의 구조적 한계를 우회하는 일반적 program-grounded RAG 패러다임 제시. **한계**: 도구·API 인터페이스 정의가 필요하고, 매우 비형식적·창의적 추론 태스크에는 적합도가 떨어질 수 있음.

🚀 실용적 활용