Context-Augmented Code Generation Using Programming Knowledge Graphs

Shahd Seddik, Fahd Seddik, Iman Saberi, Fatemeh Fard, Minh Hieu Huynh +1 more
1/28/2026
cs.SEcs.LG

Official code: iamshahd/ProgrammingKnowledgeGraph (2 stars, last commit 2026-01-26).

Abstract

Large Language Models (LLMs) excel at code generation but struggle with complex problems. Retrieval-Augmented Generation (RAG) mitigates this issue by integrating external knowledge, yet retrieval models often miss relevant context, and generation models hallucinate with irrelevant data. We propose Programming Knowledge Graph (PKG) for semantic representation and fine-grained retrieval of code and text. Our approach enhances retrieval precision through tree pruning and mitigates hallucinations via a re-ranking mechanism that integrates non-RAG solutions. Structuring external data into finer-grained nodes improves retrieval granularity. Evaluations on HumanEval and MBPP show up to 20% pass@1 accuracy gains and a 34% improvement over baselines on MBPP. Our findings demonstrate that our proposed PKG approach along with re-ranker effectively address complex problems while maintaining minimal negative impact on solutions that are already correct without RAG. The replication package is published at https://github.com/iamshahd/ProgrammingKnowledgeGraph

View on arXivView PDF

Code Implementations(1)

20TeX, ShellJan 26, 20268 months ago

Similar Papers

Cite this paper

@article{seddik2026contextaugmented,
  title  = {Context-Augmented Code Generation Using Programming Knowledge Graphs},
  author = {Shahd Seddik and Fahd Seddik and Iman Saberi and Fatemeh Fard and Minh Hieu Huynh and Patanamon Thongtanunam},
  year   = {2026},
  eprint = {2601.20810},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2601.20810v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2601.20810.svg)](https://codeofpaper.com/paper/2601.20810)

Discussion