更好地调用Grep:评估和改进用于仓库级代码补全的类Grep词汇检索方法
Better Call Grep: Evaluating and Improving Grep-Like Lexical Retrieval for Repository-Level Code Completion
AI总结:
本文评估改进类Grep词汇检索,提出Naive GrepRAG基线,又结合后处理流水线的GrepRAG在代码补全任务上优于SOTA,为轻量检索支撑仓库级代码补全提供方案。
摘要:
仓库级代码补全对大型语言模型(LLMs)而言仍具挑战性,原因在于跨文件依赖和有限的上下文窗口。现有研究采用基于语义索引或结构感知图分析的检索增强生成(RAG)框架来应对这一挑战,但这些方法在索引构建与维护时会产生大量计算开销。受开发者依赖轻量搜索工具(如ripgrep)的常见工作流启发,本文重新探讨一个基础却被忽视的问题:在需要更复杂检索机制前,简单的无索引词汇检索能在多大程度上支撑仓库级代码补全?为解答该问题,本文通过大量实证分析系统研究了轻量、无索引、感知意图的词汇检索。首先,本文提出基线框架Naive GrepRAG,其中LLMs自主生成ripgrep命令以检索相关上下文。尽管该框架简单,其性能却可与复杂的基于图的基线相媲美。进一步分析显示,其有效性源于检索到与补全位置空间更近、词汇更精确的代码片段。本文还识别出词汇检索的关键局限,包括对高频模糊关键词的噪声匹配敏感,以及由严格截断边界导致的上下文碎片化。为解决这些问题,本文提出GrepRAG,它通过包含标识符加权重排序和结构感知去重的轻量后处理流水线增强词汇检索。在CrossCodeEval和RepoEval-Updated上的大量评估表明,GrepRAG始终优于最先进(SOTA)方法,在CrossCodeEval上较最佳基线实现了7.04%-15.58%的代码精确匹配(EM)相对提升。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。