arXiv

Code-on-Graph: Iterative Programmatic Reasoning via Large Language Models on Knowledge Graphs

Title: Code-on-Graph: Iterative Programmatic Reasoning via Large Language Models on Knowledge Graphs

Original: arXiv:2606.03705v1 Announce Type: new Abstract: Knowledge Graphs (KGs) are widely used to mitigate the limitations of Large Language Models (LLMs), such as outdated knowledge and hallucinations. Existing LLM-KG integration frameworks typically rely on predefined operators to retrieve factual knowledge from KGs and inject it into prompts for answer generation. This paradigm faces two critical bottlenecks: 1) Inflexibility: The predefined operators are limited in scope and thus lack sufficient compositional expressiveness to fully capture the complex semantics required by KG questions. 2) Unscalability: Direct injection of factual knowledge into prompts limits scalability in handling large-scale factual knowledge. To address these two bottlenecks, we propose Code-on-Graph (CoG), a programmatic reasoning framework for LLM-KG integration. Specifically, given the factual knowledge retrieved at each reasoning step, CoG first identifies the corresponding KG schemas and represents these schemas as Python classes, which serve as abstract interfaces to the retrieved facts. It then generates executable code grounded in these classes, with the retrieved facts instantiated as objects of the corresponding classes during execution. This design enables flexible code-based reasoning while avoiding the direct injection of large-scale factual knowledge into prompts. Experiments on WebQSP, CWQ, and GrailQA demonstrate that CoG outperforms prior state-of-the-art models by up to 10.5%.

Rewritten:

Title: Code-on-Graph: Iterative Programmatic Reasoning via Large Language Models on Knowledge Graphs

Abstract: Large Language Models (LLMs) frequently suffer from issues like hallucinations and obsolete information, leading to the widespread adoption of Knowledge Graphs (KGs) as a remedy. Current approaches to integrating LLMs with KGs generally depend on fixed operators to extract factual data and insert it directly into prompts for generating answers. However, this method encounters two major limitations: First, it lacks flexibility, as predefined operators have a narrow scope and insufficient compositional power to adequately represent the complex semantics inherent in KG-based queries. Second, it is not scalable, because embedding vast amounts of factual data directly into prompts restricts the system's ability to manage large-scale knowledge bases effectively.

To overcome these challenges, we introduce Code-on-Graph (CoG), a novel programmatic reasoning framework designed for LLM-KG integration. At each step of the reasoning process, CoG takes the retrieved factual knowledge and maps it to corresponding KG schemas, which are then encoded as Python classes acting as abstract interfaces. The framework subsequently produces executable code based on these classes, instantiating the retrieved facts as objects during runtime. This architecture facilitates adaptable reasoning through code execution, thereby eliminating the need to inject extensive factual knowledge directly into prompts. Our evaluations on the WebQSP, CWQ, and GrailQA datasets show that CoG surpasses existing state-of-the-art models by as much as 10.5%.


Source: arXiv Generated at: 2026-06-03 00:00:00 UTC

Related Articles

TikTok Billionaire Tops Ambani as Asia’s Second-Richest
Bloomberg

TikTok Billionaire Tops Ambani as Asia’s Second-Richest

TikTok founder surpasses Mukesh Ambani to become Asia’s second-richest person, marking a significant shift in the region...

Publishers in UK can opt out of Google AI search results
BBC News

Publishers in UK can opt out of Google AI search results

UK publishers can now opt out of Google’s AI search summaries, a CMA ruling designed to boost their bargaining power and...

Kioxia Edges Nearer Toyota’s Market Cap in Shakeup to Japan Inc.
Bloomberg

Kioxia Edges Nearer Toyota’s Market Cap in Shakeup to Japan Inc.

Kioxia’s market cap nears Toyota’s, signaling a major shift in Japan’s corporate hierarchy. This narrowing gap highlight...

Reuters

Morning Bid: Marvell, a fitting name for the latest AI darling

Reuters highlights Marvell as a top AI stock, noting its name perfectly suits its status as the newest market darling.

Financial Times

Tim Hayward: I built the Jaguar E-Type of computer keyboards

Tim Hayward compares his bespoke keyboard designs to the Jaguar E-Type. He explores high-end customization for personal ...

Financial Times

AI Labs: Zuckerberg’s $100bn gamble

Meta’s $100 billion AI investment aims to secure AI dominance, but questions remain whether sheer spending can outpace c...