arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.14497cs.SEcs.CL
收藏

CodeRAG-Bench:检索能否增强代码生成?

CodeRAG-Bench: Can Retrieval Augment Code Generation?

Carnegie Mellon University(卡内基梅隆大学);University of Washington(华盛顿大学);University of Southern California(南加州大学)

Zora Zhiruo Wang, Akari Asai, Xinyan Velocity Yu, Frank F. Xu, Yiqing Xie, Graham Neubig, Daniel Fried

AI总结:

本研究构建基准CodeRAG-Bench,系统分析检索增强生成在代码生成中的适用场景与挑战,发现高质量上下文可提升性能,但检索器与生成器仍存在局限。

摘要:

尽管语言模型(LMs)已被证明在生成代码方面非常熟练,但许多程序对于仅依赖其参数化知识来生成的语言模型来说仍具有挑战性。提供外部上下文(如库文档)可以促进生成准确且功能性的代码。尽管检索增强生成(RAG)在各种面向文本的任务中取得了成功,但其在改进代码生成方面的潜力仍未得到充分探索。在这项工作中,我们通过提出以下问题进行了系统性的大规模分析:在哪些场景下检索可以惠及代码生成模型?以及仍存在哪些挑战?我们首先策划了一个全面的评估基准CodeRAG-Bench,涵盖三类代码生成任务,包括基础编程、开放领域和仓库级问题。我们从五个来源聚合文档供模型检索上下文:竞赛解决方案、在线教程、库文档、StackOverflow帖子以及GitHub仓库。我们通过提供从一个或多个来源检索的上下文来检验CodeRAG-Bench上表现最佳的模型。尽管在各种设置下通过检索高质量上下文在最终代码生成方面取得了显著进展,但我们的分析揭示了改进空间——当前的检索器在获取有用上下文方面仍存在困难,尤其是在词汇重叠有限的情况下,而生成器在有限的上下文长度或整合额外上下文的能力方面未能改进。我们希望CodeRAG-Bench能作为一个有效的测试平台,鼓励进一步开发先进的面向代码的RAG方法。

英文摘要:

While language models (LMs) have proven remarkably adept at generating code, many programs are challenging for LMs to generate using their parametric knowledge alone. Providing external contexts such as library documentation can facilitate generating accurate and functional code. Despite the success of retrieval-augmented generation (RAG) in various text-oriented tasks, its potential for improving code generation remains under-explored. In this work, we conduct a systematic, large-scale analysis by asking: in what scenarios can retrieval benefit code generation models? and what challenges remain? We first curate a comprehensive evaluation benchmark, CodeRAG-Bench, encompassing three categories of code generation tasks, including basic programming, open-domain, and repository-level problems. We aggregate documents from five sources for models to retrieve contexts: competition solutions, online tutorials, library documentation, StackOverflow posts, and GitHub repositories. We examine top-performing models on CodeRAG-Bench by providing contexts retrieved from one or multiple sources. While notable gains are made in final code generation by retrieving high-quality contexts across various settings, our analysis reveals room for improvement -- current retrievers still struggle to fetch useful contexts especially with limited lexical overlap, and generators fail to improve with limited context lengths or abilities to integrate additional contexts. We hope CodeRAG-Bench serves as an effective testbed to encourage further development of advanced code-oriented RAG methods.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