arXiv(opens in a new tab)cs.SESep 2026Cited by 2 papers on PaperVantage

Manuscript Offprint

arXiv:2609.09987

Beyond Repository Boundaries: Cross-Repository Graph Retrieval for Code Generation

Minh Le-Anh, Nam Le Hai, Quyen Tran, Anh Nguyen Hoang, Linh Ngo Van, Bach Le, Nghi D. Q. Bui

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

Repository-level code generation requires generated code to be compatible not only with the target repository but also with its dependency environment. Existing retrieval-based methods mainly retrieve context from the local repository, leaving external API usage dependent on the model's pretrained knowledge, which can be insufficient for unseen or version-specific APIs. Moreover, current retrieval strategies largely focus on one-hop evidence and overlook the structural relationships among code components. We propose CrossCoder, a cross-repository code generation framework that explicitly incorporates external libraries into the retrieval context through a unified knowledge graph over repository and library entities. CrossCoder identifies important nodes via planning and semantic retrieval, then selectively expands neighboring nodes to retrieve richer multi-hop contextual evidence for generation. To further evaluate dependency-version compatibility, we introduce VERSIONEXEC, an execution-based benchmark derived from BigCodeBench that evaluates generation under different dependency versions. Experimental results on RepoExec, DevEval, and VERSIONEXEC demonstrate that CrossCoder consistently improves both functional correctness (up to 6.3% on pass@1) and robustness to dependency-version changes.

1 Introduction

The rapid development of large language models for code (CodeLLMs) has expanded automatic code generation from isolated programming tasks toward implementations that must be integrated into existing projects (Nguyen et al., 2023; Wang et al., 2025b; Tao et al., 2026; Hai et al., 2025; Zhang et al., 2024; Athale and Vaddina, 2025). In repository-level code generation, the target code must satisfy the requested functionality while also

conforming to the surrounding codebase, including its internal APIs, data structures, and cross-file design constraints. To expose this scattered repository knowledge to the generator, recent methods commonly adopt retrieval-augmented generation, where relevant project context is retrieved and supplied as additional evidence during generation (Zhang et al., 2023; Liang et al., 2024; Wang et al., 2025c; Wu et al., 2024; Le-Anh et al., 2026). Despite this progress, there are several important dimensions of repository-level generation that remain underexplored by current retrieval-based methods.

First, repository-level code generation must remain compatible not only with the repository itself but also with external libraries imported by the project. Existing methods mainly retrieve context from the local repository, leaving third-party API usage dependent on the model's pretrained knowledge. This assumption breaks when projects rely on newly introduced APIs or unseen libraries, causing models to hallucinate unsupported APIs or reimplement functionality already provided by external dependencies. Second, even when the relevant library is covered during pretraining, repository-level prompts often expose only imports or package metadata, which are insufficient to determine the exact version-specific API semantics required by the project. Since API behaviors and interfaces may vary across versions, a generated function can correctly reuse local repository logic while still invoking an incompatible or outdated external API (Wang et al., 2025a). Third, current repository-level retrieval methods are typically based on similarity retrieval (Zhang et al., 2023; Wu et al., 2024) or dependency-aware retrieval (Gu et al., 2025; Wang et al., 2025c; Le-Anh et al., 2026). While effective for retrieving similar snippets or direct dependencies, these methods mainly rely on one-hop evidence and may overlook useful context in deeper dependency chains (Hai et al., 2025). In contrast, graph-based retrieval-augmented gener-

† Corresponding author: namlh@soict.hust.edu.vn ation (GRAG) has demonstrated strong potential in QA systems by modeling knowledge as entities and relations, enabling retrieval beyond isolated passages through structural connections (Gutierrez et al., 2024; Gutiérrez et al., 2025; Sarmah et al., 2024; Edge et al., 2025; Peng et al., 2025; Guo et al., 2025; Hieu et al., 2025; Van et al., 2026). However, its application to repository-level code generation remains largely unexplored.

To address these limitations, we propose CrossCoder, a novel repository-level code generation framework that enhances local context by incorporating cross-repository information from external libraries and employing a structural graph-expansion strategy. First, instead of confining context retrieval strictly to internal files, CrossCoder extends the scope from cross-file to cross-repository by actively retrieving context from external libraries within the environment. This fundamentally addresses the challenges of handling unseen APIs and version-specific semantics. Current repository-level methods and benchmarks largely overlook whether the generated code is compatible with the specific dependency versions in the execution environment. To isolate and rigorously evaluate this aspect, we conduct VersionExec, an execution-based benchmark derived from BigCodeBench (Zhuo et al., 2025), featuring 13 manually curated libraries with breaking API changes across older VERSIONEXEC (O) and newer VERSIONEXEC (N) environments. Our results show that explicitly providing cross-repo context yields superior alignment with environment dependencies without relying on external documentation, which is often unavailable or incomplete for third-party libraries. Second, to overcome the limitations of traditional similarity or one-hop dependency-aware retrieval, CrossCoder introduces a novel graph-expansion mechanism inspired by GRAG. Rather than utilizing dependency or call graphs merely as a one-time boundary to extract immediate neighbors and then discarding them, CrossCoder leverages the unified knowledge graph throughout the entire inference process. After identifying high-importance base nodes via initial planning, CrossCoder recursively expands to deeper neighbor nodes, dynamically retrieving multi-hop contextual evidence that traditional methods overlook.

In summary, this paper makes the following contributions:

  • We propose CrossCoder, an advanced repository-level code generation framework that incorporates cross-repository context by jointly indexing repository and library entities into a unified knowledge graph. It dynamically retrieves multi-hop context through a novel strategy involving planning, high-importance node selection, and recursive graph-based dependency expansion.

  • We introduce VERSIONEXEC, an execution-based benchmark specifically designed to evaluate code generation under shifting dependency versions. By isolating version-specific semantics across environments, it fills a critical gap in existing repository-level evaluation.

  • Extensive experiments on two recent repository-level benchmarks, RepoExec (Hai et al., 2025) and DevEval (Li et al., 2024), demonstrate that CrossCoder achieves new state-of-the-art performance, outperforming strong baselines. Notably, CrossCoder enables 20B models to match or surpass 120B models using conventional retrieval methods.

  • Through isolated evaluations on VERSIONEXEC, we demonstrate that CrossCoder is exceptionally robust against dependency-version changes, outperforming documentation-retrieval baselines without relying on external, potentially unavailable documentation.

References (1)

  • implement core logic