[Paper Review] LLM-based SPARQL Query Generation from Natural Language over Federated Knowledge Graphs
The paper presents a Retrieval-Augmented Generation (RAG) system that translates natural language questions into federated SPARQL queries over bioinformatics knowledge graphs, using endpoint metadata and a validation step to reduce hallucinations.
We introduce a Retrieval-Augmented Generation (RAG) system for translating user questions into accurate federated SPARQL queries over bioinformatics knowledge graphs (KGs) leveraging Large Language Models (LLMs). To enhance accuracy and reduce hallucinations in query generation, our system utilises metadata from the KGs, including query examples and schema information, and incorporates a validation step to correct generated queries. The system is available online at chat.expasy.org.
Motivation & Objective
- Aim to enable accurate natural-language to SPARQL query generation over federated bioinformatics KGs (e.g., UniProt, Bgee, OMA).
- Leverage LLMs with endpoint metadata and contextual information to reduce hallucinations and improve query correctness.
- Provide a scalable, deployment-friendly solution that adapts to evolving KGs without retraining.
- Offer an accessible online demo and reusable modules for others to adopt the approach.
Proposed method
- Retrieve and index endpoint metadata (examples, VoID, shapes) to build a context-aware prompt.
- Generate embeddings for user questions and similar class labels and examples from a vector store to inform prompt construction.
- Construct prompts that combine the user question with retrieved examples and schema information for SPARQL generation.
- Validate generated federated SPARQL queries against endpoint VoID schemas to detect and correct invalid predicates or classes.
- Return corrected queries along with the supporting context and similarity information to the user.

Experimental results
Research questions
- RQ1How effectively can LLMs translate natural language questions into federated SPARQL queries using retrieval-augmented context from KG endpoints?
- RQ2Does validation against endpoint schemas improve correctness and reduce hallucinations, especially for smaller LLMs?
- RQ3What is the impact of including example queries and class shapes (ShEx derived from VoID) on query accuracy?
- RQ4How does system performance vary across different LLMs and RAG configurations?
Key findings
- Larger LLMs outperform smaller models in overall query accuracy when used with RAG.
- Query validation notably improves accuracy for smaller LLMs by correcting invalid predicates and suggesting valid alternatives.
- The RAG+validation setup achieves higher F1 scores and more successful results compared to baselines without validation.
- The system remains open-source with online demo and reusable components for deployment across other bioinformatics KGs.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.