Skip to main content
QUICK REVIEW

[论文解读] RAMBO: Enhancing RAG-based Repository-Level Method Body Completion

Tuan-Dung Bui, Duc-Thieu Luu-Van|arXiv (Cornell University)|Sep 23, 2024
Parallel Computing and Optimization TechniquesComputer Science被引用 3
一句话总结

Rambo 是一种基于 RAG 的仓库级方法体补全方法,通过检索关键的仓库特定代码元素(如类、方法、字段)及其相关用法,而非依赖于整个方法体的相似性检索,从而增强代码大模型。它实现了最先进性能,相较于 RepoCoder Oracle,Exact Match 提升最高达 12%,CodeBLEU 提升 57%,Compilation Rate 提升 36%。

ABSTRACT

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.

研究动机与目标

  • 为解决在仓库级方法体补全中基于相似性的检索所存在的局限性,即检索到的代码片段往往无关或不存在。
  • 通过聚焦于关键的仓库特定代码元素及其用法,提升代码大模型生成准确、上下文相关方法体的性能。
  • 在不依赖微调或重新训练代码大模型的前提下,实现超越现有基于 RAG 和基于 Oracle 的方法的优越性能。
  • 开发一种基于目标方法结构草图的功能相关代码元素检索策略,减少噪声并提升精度。

提出的方法

  • Rambo 为目标方法生成草图体以推断其功能结构,并识别潜在的关键代码元素。
  • 它从草图中提取候选代码元素(类、方法、字段和变量),并利用这些元素在仓库中查询相关的声明和用法。
  • 检索过程聚焦于查找这些元素在语法和语义上相关的用法,将其视为构建方法体的“配方”。
  • 将检索到的元素及其用法作为上下文注入代码大模型,以指导生成准确且符合仓库一致性的代码。
  • 该方法避免使用基于学习的检索或模型微调,而是依赖于草图和代码库的结构与语义分析。
  • 使用标准指标(包括 BLEU、CodeBLEU、Compilation Rate、Exact Match 和 pass@k)在 40 个 Java 仓库上对方法进行了评估。
Figure 1 : Rambo : A Repository-Level Method Body Completion Approach
Figure 1 : Rambo : A Repository-Level Method Body Completion Approach

实验结果

研究问题

  • RQ1基于关键代码元素及其用法的检索策略,是否能在仓库级方法体补全中超越基于相似性的检索?
  • RQ2Rambo 在多种评估指标下与最先进方法(如 RepoCoder 和 RepoCoder Oracle)相比表现如何?
  • RQ3基于草图的元素提取在多大程度上提升了检索精度并减少了代码生成中的噪声?
  • RQ4无需微调或修改底层代码大模型,检索增强生成方法是否能实现最先进性能?

主要发现

  • 与基线相比,Rambo 在 CodeBLEU 上最高提升 57%,表明生成代码在结构和语义对齐方面有显著提升。
  • Compilation Rate 提升 36%,表明生成的方法体在语法上更正确,更接近生产就绪状态。
  • 在 Exact Match 上,Rambo 相较于 RepoCoder Oracle 最高提升 12%,为仓库级 MBC 设定了新的最先进基准。
  • 该方法在 BLEU 上最高提升 46%,在 Exact Match 上最高提升 3 倍,凸显其在生成准确且完整方法体方面的有效性。
  • 基于草图的检索机制减少了噪声和无关上下文,从而实现了更可靠且功能准确的代码生成。
Figure 3 : Rambo ’s performance by references’ size (LOC), left axis: CodeBLEU and CR ; right axis: Distribution
Figure 3 : Rambo ’s performance by references’ size (LOC), left axis: CodeBLEU and CR ; right axis: Distribution

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。