RAMBO通过挖掘代码库特有元素提升方法体补全准确率
RAMBO: Enhancing RAG-based Repository-Level Method Body Completion
- 不检索相似代码,而是识别代码库特有的类、方法和变量及其用法
- 在40个Java项目上使精确匹配率提升3倍,最高达57%的CodeBLEU提升
- 适合需要高精度代码补全的大型项目开发者或工具研发者
代码补全对软件开发至关重要,能基于上下文预测代码片段。其中方法体补全(MBC)尤为困难,需根据方法签名和上下文生成完整方法体。在大型代码库中,方法体必须整合自定义API、模块间依赖和项目特定规范等要素。本文提出RAMBO,一种基于检索增强生成(RAG)的仓库级方法体补全新方法。不同于检索相似方法体,RAMBO识别关键仓库特有元素(如类、方法、变量/字段)及其相关使用场景,并将其融入生成过程,以提升生成结果的准确性与上下文相关性。在40个Java项目上,使用主流代码大模型测试显示,RAMBO显著优于当前最优方案:BLEU提升最高达46%,CodeBLEU提升57%,编译成功率提高36%,精确匹配率最高提升3倍。尤为突出的是,其精确匹配率超越RepoCoder Oracle方法最高12%,树立了仓库级方法体补全的新基准。
原文摘要 · Abstract (English)
Code completion is essential in software development, helping developers by predicting code snippets based on context. Among completion tasks, Method Body Completion (MBC) is particularly challenging as it involves generating complete method bodies based on their signatures and context. This task becomes significantly harder in large repositories, where method bodies must integrate repositoryspecific elements such as custom APIs, inter-module dependencies, and project-specific conventions. In this paper, we introduce RAMBO, a novel RAG-based approach for repository-level MBC. Instead of retrieving similar method bodies, RAMBO identifies essential repository-specific elements, such as classes, methods, and variables/fields, and their relevant usages. By incorporating these elements and their relevant usages into the code generation process, RAMBO ensures more accurate and contextually relevant method bodies. Our experimental results with leading code LLMs across 40 Java projects show that RAMBO significantly outperformed the state-of-the-art repository-level MBC approaches, with the improvements of up to 46% in BLEU, 57% in CodeBLEU, 36% in Compilation Rate, and up to 3X in Exact Match. Notably, RAMBO surpassed RepoCoder Oracle method by up to 12% in Exact Match, setting a new benchmark for repository-level MBC.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。