Repository-level code completion remains challenging for large language models (LLMs) due to cross-file dependencies and limited context windows. Prior work addresses this challenge using Retrieval-Augmented Generation (RAG) frameworks based on semantic indexing or structure-aware graph analysis, but these approaches incur substantial computational overhead for index construction and maintenance. Motivated by common developer workflows that rely on lightweight search utilities (e.g., ripgrep), we revisit a fundamental yet underexplored question: how far can simple, index-free lexical retrieval support repository-level code completion before more complex retrieval mechanisms become necessary? To answer this question, we systematically investigate lightweight, index-free, intent-aware lexical retrieval through extensive empirical analysis. We first introduce Naive GrepRAG, a baseline framework in which LLMs autonomously generate ripgrep commands to retrieve relevant context. Despite its simplicity, Naive GrepRAG achieves performance comparable to sophisticated graph-based baselines. Further analysis shows that its effectiveness stems from retrieving lexically precise code fragments that are spatially closer to the completion site. We also identify key limitations of lexical retrieval, including sensitivity to noisy matches from high-frequency ambiguous keywords and context fragmentation caused by rigid truncation boundaries. To address these issues, we propose GrepRAG, which augments lexical retrieval with a lightweight post-processing pipeline featuring identifier-weighted re-ranking and structure-aware deduplication. Extensive evaluation on CrossCodeEval and RepoEval-Updated demonstrates that GrepRAG consistently outperforms state-of-the-art (SOTA) methods, achieving 7.04-15.58 percent relative improvement in code exact match (EM) over the best baseline on CrossCodeEval.


翻译:仓库级代码补全对于大语言模型(LLMs)而言仍具挑战性,主要源于跨文件依赖关系和有限的上下文窗口。先前研究通过基于语义索引或结构感知图分析的检索增强生成(RAG)框架应对这一挑战,但这些方法在索引构建和维护方面产生了显著的计算开销。受开发者通常依赖轻量级搜索工具(如ripgrep)的工作流程启发,我们重新审视一个基础但尚未被充分探索的问题:在需要更复杂检索机制之前,简单、无需索引的词法检索能在多大程度上支持仓库级代码补全?为回答此问题,我们通过广泛的实证分析,系统研究了轻量级、无需索引、意图感知的词法检索。我们首先提出Naive GrepRAG,这是一个基线框架,其中LLMs自主生成ripgrep命令以检索相关上下文。尽管其设计简单,Naive GrepRAG实现了与复杂图基线方法相当的性能。进一步分析表明,其有效性源于检索到词法精确且空间上更接近补全位置的代码片段。同时,我们识别出词法检索的关键局限性,包括对高频模糊关键词产生的噪声匹配敏感,以及因截断边界僵化导致的上下文碎片化。为解决这些问题,我们提出GrepRAG,该框架通过轻量级后处理流程增强词法检索,该流程包含标识符加权重排序和结构感知去重。在CrossCodeEval和RepoEval-Updated数据集上的广泛评估表明,GrepRAG持续优于现有最佳(SOTA)方法,在CrossCodeEval上相较于最佳基线实现了7.04-15.58%的代码精确匹配(EM)相对提升。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
定制化大型语言模型的图检索增强生成综述
专知会员服务
37+阅读 · 2025年1月28日
微软最新《检索增强生成(RAG)》综述
专知会员服务
56+阅读 · 2024年9月24日
大型语言模型对齐技术综述:RLHF、RLAIF、PPO、DPO 等
专知会员服务
55+阅读 · 2024年7月24日
NLG ≠ 机器写作 | 专家专栏
量子位
13+阅读 · 2018年9月10日
深度学习文本分类方法综述(代码)
中国人工智能学会
28+阅读 · 2018年6月16日
TextInfoExp:自然语言处理相关实验(基于sougou数据集)
全球人工智能
12+阅读 · 2017年11月12日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员