Abstract
The Knowledge Base Question Answering (KBQA) task aims to answer natural language questions based on a given knowledge base. Recently, Large Language Models (LLMs) have shown strong capabilities in language understanding and can be used to solve this task. In doing so, a major challenge for LLMs is to overcome the immensity and heterogeneity of knowledge base schemas. Existing methods bypass this challenge by initially employing LLMs to generate drafts of logic forms without schema-specific details. Then, an extra module is used to inject schema information to these drafts. In contrast, in this paper, we propose a simple In-Context Schema Understanding (ICSU) method that enables LLMs to directly understand schemas by leveraging in-context learning. Specifically, ICSU provides schema information to LLMs using schema-related annotated examples. We investigate three example retrieval strategies based on raw questions, anonymized questions, and generated SPARQL queries. Experimental results show that ICSU demonstrates competitive performance compared to baseline methods on both the KQA Pro and WebQSP datasets.
Introduction
Large Language Models (LLMs) excel in natural language processing but often struggle with structured database queries due to the "schema gap." When querying a Knowledge Base (KB), an LLM may fail to map a natural language concept like "constitutional monarchy" to the specific database predicate (e.g., <pred:instance_of>). This challenge is exacerbated by the scale of modern KBs, which can contain thousands of relations, and their heterogeneity, where different databases use varying naming conventions for identical concepts.
Previous approaches often relied on multi-stage pipelines where LLMs generate "schema-free" drafts that are subsequently mapped to the KB by external modules. This paper introduces In-Context Schema Understanding (ICSU), a method that allows LLMs to learn a database's unique schema on the fly through in-context learning with strategically selected examples.
Methodology
The ICSU framework leverages the few-shot learning capabilities of LLMs. By providing a small set of annotated examples that demonstrate the mapping from natural language to the specific KB schema, the LLM can generate accurate SPARQL queries by analogy. The "secret sauce" is how the system finds the most relevant examples to include in the prompt.
 Source, p. 1
The authors explored four retrieval strategies:
- ICSU (Raw): Retrieves examples based on the similarity of the raw natural language question.
- ICSU (Anonymized): Replaces entities with placeholders to focus on the logical structure and relations.
- ICSU (SPARQL): Uses a two-step process where an initial "draft" SPARQL query is generated to retrieve examples with similar structural logic.
- ICSU (Hybrid): Combines these strategies to provide a diverse set of contextually relevant examples.
Experiments and Results
The method was evaluated on two benchmarks: KQA Pro (a large-scale dataset with a non-standard Wikidata schema) and WebQSP (a smaller dataset based on Freebase). These datasets were chosen to test the model's ability to learn new schemas and its robustness with limited data.
As shown in the results, ICSU (Hybrid) achieved a state-of-the-art accuracy of 76.16% on KQA Pro, significantly outperforming previous LLM-based baselines like KB-Binder (69.81%). On WebQSP, the ICSU (SPARQL) strategy proved particularly effective, reaching a score of 72.36, proving the method is robust even when data is scarce.
Key Insights
- Structural Similarity Matters: The "Anonymized" and "SPARQL" retrieval strategies consistently outperformed "Raw" retrieval. This indicates that for schema understanding, the LLM needs to see how relationships (like "shorter than" or "instance of") are mapped, rather than focusing on specific entities.
- Real-time Learning: Tests on the KQA Pro dataset confirmed that the LLM was genuinely learning the new schema from the provided context rather than relying on pre-existing knowledge from its training data.
- Model Sensitivity: While larger models like GPT-3.5 benefited from the diversity of the Hybrid approach, smaller models (e.g., LLaMA-7B) were more sensitive to "noise" and actually performed better with the more focused SPARQL-only retrieval.
Conclusion
ICSU provides a streamlined, effective approach to KBQA by enabling LLMs to understand complex schemas through in-context learning. While the current method assumes successful entity linking, it demonstrates that providing the right structural context can bridge the gap between natural language and formal database schemas without the need for complex external binding modules. Future work will look into integrating entity linking directly into the in-context learning flow.
Summary updated