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.
翻译:通用自动化软件工程(ASE)涵盖代码补全、检索、修复、问答及摘要等任务。这些任务需要一个能够处理两类查询的代码检索系统:一类是针对代码实体的特定查询(例如定位特定类或检索函数依赖关系),另一类是不含显式代码实体的通用自然语言查询(例如描述任务并检索对应代码)。本文提出RANGER,一种仓库级代码检索智能体,旨在同时处理这两类查询,弥补了近期研究主要聚焦于代码实体查询的不足。我们首先提出一种工具,能够构建覆盖整个仓库的综合性知识图谱,捕获从文件层级到变量层级的跨文件依赖关系,并通过为图谱节点添加文本描述与嵌入表示来弥合代码与自然语言之间的语义鸿沟。RANGER随后通过双阶段检索流程在此图谱上运行:基于实体的查询通过高效的Cypher查询直接响应,自然语言查询则通过蒙特卡洛树搜索引导的图谱探索进行处理。我们在四个涵盖核心ASE任务的多样化基准上评估RANGER,包括代码搜索、问答、跨文件依赖检索及仓库级代码补全。在CodeSearchNet与RepoQA基准上,其性能超越使用Qwen3-8B等强模型嵌入的检索基线;在RepoBench上实现了优于基线的跨文件依赖检索效果;在CrossCodeEval基准中,RANGER与BM25结合相比其他检索增强生成方法取得了最高的代码补全精确匹配率。