NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Improving LLM-based KGQA for multi-hop Question Answering with implicit reasoning in few-shot examples

Mili Shah, Joyce Cahoon, Mirco Milletarì, Jing Tian, Fotis Psallidas, Andreas Mueller, Nick Litombe2024

Abstract

Large language models (LLMs) have shown remarkable capabilities in generating natural language texts for various tasks. However, using LLMs for question answering on knowledge graphs still remains a challenge, especially for questions requiring multi-hop reasoning. In this paper, we present a novel planned query guidance approach that improves large language model (LLM) performance in multi-hop question answering on knowledge graphs (KGQA). We do this by designing few-shot examples that implicitly demonstrate a systematic reasoning methodology to answer multi-hop questions. We evaluate our approach for two graph query languages, Cypher and SPARQL, and show that the queries generated using our strategy outperform the queries generated using a baseline LLM and typical few-shot examples by up to 24.66% and 7.7% in execution match accuracy for the MetaQA and the Spider benchmarks respectively. We also conduct an ablation study to analyze the incremental effects of the different techniques of designing few-shot examples. Our results suggest that our approach enables the LLM to effectively leverage the few-shot examples to generate queries for multi-hop KGQA.

Introduction

Knowledge Graph Question Answering (KGQA) involves translating natural language questions (e.g., "Who directed the movies starring Tom Hanks?") into formal graph query languages like Cypher or SPARQL. While LLMs are proficient at simple one-hop queries, they often struggle with multi-hop reasoning—tasks that require traversing multiple relationships across a graph. Traditional query writing styles are often too condensed for an LLM to learn the underlying logic, and fine-tuning specialized models for every new schema is prohibitively expensive. This research introduces "planned query guidance," a method to teach LLMs reasoning logic purely through the design of few-shot examples provided in the prompt.

Methodology: Planned Query Guidance

The core of this approach is a set of six design principles for few-shot examples that provide implicit reasoning. Instead of using explicit Chain-of-Thought (CoT) prompting, which increases latency and cost, the researchers use a specific coding style to guide the model:

  1. Structured Traversal Clarity: Each "hop" in the graph is written on its own line.
  2. Logical Continuity: The endpoint of one line’s traversal must be the starting point of the next, creating a clear chain.
  3. Distinct Separation of Logic: Graph patterns (MATCH) are kept separate from filters and constraints (WHERE).
  4. Descriptive Variable Naming: Meaningful names (e.g., dilMovie or actorName) replace generic variables like n1 to help the LLM track entities.
  5. Increasing Complexity: Examples are ordered from simple 1-hop to complex 3-hop queries to reinforce the pattern.
  6. Consistency: All examples follow the exact same structural template.

Evaluation and Results

The approach was evaluated using GPT-4 on two major benchmarks: MetaQA (a movie-based graph for multi-hop testing) and Spider (a complex, cross-domain dataset adapted for SPARQL).

Comparison of execution match accuracy on MetaQA across different question complexities.

As shown in the results for MetaQA, the proposed approach significantly outperforms both the LangChain baseline and conventional few-shot styles. On the most difficult 3-hop questions, the method achieved 97.33% execution match accuracy, compared to 67.33% for the LangChain baseline and 72.67% for conventional examples. For the Spider benchmark, the method showed a peak improvement of 7.7% on specific sub-graphs.

Ablation Study

To analyze the incremental effects of these design techniques, the researchers conducted an ablation study. The results confirmed that structural clarity and descriptive naming are the primary drivers of performance.

Ablation study showing the impact of various few-shot design choices on execution match accuracy.

The study demonstrated that "All hops in one line" (the conventional style) was significantly less effective than the multi-line approach. Furthermore, using non-descriptive variable names led to a drop in accuracy from 97.33% to 87.33%, proving that variable names act as essential anchors for the LLM's attention.

Conclusion

This research demonstrates that the structural format of few-shot examples can serve as an effective reasoning chain for LLMs in KGQA tasks. By forcing the query into a multi-line, "one-hop-per-line" format with descriptive variables, the LLM is effectively guided to plan its path through the graph. While the method shows strong results, future work will address extreme complexity (10+ hops) and the potential for automatic generation of these structured prompts.

Summary updated

BibTeX
@misc{shah2024improving,
  author = {Mili Shah and Joyce Cahoon and Mirco Milletarì and Jing Tian and Fotis Psallidas and Andreas Mueller and Nick Litombe},
  title = {{Improving LLM-based KGQA for multi-hop Question Answering with implicit reasoning in few-shot examples}},
  year = {2024},
  doi = {10.18653/v1/2024.kallm-1.13},
}
Figure