Abstract
Knowledge Graph Question Answering (KGQA) faces challenges when Large Language Models (LLMs) are tasked with generating complex SPARQL queries directly, often resulting in "tool-use hallucinations" and poor readability. This paper introduces Memory-augmented Query Reconstruction (MemQ), a novel framework that decouples high-level natural language reasoning from low-level query syntax. MemQ utilizes a Tool Utilization Memory to store atomic query snippets paired with natural language descriptions. During inference, the LLM generates a natural language reasoning plan, and MemQ retrieves and reconstructs the corresponding SPARQL query. Evaluated on WebQSP and CWQ, MemQ achieves state-of-the-art performance, demonstrating improved structural accuracy and robustness to noisy data.
Introduction
Large Language Models (LLMs) have shown remarkable capabilities in natural language understanding, yet their performance in Knowledge Graph Question Answering (KGQA) is often hampered by the requirement to generate precise database queries like SPARQL. This direct generation approach leads to two primary issues: hallucination of non-existent relations and poor human-verifiability of abstract code. The authors argue that forcing LLMs to act simultaneously as logicians and database programmers is suboptimal. Instead, they propose decoupling these roles, allowing the LLM to focus on high-level reasoning while a specialized system handles technical query reconstruction.
The MemQ Framework
The proposed MemQ framework operates through a three-stage process designed to bridge the gap between natural language intent and formal query execution.
- Memory Construction: Historical query data is decomposed into atomic statements. An LLM generates natural language descriptions for these snippets (e.g., "Find the sibling of X"), which are then stored in a Tool Utilization Memory. This stage effectively creates a library of reusable query components.
- Knowledge Reasoning: For a given question, the LLM acts as a "Planning Expert," generating a step-by-step reasoning plan entirely in natural language. This avoids the pitfalls of syntax errors during the reasoning phase.
- Query Reconstruction: MemQ uses semantic similarity (via Sentence-BERT) to retrieve the most relevant SPARQL snippets from memory for each reasoning step. An Adaptive Memory Recall Strategy determines the optimal number of snippets, which are then stitched into a valid SPARQL query using rule-based logic.
A critical component of this reconstruction is the handling of Compound Value Type (CVT) nodes, which represent complex n-ary relations in graphs like Freebase. MemQ ensures these structures are correctly decomposed and reassembled without losing semantic integrity.
Experimental Evaluation
MemQ was evaluated on two prominent KGQA benchmarks: WebQSP (WebQuestions Semantic Parses) and CWQ (Complex WebQuestions). CWQ is particularly challenging as it requires multi-hop reasoning and various constraints.
Key Results
MemQ achieved state-of-the-art (SOTA) results on both benchmarks:
- WebQSP: 0.841 Hits@1 and 0.858 F1.
- CWQ: 0.803 Hits@1 and 0.830 F1.
Beyond raw performance, MemQ demonstrated significant improvements in structural accuracy. By measuring "Graph Edit Distance," the authors found that MemQ's reconstructed queries were structurally closer to ground-truth queries than those produced by previous methods like RoG.
Robustness and Efficiency
The framework showed remarkable resilience to data quality issues. Even when 10-20% of the training data was "disturbed" with noise, MemQ maintained high performance. Furthermore, it exhibited high data efficiency, outperforming zero-shot baselines with only 10% of the available training data.
Conclusion
MemQ demonstrates that decoupling reasoning from syntax is a powerful strategy for KGQA. By leveraging natural language as a bridge between LLM planning and formal query reconstruction, the framework significantly reduces hallucinations and improves the reliability of tool-use in complex reasoning tasks. Future work will explore automatic memory construction from raw Knowledge Graphs and the transferability of tool memories across different domains.
Summary updated