Effective and Efficient Context Retrieval via Partial Dependency Graph for Repository-Level Code Generation

๐Ÿ“… 2026-08-03
๐Ÿ“ˆ Citations: 0
โœจ Influential: 0
๐Ÿ“„ PDF
๐Ÿค– AI Summary
Existing retrieval-augmented generation approaches struggle to effectively capture the dependency context of target functions in repository-scale code generation: similarity-based retrieval ignores dependencies, while static dependency graphs are costly to construct and lack flexibility. Inspired by human developer behavior, this work proposes DyRetrieverโ€”a dynamic retrieval mechanism that leverages the semantic reasoning capabilities of large language models to perform multi-hop traversal along dependency paths starting from entry functions, constructing and discarding local dependency graphs on demand without relying on handcrafted rules or global static graphs. By integrating similarity-based retrieval with dynamic dependency validation, DyRetriever enables efficient and adaptive context acquisition. The resulting system, DyCoder, achieves relative Pass@1 improvements of 25.63% and 59.73% on CoderEval and DevEval, respectively, and operates 7.4ร— faster than static graph baselines.
๐Ÿ“ Abstract
LLM-based repository-level code generation aims to generate code using the context available in a software repository, requiring LLMs to reason over complex code dependencies. Due to limited context windows and insufficient repository-specific understanding, LLMs typically rely on retrieval-augmented generation (RAG) to incorporate relevant code. Early RAG approaches primarily employ similarity-based retrieval, which often fails to retrieve code snippets that the target function 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 collect helpful context by implicitly constructing a partial dependency graph and iteratively inspecting along it. Inspired by this behavior, we propose DyRetriever, an efficient context retrieval method via partial dependency graphs. DyRetriever uses an LLM to first select a set of entry-point functions and then perform multi-hop reasoning along the code dependency graph. During multi-hop reasoning, it uses the LLM's semantic understanding to validate whether a function can help generate the target function, eliminating manually designed rules and enabling flexibility across scenarios. Instead of statically constructing a global dependency graph, DyRetriever builds a partial graph on demand and discards it after use, reducing construction and maintenance costs. We integrate DyRetriever with a similarity-based code retriever to build DyCoder and evaluate it on 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.4x faster than baselines based on static dependency graph construction.
Problem

Research questions and friction points this paper is trying to address.

repository-level code generation
context retrieval
dependency graph
retrieval-augmented generation
code generation
Innovation

Methods, ideas, or system contributions that make the work stand out.

partial dependency graph
retrieval-augmented generation
multi-hop reasoning
repository-level code generation
dynamic context retrieval