Unseen-Codebases-Domain Data Synthesis and Training Based on Code Graphs

Guangsheng Ou, Qiming Zhang, Sirong Chen, Anji Li, Dong Xu, Tiancheng Luo, Dekun Dai, Cuiyun Gao, Long Wang, Jun Zhou, Mingwei Liu, Zibin ZhengarXiv 2026

TL;DR

UCD-Training is a novel two-stage post-training framework that adapts Large Language Models (LLMs) to entirely new, unseen codebases using only their raw source code. By constructing a structured code graph, it synthesizes dependency-preserving pretraining data and reasoning-enriched fine-tuning data, boosting code generation performance by up to 26.1% over standard baselines and significantly outperforming Retrieval-Augmented Generation (RAG).

What Problem Does This Paper Address?

When developers work with newly released software frameworks, proprietary enterprise systems, or private repositories, LLMs frequently fail. Because these "unseen codebases" were absent from the models' pretraining corpora, the models suffer from high hallucination rates and generate invalid API compositions.

While inference-time techniques like Retrieval-Augmented Generation (RAG) can pull relevant code snippets into the prompt, they don't help the model fundamentally understand the underlying architecture or latent usage conventions of a complex codebase. On the other hand, traditional post-training data synthesis methods (like OSS-Instruct) rely on existing real-world usage examples from public repositories—a luxury that brand-new or private codebases simply do not have.

To bridge this gap, the authors tackle a tough question: How can we effectively teach an LLM to understand and utilize a completely unseen codebase when only its raw source code implementation is available?

Methods

The authors introduce UCD-Training (Unseen-Codebase-Domain Training), a framework that extracts structural knowledge directly from source code and injects it into LLMs via a two-stage training pipeline.

Fig. 1. Overview of UCD-Training
  1. Code Graph Construction: The framework first performs program analysis on the codebase to build a structured code graph. Code entities (files, classes, functions) become nodes, while their relationships (dependencies, calls, includes) become edges.
  2. Dependency-Preserving Continued Pretraining (CPT): To help the model memorize the codebase structure, the authors extract a file-level dependency graph. They use a Depth-First Search (DFS) traversal to concatenate file contents. This ensures that files with direct dependencies are placed adjacently within the training context window, preventing structural knowledge from being fragmented during truncation.
  3. Graph-Grounded Supervised Fine-Tuning (SFT): The framework synthesizes three complementary types of training data, all augmented with natural language reasoning traces:
  4. Single-hop relation data: Teaches basic structural connections (e.g., which class contains which method).
  5. Compositional API data: Generates multi-API exam-style questions (Q&A, fill-in-the-blank, and coding tasks) to teach how different APIs interact.
  6. Codebase utilization data: Converts internal test cases into functional code generation tasks by separating the implementation from the assertions.

To ensure data quality, a strict two-stage filtering pipeline uses rule-based syntactic checks and LLM-based semantic consistency checks to eliminate synthetic errors and hallucinations before training.

Datasets

Because existing code generation benchmarks focus almost entirely on public code, the authors introduced a new benchmark: UnseenCodeBench.

To guarantee the codebases were truly "unseen" by modern LLMs, they selected four real-world repositories created after March 2025 (past the knowledge cutoff of the evaluated models):

  • C++: sqlgen (database system), reaction (programming framework), and Hexi (binary data stream processing).
  • Python: LEANN (high-performance retrieval engine).

The evaluation tasks were generated with LLM assistance and rigorously double-checked by human engineers, consuming over 100 person-hours to ensure high quality.

Fig. 2. Example for Generating Codebase Utilization Data

Key Insights and Ideas

  • DFS Beats Topological Sorting for CPT: Standard topological sorting can inadvertently separate closely dependent files when text is split into context windows. DFS traversal guarantees that directly related files stay close together, allowing the model to better capture cross-file dependencies.
  • Test Cases as High-Quality Priors: Instead of randomly guessing how APIs might combine, UCD-Training leverages the codebase's internal test cases. Because these test cases were written by the original maintainers to validate concrete features, they naturally reflect realistic usage patterns and engineering constraints.
  • Compositional API Data is King: In ablation studies, removing the compositional API reasoning data caused the most drastic performance drops (e.g., a 29.7% drop in pass@1 on the Python dataset). Learning how multiple APIs interact is the single most critical factor in mastering an unseen codebase.

