arXiv:2508.05970cs.SEcs.AI2025-08被引 7

通过评估代码片段影响,筛选出有用上下文提升代码补全效果

Impact-driven Context Filtering For Cross-file Code Completion

  • 用概率指标衡量每个检索代码块对补全的贡献
  • 仅少量片段真正有益,部分反而降低准确率
  • 适合需要高效精准补全的开发者和大模型研究者

检索增强生成(RAG)在仓库级代码补全中展现巨大潜力,通过融合跨文件知识与文件内前序代码,提供完整上下文。为理解检索到的跨文件上下文的贡献,我们引入基于似然的度量来评估每个代码块对补全的影响。分析显示,尽管检索大量代码块,仅有少数正向贡献,部分甚至损害性能。基于此,我们构建了一个仓库级数据集,将每个检索块标记为正、中性或负。随后提出自适应检索上下文过滤框架CODEFILTER,利用该数据集训练以减轻负面上下文的有害影响。在RepoEval和CrossCodeLongEval上的广泛评估表明,相比无过滤方法,CODEFILTER在各类任务中均持续提升补全准确率。此外,它显著缩短输入提示长度,提高计算效率,并在不同模型间表现出强泛化能力。结果凸显了CODEFILTER在提升仓库级代码补全准确性、效率和可解释性方面的潜力。

原文摘要 · Abstract (English)

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.

代码补全上下文过滤RAG效率优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。