GenSPARQL: A Generative Extension of SPARQL for Incomplete Knowledge Graphs

Jingcheng Wu, Yi Wang, Hongkuan Zhou, Steffen Staab, Bo XiongarXiv 2026 · arXiv

TL;DR

GenSPARQL is a generative extension of the SPARQL query language that allows users to fill gaps in incomplete Knowledge Graphs (KGs) using Large Language Models (LLMs). By introducing a new operator, GENOP, it seamlessly integrates LLM-generated data into structured queries, automatically mapping text responses back to graph entities (IRIs) and optimizing query execution to minimize expensive LLM calls.

What Problem Does This Paper Address?

Knowledge Graphs like Wikidata are incredibly powerful but notoriously incomplete. If you query a KG for "the playing positions of the 2026 Argentine World Cup squad," and that specific data hasn't been curated yet, a standard SPARQL query returns nothing—even if the information is common knowledge.

While LLMs "know" these missing facts, using them with KGs is currently clunky. LLMs return plain text (e.g., "Lionel Messi") rather than the unique identifiers KGs require (e.g., wd:Q615). Furthermore, calling an LLM for every single entity in a large database is slow and expensive. GenSPARQL addresses these hurdles by bringing the LLM directly into the query engine.

Methods

The authors introduce GenSPARQL, which extends SPARQL 1.1 with a novel operator called GENOP.

Key technical features include:

  • The GENOP Operator: This operator takes a natural language prompt template, a set of output variables, an LLM model identifier, and a similarity threshold. It can operate in base mode (generating new lists of items) or context mode (filling in attributes for existing entities in the graph).
  • Similarity Joins: Because LLMs return strings, GenSPARQL uses a similarity join to map these strings back to the graph's IRIs. It primarily uses cosine similarity of text embeddings (via models like bge-large-en-v1.5) to handle name variants (e.g., matching "Emiliano Martinez" to "Emiliano Martínez").
  • Lazy Query Planning: To save on costs and time, the GenSPARQL planner ensures that LLMs are only invoked for the specific bindings that have already passed through other graph filters. For example, if you filter for "Argentine players" first, the LLM is only asked for the positions of those 26 players, rather than all 1,200+ players in the database.
Figure 2: Two GENOP queries over the 2026 World Cup graph.

Datasets

The researchers evaluated GenSPARQL using two custom-built graphs derived from Wikidata:

  1. 2026 World Cup Graph: Containing 1,248 players and 48 teams, with playing positions intentionally removed.
  2. Nobel Laureates Graph: Containing 1,018 laureates, with birth years removed.

They tested the system against three open-weight LLMs: Qwen3-30B, Qwen3-8B, and Mistral-7B.

Key Insights and Ideas

  • Bridging the "String-to-IRI" Gap: The most significant "aha" moment is the use of embedding-based similarity joins within the query algebra. This allows the system to be resilient to the "fuzzy" nature of LLM outputs while maintaining the rigour of a structured database.
  • LLMs as On-Demand Materializers: Instead of pre-calculating and storing every possible missing fact (which is wasteful), GenSPARQL treats the LLM as a virtual part of the graph that materializes data only when a query specifically asks for it.
  • Efficiency through Ordering: By placing GENOP at the end of the join sequence, the system avoids the "N-call problem" where an LLM might be queried for irrelevant data.

Key Results

The evaluation showed that GenSPARQL is highly effective at recovering missing information:

  • Entity Mapping: Using embedding similarity, the system correctly mapped 83% of the entities named by the LLMs back to the graph, with only a single incorrect match at a threshold of $\theta = 0.85$.
  • Fact Accuracy: The LLMs correctly identified player positions 55–59% of the time and birth years 69–90% of the time. While not perfect, this is a massive improvement over the 0% return rate of standard SPARQL on incomplete data.
  • Optimization: In one test case, the query planner reduced the number of LLM calls from 1,248 (total players) down to just 104 (players in a specific group), demonstrating the power of integrated query optimization.
Table 1: Results for the generated attributes and names.

Limitations and Future Work

The authors acknowledge several areas for improvement:

  • Hallucinations: LLMs can still generate names for entities that don't exist in the graph or the real world.
  • Uncertainty: Currently, GenSPARQL returns results as "facts," but LLM outputs are probabilistic. Future work could involve propagating uncertainty scores through the query results.
  • Mapping Complexity: While embedding similarity is strong, very low thresholds can lead to "false friends" (mapping a name to the wrong, similar-sounding entity).

GenSPARQL represents a significant step toward "Hybrid Intelligence" systems that combine the reliability of structured data with the vast, latent knowledge of generative AI.

Summary updated

Abstract

Knowledge graphs on the Web are incomplete, and SPARQL answers a query only from the stored triples. Large language models (LLMs) can predict missing facts, but an LLM returns names instead of IRIs and requires one call per binding of a query variable. We present GenSPARQL, a generative extension of SPARQL 1.1 with an operator GENOP that binds values generated by an LLM to query variables during query evaluation. A similarity join maps generated names to entities of the graph, and the query planner invokes the LLM only for the bindings selected by the other graph patterns and filters. In a web workbench, attendees query two graphs built from Wikidata and inspect generated values, mapped entities and LLM calls. In our evaluation with three open-weight LLMs, the embedding similarity maps 83% of the entities named by the LLMs and yields only one incorrect match.
BibTeX
@misc{wu2026gensparql,
  author = {Jingcheng Wu and Yi Wang and Hongkuan Zhou and Steffen Staab and Bo Xiong},
  title = {{GenSPARQL: A Generative Extension of SPARQL for Incomplete Knowledge Graphs}},
  year = {2026},
  eprint = {2611.26062},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.26062},
}
Figure