arXiv:2509.25257cs.SEcs.IR2025-09被引 7

RANGER用图增强检索,同时搞定代码找类和自然语言查代码。

RANGER -- Repository-Level Agent for Graph-Enhanced Retrieval

  • 构建仓库级代码知识图谱,细到变量层级的依赖关系
  • 实体查询用快速查找,自然语言查询用智能探索策略
  • 在多个任务中优于现有方法,尤其擅长跨文件依赖和代码补全

通用自动化软件工程涵盖代码补全、检索、修复、问答和摘要等任务。这些任务需要能处理代码实体查询(如定位特定类)和自然语言查询(如描述任务找对应代码)的检索系统。本文提出RANGER,一个面向仓库级别的代码检索代理,同时支持两类查询,弥补了近期研究多集中于代码实体查询的空白。首先构建涵盖整个仓库的完整知识图谱,捕捉层级与跨文件依赖至变量级别,并为图节点附加文本描述和嵌入表示,弥合代码与自然语言的差距。RANGER通过双阶段检索流程运行:实体查询使用快速Cypher查询,自然语言查询则由基于MCTS的图探索处理。在四个多样化的基准上评估,覆盖代码搜索、问答、跨文件依赖检索和仓库级代码补全。在CodeSearchNet和RepoQA上,优于使用Qwen3-8B等强模型嵌入的基线;在RepoBench上,跨文件依赖检索表现更优;在CrossCodeEval上,搭配BM25时代码补全精确匹配率最高,优于其他RAG方法。

原文摘要 · Abstract (English)

General-purpose automated software engineering (ASE) includes tasks such as code completion, retrieval, repair, QA, and summarization. These tasks require a code retrieval system that can handle specific queries about code entities, or code entity queries (for example, locating a specific class or retrieving the dependencies of a function), as well as general queries without explicit code entities, or natural language queries (for example, describing a task and retrieving the corresponding code). We present RANGER, a repository-level code retrieval agent designed to address both query types, filling a gap in recent works that have focused primarily on code-entity queries. We first present a tool that constructs a comprehensive knowledge graph of the entire repository, capturing hierarchical and cross-file dependencies down to the variable level, and augments graph nodes with textual descriptions and embeddings to bridge the gap between code and natural language. RANGER then operates on this graph through a dual-stage retrieval pipeline. Entity-based queries are answered through fast Cypher lookups, while natural language queries are handled by MCTS-guided graph exploration. We evaluate RANGER across four diverse benchmarks that represent core ASE tasks including code search, question answering, cross-file dependency retrieval, and repository-level code completion. On CodeSearchNet and RepoQA it outperforms retrieval baselines that use embeddings from strong models such as Qwen3-8B. On RepoBench, it achieves superior cross-file dependency retrieval over baselines, and on CrossCodeEval, pairing RANGER with BM25 delivers the highest exact match rate in code completion compared to other RAG methods.

代码检索知识图谱RAG自动编程

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