KCoEvo: A Knowledge Graph Augmented Framework for Evolutionary Code Generation

Jiazhen Kang, Yuchen Lu, Chen Jiang, Jinrui Liu, Tianhao Zhang, Bo Jiang, Ningyuan Sun, Tongtong Wu, Guilin Qi

TL;DR

Large Language Models (LLMs) frequently struggle with version-aware code migration because they lack a structured understanding of how APIs change over time. KCoEvo addresses this by introducing a two-stage knowledge graph-augmented framework that retrieves explicit evolution paths and uses them to guide LLMs in generating version-compliant code. This approach significantly boosts migration accuracy and execution success across both minor and major library updates.

What Problem Does This Paper Address?

In modern software development, third-party libraries and frameworks evolve rapidly. While updates bring new features, they often introduce breaking API changes that complicate code maintenance.

LLMs like GPT-4o or DeepSeek show immense promise in code generation, but they suffer from "temporal knowledge obsolescence." Because their training data is static, they operate on implicit, unstructured internal knowledge. Consequently, when tasked with updating code to a newer library version, they often hallucinate deprecated APIs or generate syntactically invalid code. They lack a reliable mechanism to trace how an API's structure, parameters, or module locations have shifted across versions.

Illustration of API evolution in PyTorch across different update stages and its impact on industry adopters.

Methods

The authors propose KCoEvo, a framework that decomposes version-aware code migration into two synergistic stages: Evolutionary Path Retrieval and Path-Informed Code Generation.

Overview of the KCoEvo framework, detailing the two-stage pipeline from path retrieval to code generation.
  1. API Knowledge Graph Construction: KCoEvo builds a two-level structured knowledge graph (KG).
  2. A static API graph captures intra-version hierarchies (e.g., modules containing classes, classes containing methods, and their parameters).
  3. A dynamic alignment graph links these entities across versions using explicit evolution types like Add, Retain, Remove, Rename, and Relocate.
Lightweight schema of the version-aware knowledge graph showing intra-version (blue) and cross-version (red) relations.
  1. Evolutionary Path Retrieval: Given a code snippet and a target version, the system locates the relevant API nodes and uses Breadth-First Search (BFS) to traverse the cross-version graph. This extracts a precise trajectory of how the source API transitions to the target version.
  2. Path-Informed Code Generation: The framework reuses the backbone LLM in a two-phase prompting process. First, a Planning Module generates an explicit evolutionary path (e.g., a1 -> relocate -> a1' -> parameter-change -> a2). Second, a Reasoning Module uses this structural path as guidance to generate the final, updated code snippet.

Datasets

The framework was evaluated using VersiCode, a specialized benchmark designed to measure version-controllable code generation. VersiCode contains hundreds of aligned source and target code pairs mined from historical version changes of prominent Python libraries (such as TensorFlow, Pandas, Scikit-learn, and Transformers). The dataset supports granular evaluation categorized by evolution types and release timelines.

Key Insights and Ideas

  • The Semantic-Syntactic Gap: Integrating KGs drastically improves an LLM's semantic matching ability (Exact Match scores skyrocketed). However, the improvement in functional correctness (Critical Diff Check) was sometimes smaller. This reveals that while structured graphs help LLMs "memorize" API replacements, they can cause the model to overfit to symbolic matching, occasionally neglecting strict syntax or argument counts.
  • Even "Smart" Models Need Grounding: High-capacity models like GPT-5 possess strong baselines, but their performance gains under KCoEvo were still notable in minor-version migrations. This proves that even state-of-the-art LLMs cannot reliably deduce subtle, fine-grained API updates without explicit structural grounding.
  • Context Quality Matters: When comparing KCoEvo against standard Retrieval-Augmented Generation (RAG), providing the LLM with structured library source code or graph paths yielded far superior generalization than using fragmented, context-poor Stack Overflow snippets.

Key Results

KCoEvo was tested across a variety of open- and closed-source LLMs (including DeepSeek-V3, Qwen2.5, LLaMA-3, Gemini, and GPT-5), yielding substantial performance leaps:

  • DeepSeek-V3 saw its Exact Match (EM@1) jump from 59.52% to 100.00% and its functional correctness (CDC@1) improve from 59.52% to 96.83% in Major$\rightarrow$Major version migrations.
  • Qwen2.5-Coder-32B-Instruct and Llama-3-70B-Instruct-Turbo achieved massive improvements of over 60 percentage points in EM@1 during complex cross-version shifts (like Major$\rightarrow$Minor and Minor$\rightarrow$Major transitions).

Limitations and Future Work

The primary bottleneck of KCoEvo is the overhead of knowledge graph maintenance. Continuously extracting, updating, and storing large-scale KGs across dozens of rapidly updating software ecosystems demands significant computational and storage resources.

To make this sustainable for large organizations, the authors note that future work must focus on developing lightweight, incremental graph update strategies. Additionally, they plan to extend the framework to support cross-lingual code adaptation and integrate KCoEvo directly into IDEs as developer plugins for real-time, automated dependency updates.

Summary updated

BibTeX
@inproceedings{kang2026kcoevo,
  author = {Jiazhen Kang and Yuchen Lu and Chen Jiang and Jinrui Liu and Tianhao Zhang and Bo Jiang and Ningyuan Sun and Tongtong Wu and Guilin Qi},
  title = {{KCoEvo: A Knowledge Graph Augmented Framework for Evolutionary Code Generation}},
  booktitle = {DASFAA},
  year = {2026},
  doi = {10.1007/978-981-92-0378-9\_30},
}
Figure