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

面向跨文件代码补全的基于影响的上下文过滤

Impact-driven Context Filtering For Cross-file Code Completion

Nanyang Technological University(南洋理工大学);Nanjing University(南京大学)

Yanzhou Li, Shangqing Liu, Kangjie Chen, Tianwei Zhang, Yang Liu

AI总结:

本文提出基于似然指标的上下文过滤框架CODEFILTER,通过构建仓库级数据集过滤负面检索上下文,显著提升了跨文件代码补全的准确率和计算效率。

摘要:

检索增强生成(RAG)近期在仓库级代码补全中展现出巨大潜力,它将跨文件知识与文件内前置代码相结合,为生成提供全面的上下文。为了更好地理解检索到的跨文件上下文的贡献,我们引入了一种基于似然的指标来评估每个检索到的代码块对补全的影响。我们的分析表明,尽管检索到了大量代码块,但只有一小部分对补全有积极贡献,而有些代码块甚至会降低性能。为了解决这个问题,我们利用该指标构建了一个仓库级数据集,其中每个检索到的代码块根据其与目标补全的相关性被标记为正面、中性或负面。然后,我们提出了一个自适应检索上下文过滤框架CODEFILTER,该框架在此数据集上训练,以减轻负面检索上下文在代码补全中的有害影响。在RepoEval和CrossCodeLongEval基准上的广泛评估表明,与没有过滤操作的方法相比,CODEFILTER在各种任务中始终如一地提高了补全准确率。此外,CODEFILTER显著减少了输入提示的长度,提高了计算效率,同时在不同模型之间展现出强大的泛化能力。这些结果强调了CODEFILTER在提升仓库级代码补全的准确性、效率和可归因性方面的潜力。

英文摘要:

Retrieval-augmented generation (RAG) has recently demonstrated considerable potential for repository-level code completion, as it integrates cross-file knowledge with in-file preceding code to provide comprehensive contexts for generation. To better understand the contribution of the retrieved cross-file contexts, we introduce a likelihood-based metric to evaluate the impact of each retrieved code chunk on the completion. Our analysis reveals that, despite retrieving numerous chunks, only a small subset positively contributes to the completion, while some chunks even degrade performance. To address this issue, we leverage this metric to construct a repository-level dataset where each retrieved chunk is labeled as positive, neutral, or negative based on its relevance to the target completion. We then propose an adaptive retrieval context filtering framework, CODEFILTER, trained on this dataset to mitigate the harmful effects of negative retrieved contexts in code completion. Extensive evaluation on the RepoEval and CrossCodeLongEval benchmarks demonstrates that CODEFILTER consistently improves completion accuracy compared to approaches without filtering operations across various tasks. Additionally, CODEFILTER significantly reduces the length of the input prompt, enhancing computational efficiency while exhibiting strong generalizability across different models. These results underscore the potential of CODEFILTER to enhance the accuracy, efficiency, and attributability of repository-level code completion.

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

↑