Abstract
We present LinkQ, a system that leverages a large language model (LLM) to facilitate knowledge graph (KG) query construction through natural language question-answering. Traditional approaches often require detailed knowledge of a graph querying language, limiting the ability for users — even experts — to acquire valuable insights from KGs. LinkQ simplifies this process by implementing a multistep protocol in which the LLM interprets a user's question, then systematically converts it into a well-formed query. LinkQ helps users iteratively refine any open-ended questions into precise ones, supporting both targeted and exploratory analysis. Further, LinkQ guards against the LLM hallucinating outputs by ensuring users' questions are only ever answered from ground truth KG data. We demonstrate the efficacy of LinkQ through a qualitative study with five KG practitioners. Our results indicate that practitioners find LinkQ effective for KG question-answering, and desire future LLM-assisted exploratory data analysis systems.
Introduction
Knowledge Graphs (KGs) like Wikidata serve as massive repositories of interconnected information. However, extracting specific insights from these graphs typically requires mastery of specialized query languages like SPARQL and familiarity with obscure entity identification codes (e.g., Wikidata's code for "gold medal" is wd:Q7323). While Large Language Models (LLMs) show promise in translating natural language to code, they are prone to "hallucinations," often inventing non-existent entity IDs or relationships. This unreliability makes them difficult to use for high-stakes data retrieval.
LinkQ addresses these challenges by introducing a "human-in-the-loop" visual interface. It bridges the gap between flexible natural language and the rigid schemas of KGs through a structured grounding protocol that ensures accuracy while providing visual verification tools for the user.
System Architecture and Methodology
The core of LinkQ is a state-machine workflow designed to prevent the common pitfalls of LLM-generated queries. Rather than attempting a single-shot translation, the system follows a multi-step protocol to "ground" the LLM's logic in real-world data.
- Clarification: If a user’s initial query is too broad, the LLM suggests specific KG properties to narrow the scope.
- Fuzzy Search & Grounding: The LLM identifies potential entities and triggers a fuzzy search via the Wikidata API. This forces the LLM to use verified, ground-truth IDs instead of hallucinated ones.
- Graph Traversal: The LLM explores the graph's relations to identify valid paths between entities (e.g., connecting a film to its director and then to that director's awards).
- Visual Preview: Before execution, the system presents a preview panel where users can inspect the raw SPARQL code, an entity-relation table, and a visual query graph.
- Execution & Summarization: Upon user approval, the query is executed against the KG, and the LLM generates a natural language summary of the results.
The LinkQ Visual Interface
The interface is designed to build trust and reduce cognitive burden. The Query Preview Panel is a critical component, allowing users to verify the LLM's semantic intent before running potentially expensive or incorrect queries.
Key visual elements include:
- Query Graph: A node-link diagram that maps the query’s logic, showing how variables and terms connect. Practitioners found this visualization essential for confirming that the LLM correctly captured their intent.
- Entity-Relation Table: Provides human-readable labels for the technical IDs used in the query, making it easier to spot errors in entity selection.
- Results Summary: A natural language explanation of the data retrieved from the KG, providing immediate context to the raw table results.
Evaluation and Results
LinkQ was evaluated using Wikidata, a massive RDF knowledge graph with over 100 million entities. The researchers tested several LLMs, including GPT-4, Code Llama, and Mistral, ultimately selecting GPT-4 for its superior consistency.
A qualitative study with five KG practitioners (data scientists) explored use cases in films, cybersecurity, and geography. The study revealed that the entire protocol typically takes only 10–15 seconds from input to result. In stress tests, LinkQ successfully generated correct SPARQL queries in approximately 66% of cases. Failures were primarily attributed to missing data within Wikidata itself or complex unit conversion requirements.
Practitioners reported that LinkQ significantly lowered the barrier to entry for KG exploration. One participant noted they no longer felt the need to manually write SPARQL queries, praising the system's ability to retrieve "actual, ground truth information."
Discussion and Future Work
The "hallucination guard" provided by the iterative lookup protocol is LinkQ's primary innovation. By requiring the LLM to validate IDs against the KG before finalizing a query, the system eliminates the most frequent failure point of AI coding assistants.
However, limitations remain. The system currently requires complex prompting to ensure the LLM adheres to the protocol. Future iterations could improve the distinction between LLM-generated summaries and raw KG data to prevent user confusion. Additionally, while LinkQ excels with public data like Wikidata, future research will focus on scaling the system for private enterprise databases and conducting quantitative comparisons against standard Retrieval-Augmented Generation (RAG) techniques.
Summary updated