Key Results

  • Outperforming RAG: Models trained with UCD-Training significantly outperformed state-of-the-art models using RAG. A relatively small 8B model trained via UCD-Training achieved a 31.5% pass@1 score on UnseenCodeBench, beating Claude-Sonnet-4.5 with RAG by 10.1% absolute.
  • Scaling Capabilities: Performance scaled favorably with model size. Moving from a Qwen 8B base to a 14B base improved pass@1 from 20.0% to 29.1% on the reaction codebase.
  • Multi-Codebase Mastery: In a simulated enterprise scenario where a single model was trained on all four unseen codebases simultaneously, the unified model retained its capabilities well, achieving a 36.0% pass@1 and outperforming all non-UCD baselines by 4.7% to 23.6%.

Limitations and Future Work

While highly effective, the authors note a few limitations:

  • Language Coverage: The current evaluation is restricted to C++ and Python. Future work will expand the framework to support a broader range of programming languages.
  • Hyperparameter Optimization: Due to computational constraints, the authors could not exhaustively search for the absolute optimal training configurations (such as the perfect ratio of general-domain to domain-specific data). They plan to explore these optimal training configurations in future empirical studies.

Summary updated

Abstract

In the context of newly release software frameworks, large language models (LLMs) often exhibit poor performance and a high rate of hallucination, as they are not exposed to such environments during training. Although inference-time augmentation techniques such as retrieval-augmented generation (RAG) can partially mitigate hallucinations, knowledge injection through prompting alone is insufficient to enable models to fully understand the intrinsic relationships among different components of a codebase, or to reason about the correct compositions and apply. Although explicit knowledge injection can be achieved through post-training, compared with public code domains, unseen codebases typically provide only source code and lack large volumes of high-quality, usage-oriented code that can be directly leveraged as training data. Consequently, existing data synthesis approaches are insufficient to adequately capture unseen codebases usage scenarios when restricted to source code alone. To address these challenges, we propose UCD-Training, a two-stage training framework for reasoning-aware data synthesis grounded in a code graph constructed from unseen codebases. UCD-Training first parses the source code to build a code graph, then conducts dependency-preserving continued pretraining (CPT) using file-level dependency data, followed by graph-grounded supervised fine-tuning (SFT) on three types of synthesized data augmented with explicit reasoning traces: (1) single-hop relation reasoning data, (2) compositional API reasoning data, and (3) codebase utilization data. We further introduce a new benchmark, UnseenCodeBench, for code generation on unseen codebases and conduct comprehensive experiments across multiple codebases.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
UnseenCodeBenchUCD-Training (Qwen3-14B-Base)Avg. pass@138.5%+7.2 vs baselineparams=14B · backbone=Qwen3-14B-Base · training-setting=standard
Source quote
L365: {Qwen3-14B-Base\xspace} │ 29.3% │ 22.2% │ 42.0% │ 29.1% │ 54.2% │ 47.2% │ 55.2% │ 38.5%
UnseenCodeBenchUCD-Training (Qwen3-8B-Base)Avg. pass@131.5%+0.2 vs baselineparams=8B · backbone=Qwen3-8B-Base · training-setting=standard
Source quote
L364: {Qwen3-8B-Base\xspace} │ 22.8% │ 19.1% │ 34.5% │ 20.0% │ 45.8% │ 38.8% │ 47.8% │ 31.5%
UnseenCodeBenchUCD-Training (combined; Qwen3-14B-Base)Avg. pass@136.0%+4.7 vs baselineparams=14B · backbone=Qwen3-14B-Base · training-setting=combined
Source quote
L369: {Qwen3-14B-Base\xspace} │ 23.3% │ 19.8% │ 44.4% │ 27.2% │ 54.7% │ 46.1% │ 50.9% │ 36.0%
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
UnseenCodeBenchCOTTON (Qwen3-14B-Base) baselineAvg. pass@131.3%params=14B · backbone=Qwen3-14B-Base
Source quote
L361: Qwen3-14B-Base\xspace │ 20.5% │ 16.2% │ 33.3% │ 18.8% │ 44.8% │ 39.1% │ 50.9% │ 31.3%
UnseenCodeBenchRAG (Claude-Sonnet-4.5) baselineAvg. pass@121.4%method=RAG · backbone=Claude-Sonnet-4.5
Source quote
L349: Claude-Sonnet-4.5\xspace │ 11.2% │ 9.5% │ 11.6% │ 2.2% │ 44.2% │ 39.4% │ 34.5% │ 21.4%
BibTeX
@misc{ou2026unseen,
  author = {Guangsheng Ou and Qiming Zhang and Sirong Chen and Anji Li and Dong Xu and Tiancheng Luo and Dekun Dai and Cuiyun Gao and Long Wang and Jun Zhou and Mingwei Liu and Zibin Zheng},
  title = {{Unseen-Codebases-Domain Data Synthesis and Training Based on Code Graphs}},
  year = {2026},
  eprint = {2602.20799},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.20799},
}

Loading related content...

Figure