This repository contains the official implementation of Smart SPARQL Advisor, as presented in our PVLDB 2025 paper:
"Smart SPARQL Advisor: Guiding Users in Query Formulation with Performance Prediction"
The system integrates learned Query Performance Prediction (QPP) with large language model (LLM)–based query reformulation to assist users in crafting performant SPARQL queries over Knowledge Graphs.
Writing SPARQL queries is often an iterative and time-consuming process, especially by long-running query executions that may result in timeouts.
Smart SPARQL Advisor (SSA) addresses this challenge by:
- Predicting query runtimes prior to execution using a learned QPP model (PlanRGCN)
- Recommending runtime-efficient alternative queries via an LLM guided by learned query embeddings
SSA/
├── PlanRGCN/ # PlanRGCN model for SPARQL Query Performance Prediction
│ ├── data/ # Training datasets and query collections
│ ├── PlanRGCN/ # Core PlanRGCN implementation
│ ├── scripts/ # Utility scripts
│ └── README.md # PlanRGCN-specific documentation
├── qpp_llm_frontend/ # Web application for Smart SPARQL Advisor
│ ├── backend/ # Python Flask backend
│ │ ├── app.py # Main Flask application
│ │ ├── qpp_model_api.py # QPP model API service
│ │ ├── ollama_client.py # Ollama LLM client
│ │ └── streaming_utils.py # Streaming response utilities
│ ├── src/ # React frontend source code
│ │ └── components/ # React components
│ └── package.json # Node.js dependencies
├── q_recom/ # Query recommendation system
│ └── prompt_gen.py # Prompt templates for LLM-based reformulation
├── dockerfiles/ # Docker configurations
└── requirements.txt # Python dependencies
- Python 3.10+
- Node.js 16+ (for frontend)
- Ollama (for local LLM serving)
- A SPARQL endpoint (e.g., Virtuoso, Blazegraph)
- Trained PlanRGCN model and KG statistics
-
Clone the repository:
git clone git@github.com:dkw-aau/SSA.git cd SSA -
Install Python dependencies:
pip install -r requirements.txt
-
Install Node.js dependencies:
cd qpp_llm_frontend npm install cd ..
-
Install and setup Ollama:
# Install Ollama curl -fsSL https://ollama.com/install.sh | sh # Pull required LLM models ollama pull llama3:8b ollama pull phi3:mini ollama pull qwen2.5:7b
To run the Smart SPARQL Advisor system, you need to start three components in the following order:
-
Start Ollama server:
ollama serve
-
Start the main Flask backend:
python3 qpp_llm_frontend/backend/app.py
-
Start the QPP model API:
python qpp_llm_frontend/backend/qpp_model_api.py
The web interface will be available at http://localhost:3000
Alternatively, you can use Docker to build and run the system:
docker build -t ssa:default -f dockerfiles/Dockerfile_nodejs .
# Add docker run commands as needed- SPARQL Endpoint: Configure your SPARQL endpoint URL in the web interface
- LLM Models: Available models are automatically detected from your Ollama installation
- QPP Model: Ensure the trained PlanRGCN model is available (see
PlanRGCN/README.md)
- Open the web interface at
http://localhost:3000 - Enter your SPARQL endpoint URL
- Select similarity function and LLM model
- Input your SPARQL query
- Click "Evaluate Query" to get:
- Runtime prediction
- Alternative query formulations (if needed)
- Query execution results
@article{mohanaraj2025ssa,
title = {Smart SPARQL Advisor: Guiding Users in Query Formulation with Performance Prediction},
author = {Abiram Mohanaraj and Matteo Lissandrini and Katja Hose},
journal = {PVLDB},
volume = {X},
number = {X},
year = {2025}
}