ReCode: Improving LLM-based Code Repair with Fine-Grained Retrieval-Augmented Generation

📅 2025-09-02
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Existing LLM-based code repair methods suffer from high training/inference overhead and low retrieval accuracy in RAG due to coarse-grained code embeddings. This paper proposes ReCode, a fine-grained retrieval-augmented in-context learning framework for efficient and accurate code repair. Its core contributions are: (1) algorithm-aware retrieval—leveraging a lightweight algorithm classifier to predict defect types and dynamically prune the retrieval space; and (2) a modular dual-encoder architecture that separately models code structure and natural language semantics to enable fine-grained cross-modal matching. We evaluate ReCode on the real-world user-defect dataset RACodeBench and competitive programming benchmarks. Results show that ReCode significantly reduces inference cost while outperforming state-of-the-art methods in repair accuracy.

Technology Category

Application Category

📝 Abstract
Recent advances in large language models (LLMs) have demonstrated impressive capabilities in code-related tasks, such as code generation and automated program repair. Despite their promising performance, most existing approaches for code repair suffer from high training costs or computationally expensive inference. Retrieval-augmented generation (RAG), with its efficient in-context learning paradigm, offers a more scalable alternative. However, conventional retrieval strategies, which are often based on holistic code-text embeddings, fail to capture the structural intricacies of code, resulting in suboptimal retrieval quality. To address the above limitations, we propose ReCode, a fine-grained retrieval-augmented in-context learning framework designed for accurate and efficient code repair. Specifically, ReCode introduces two key innovations: (1) an algorithm-aware retrieval strategy that narrows the search space using preliminary algorithm type predictions; and (2) a modular dual-encoder architecture that separately processes code and textual inputs, enabling fine-grained semantic matching between input and retrieved contexts. Furthermore, we propose RACodeBench, a new benchmark constructed from real-world user-submitted buggy code, which addresses the limitations of synthetic benchmarks and supports realistic evaluation. Experimental results on RACodeBench and competitive programming datasets demonstrate that ReCode achieves higher repair accuracy with significantly reduced inference cost, highlighting its practical value for real-world code repair scenarios.
Problem

Research questions and friction points this paper is trying to address.

Improving code repair accuracy with fine-grained retrieval
Reducing high inference costs in LLM-based code repair
Addressing structural code intricacies in retrieval strategies
Innovation

Methods, ideas, or system contributions that make the work stand out.

Fine-grained retrieval-augmented generation framework
Algorithm-aware retrieval strategy with type predictions
Modular dual-encoder architecture for semantic matching
🔎 Similar Papers
No similar papers found.
Y
Yicong Zhao
College of Computer Science and Artificial Intelligence, Fudan University
Shisong Chen
Shisong Chen
Ph.D. of Computer Science and Technology, East China Normal University
Natural Language ProcessingKnowledge Graph
J
Jiacheng Zhang
College of Computer Science and Artificial Intelligence, Fudan University
Z
Zhixu Li
School of Information, Renmin University of China; School of Smart Governance, Renmin University of China