让AI理解整个代码库,生成可运行的代码变更。
Retrieval-Augmented Code Generation: A Survey with Focus on Repository-Level Approaches
- 用检索增强生成框架整合代码库上下文。
- 支持跨文件依赖与全局语义一致性的代码生成。
- 适合研究AI辅助软件工程的开发者和研究人员。
大型语言模型(LLMs)的进步显著提升了自动化代码生成能力。尽管现有方法在函数和文件级别表现优异,但真实软件工程需对整个代码库进行推理,包括跨文件依赖、动态执行环境和全局语义一致性。这一挑战催生了代码库级代码生成(RLCG),要求模型在检索、组织和利用代码库级上下文的基础上生成连贯且可执行的代码变更。为此,检索增强生成(RAG)已成为代码库级智能的重要范式。本文综述了检索增强代码生成(RACG),重点关注代码库级方法。我们不将RACG视为静态的‘检索-生成’流程,而是将其视为涉及上下文构建、检索优化、生成与环境交互的耦合演化过程。通过统一分析框架,涵盖检索基础、控制机制与评估设置,系统考察检索策略、基于图与非图的检索范式、训练驱动优化及自主代理架构。我们总结常用数据集、基准测试与系统配置,并讨论可扩展性、可靠性、效率及RACG与长上下文LLMs之间的必要边界等关键挑战。本综述旨在为快速演进的RACG领域提供结构化理解,并指明未来人工智能驱动软件工程的研究方向。
原文摘要 · Abstract (English)
Recent advances in large language models (LLMs) have significantly improved automated code generation. While existing approaches have achieved strong performance at the function and file levels, real-world software engineering requires reasoning over entire repositories, including cross-file dependencies, evolving execution environments, and global semantic consistency. This challenge has led to the emergence of Repository-Level Code Generation (RLCG), where models must retrieve, organize, and utilize repository-scale context to generate coherent and executable code changes. To address these challenges, Retrieval-Augmented Generation (RAG) has become an increasingly important paradigm for repository-level code intelligence. In this survey, we present a comprehensive review of Retrieval-Augmented Code Generation (RACG), with a particular focus on repository-level approaches. Rather than viewing RACG as a static ``retrieve-then-generate'' pipeline, we characterize it as a coupled and evolving process involving context construction, retrieval optimization, generation, and environment interaction. We organize existing methods through a unified analytical framework spanning retrieval substrate, control regime, and evaluation setting. Based on this framework, we systematically examine retrieval strategies, graph-based and non-graph-based retrieval paradigms, training-driven optimizations, and autonomous agent architectures. We further summarize widely used datasets, benchmarks, and system configurations, and discuss key challenges including scalability, reliability, efficiency, and the necessity boundary between RACG and long-context LLMs. Through this survey, we aim to provide a structured understanding of the rapidly evolving RACG landscape and highlight promising directions for future AI-powered software engineering research.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。