一句话:提出 DyRetriever,用 LLM 按需构建部分依赖图并多跳推理检索上下文,提升仓库级代码生成。
仓库级代码生成要求 LLM 理解复杂依赖,但上下文窗口有限,常依赖 RAG 检索相关代码。相似度检索难找到目标函数真正依赖的代码,已有图检索又依赖手工规则和静态全图,维护成本高。受人类开发者按需沿依赖图检查的启发,本文提出 DyRetriever:由 LLM 选择入口函数,沿代码依赖图多跳推理,并用语义理解验证候选函数是否有助生成,按需构建部分依赖图、用后丢弃;再与相似度检索结合为 DyCoder。在 CoderEval 与 DevEval 上,DyCoder 相比现有 RAG 方法 Pass@1 相对提升 25.63% 和 59.73%,且比静态依赖图基线快 7.4 倍。
LLM-based repository-level code generation aims to generate code according to the available context within a software repository, requiring LLMs to understand and reason over complex code dependencies. Due to limited context windows and insufficient understanding of repository-specific code, LLMs typically rely on retrieval-augmented generation (RAG) to incorporate relevant contextual code. Early RAG approaches primarily employ similarity-based retrieval, which often fails to retrieve code snippets that the target function actually depends on. Recent work introduces graph-based retrieval to model such dependencies, but typically relies on manually designed rules and static global graphs, leading to limited flexibility and high construction and maintenance costs. In contrast, human developers typically collect helpful context by implicitly constructing a partial dependency graph and iteratively inspecting along it. Inspired by human behavior, we propose DyRetriever, an effective and efficient context retrieval method via partial dependency graphs. DyRetriever leverages an LLM to simulate how human developers collect helpful context by first selecting a set of entry-point functions and then performing multi-hop reasoning along the code dependency graph. During multi-hop reasoning, DyRetriever leverages the LLM’s semantic understanding to explicitly validate whether a function can help to generate the target function, thereby eliminating reliance on manually designed rules and enabling flexibility across application scenarios. Instead of statically constructing a global dependency graph, DyRetriever builds a partial graph on demand and discards it after use, reducing construction overhead and avoiding maintenance costs. We integrate DyRetriever with a similarity-based code retriever to build a new code generation approach, DyCoder, and evaluate it on two widely used repository-level code generation benchmarks, CoderEval and DevEval. Experimental results show that DyCoder achieves relative Pass@1 improvements of 25.63% and 59.73% on CoderEval and DevEval, respectively, compared with existing RAG-based methods, while being 7.4× faster than baselines based on static dependency graph construction.
@inproceedings{paperbot12352,
title = {Effective and Efficient Context Retrieval via Partial Dependency Graph for Repository-Level Code Generation},
author = {Zhongxin Liu and Zhonghao Jiang and Zhifan Ye and Haoye Wang and Jiakun Liu and Xiaoxue Ren},
booktitle = {ASE},
year = {2026},
doi = {10.1145/3832783.3834350}
}