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)相对提升。