Context-Augmented Code Generation Using Programming Knowledge Graphs DOI: XXXXXXX.XXXXXXX Journal: TOSEM Volume: 37 4 111 8 CCS: Computing methodologies Natural language processing CCS: Software and its engineering
Shahd Seddik, Fahd Seddik, Iman Saberi, Fatemeh Fard, Minh Hieu Huynh, Patanamon Thongtanunam · 2026
Read Context-Augmented Code Generation Using Programming Knowledge Graphs DOI: XXXXXXX.XXXXXXX Journal: TOSEM Volume: 37 4 111 8 CCS: Computing methodologies Natural language processing CCS: Software and its engineering by Shahd Seddik, Fahd Seddik, Iman Saberi, Fatemeh Fard, Minh Hieu Huynh, Patanamon Thongtanunam (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2601-20810.txt.
Introduction
Shahd Seddik and five co-authors work on making AI write better code for hard problems. Their 2026 paper notes that large language models excel at code generation but stumble on complex tasks. Retrieval-augmented generation helps by fetching outside knowledge. Yet the fetch can miss key context, and the model may hallucinate when fed irrelevant data.
The authors propose Programming Knowledge Graphs, or PKG. A knowledge graph stores code and text as linked facts with clear meaning. That structure supports fine-grained retrieval: small, precise pieces of context. The aim is to hand the model only what it truly needs. The paper targets software tasks where a wrong guess is costly. It shows one way to ground code models in curated knowledge.
Catalog record
| CREATOR | Shahd Seddik, Fahd Seddik, Iman Saberi, Fatemeh Fard, Minh Hieu Huynh, Patanamon Thongtanunam |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 85 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2601-20810
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Context-Augmented Code Generation Using Programming Knowledge Graphs DOI: XXXXXXX.XXXXXXX Journal: TOSEM Volume: 37 4 111 8 CCS: Computing methodologies Natural language processing CCS: Software and its engineering Shahd Seddik, Fahd Seddik, Iman Saberi, Fatemeh Fard, Minh Hieu Huynh, Patanamon Thongtanunam 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 . 1. Introduction Large Language Models (LLMs) have enabled natural-language-to-code generation on a wide range of programming tasks ( 3 ; 13 ; 27 ) . However, functional correctness often depends on external programming knowledge that is not consistently stored in model parameters, including API usage conventions, corner cases, and idiomatic patterns. Consequently, Retrieval-Augmented Generation (RAG) has become a practical mechanism for grounding code generation in external sources such as library documentation, tutorials, and code repositories ( 43 ; 38 ) . Recent large-scale evaluations further show that end-to-end gains depend jointly on retrieval quality and the generator’s ability to use retrieved context effectively ( 35 ) . At the same time, code-oriented RAG remains brittle. Prior work has shown that retrieved context can be redundant, partially relevant, or misleading, and that models may under-utilize or be distracted by long contexts ( 35 ) . More broadly, analyses of context utilization caution that performance measured under simplified or synthetic assumptions can overestimate how effectively models use retrieved context under realistic retrieval distributions ( 11 ) . Recent RAG pipelines for code have explored diverse retrieval strategies and knowledge bases ( 30 ) , yet systematic evidence suggests two recurring bottlenecks: accurately identifying helpful evidence for a given programming query, and operating under limited context budgets where irrelevant retrieval can directly harm generation ( 35 ) . A central reason these bottlenecks persist is that actionable programming knowledge is heterogeneous. Developers draw from code-centric artifacts (e.g., implementations, utilities, reusable patterns) as well as text-centric artifacts (e.g., tutorial narratives, API documentation, and Q&A explanations) ( 35 ) . This heterogeneity is not incidental; software maintenance evidence indicates that code and natural-language documentation often co-evolve, implying that text encodes complementary signals rather than redundant descriptions of code ( 24 ) . As a result, the representation used for retrieval must cope with fundamentally different structures across artifacts. This raises an under-specified design problem. For code generation, what should be retrieved, and in what representation, to preserve useful knowledge while minimizing noise? Empirical studies show that different retrieved information types have qualitatively different values. Context-relevant information can help, while superficially similar snippets can introduce noise and degrade results ( 8 ) . These findings motivate knowledge representations that are explicitly designed to separate, organize, and filter heterogeneous knowledge rather than treating all data sources as flat nearest-neighbor chunks ( 15 ) . Recent work supports the principle that structure can materially change retrieval behavior and downstream generation ( 31 ) . For code-centric corpora, structure-aware chunking based on Abstract Syntax Trees (ASTs) yields more coherent retrievable units and improves retrieval-augmented code generation relative to line-based heuristics ( 40 ) . For long or redundant sources, tree-structured search improves over flat ranking ( 31 ) . In addition, work on granularity selection shows that the size of retrieval units induces an inherent precision–recall trade-off that can substantially affect downstream performance ( 42 ) . Collectively, these results motivate studying representations that (i) align retrieval units with structure and (ii) provide explicit control over how context is assembled. In this work, we present Programming Knowledge Graphs (PKGs) , a novel representation for RAG, using two stand-alone variants to isolate the role of knowledge modality and representation, being code-centric PKG and text-centric PKG. Through PKG, we address the two challenges of accurately identifying and retrieving helpful documents for code generation. The code-centric PKG is constructed by parsing source code into an AST-derived hierarchy and then constructing a directed structure that mirrors syntactic containment. A function node expands to a sequence of block nodes, each of which may expand to child block nodes (and so on), yielding a multi-level tree rooted at the function. This construction aligns retrieval units with syntactic boundaries and preserves self-contained code regions, consistent with evidence that AST-respecting segmentation produces more coherent retrieval units for retrieval-augmented code generation ( 40 ) . A key advantage of this hierarchy is that it enables retrieval at multiple granularities. We instantiate two retrieval settings: Func-PKG , which retrieves at the function level (coarser units), and Block-PKG , which retrieves at the block level (finer units). These settings operationalize an inherent granularity trade-off: coarser units tend to increase recall but risk injecting irrelevant content, while finer units can improve precision but may omit surrounding context needed for correct synthesis. Prior RAG work highlights that chunk granularity directly affects retrieval precision and recall and that selecting an appropriate granularity can significantly change downstream performance ( 42 ) . We therefore evaluate both granularity settings to quantify this precision–recall trade-off in code-centric PKG retrieval and to determine when finer structure improves (or harms) end-to-end code generation. The text-centric PKG targets tutorial/documentation-style knowledge, where usefulness often depends on internal structure (titles, sections, explanations, examples) and on the ability to retrieve specific fields rather than entire passages ( 15 ) . We adopt a structured JSON representation as an explicit schema over heterogeneous tutorial fields, then construct a Directed Acyclic Graph (DAG) whose nodes correspond to JSON fields/sections and whose edges encode structural relations (e.g., example-to-explanation linkage). The intent is twofold: (i) normalize diverse textual artifacts into a parseable representation that supports field-level retrieval and assembly; and (ii) enable structure-aware traversal and composition, following the general retrieval-and-structuring perspective that hierarchical organization can improve controllability and reduce noise ( 15 ; 39 ) . Because structured expansion can still overgrow context windows, we incorporate tree pruning as an explicit control mechanism before prompt construction. This design follows evidence that pruning irrelevant context can reduce computational overhead and mitigate noise propagation in retrieval-augmented generation ( 5 ) . Finally, even with improved context, different approaches excel at solving distinct types of problems ( 32 ) . We therefore complement retrieval with post-generation reranking (sample–then–select), where multiple candidate solutions from multiple methods (e.g., RAG and non-RAG approaches) are generated and then ranked to select the best. Recent work on code generation studies candidate reranking explicitly and reports improved success by selecting among diverse samples, supporting reranking as a practical method applied to retrieval ( 29 ; 2 ) . The reranker, therefore, can prioritize solutions generated without