SQL Detective is an interactive investigation game where you solve a murder mystery by querying a police database using natural language. This application showcases the power of Retrieval-Augmented Generation (RAG) techniques with local small language models and database integration.
As a detective in SQL City, you're tasked with solving a murder that occurred on January 15, 2018. The uniqueness of this application lies in its approach:
- Natural Language to SQL Translation: Ask questions in plain English
- Database Query Execution: Retrieve specific information from the police database
- Context-Aware Analysis: Get intelligent insights based on the query results
- Progressive Investigation: Follow leads from clue to clue to solve the case
- Conversational Interface: Interact with the investigation through a chat interface
- Automatic SQL Translation: No SQL knowledge required - just ask questions naturally
- Intelligent Analysis: The detective AI analyzes query results and suggests next steps
- Investigation Notes: Keep track of your findings in the detective's notebook
- Local Processing: All processing happens locally with no data sent to external APIs
- Backend Framework:
Python
- Frontend:
Streamlit
- Database:
SQLite
- LLM Platform:
Ollama
- Language Model Used:
DeepSeek-R1:1.5b
- RAG Implementation:
LangChain
for orchestration and context management
Ollama-SQLite-RAG/
β
βββ main.py # Application entry point
βββ modules/
β βββ chatbot.py # Main conversation handler
β βββ model.py # Base classes for language model interactions
β βββ settings.py # Configuration settings
β βββ tools.py # Utility functions
β βββ database/
β βββ db.py # Database connection and query handling
β βββ sql-murder-mystery.db # SQLite database file
β
βββ detective_test.py # Test script for detective model
βββ translator_test.py # Test script for translator model
- User Input: The user submits a natural language question about the case
- Translation: The Translator model converts the question to a valid SQL query
- Database Query: The system executes the SQL query against the police database
- Analysis: The Detective model analyzes the query results in the context of the question
- Response: The system presents findings and suggests next investigative steps
This application implements a complete RAG pipeline:
- Retrieval: SQL queries retrieve relevant information from the database
- Augmentation: The retrieved data augments the context for the language model
- Generation: The language model generates insights based on the augmented context
- Python 3.8+
- Ollama installed locally
DeepSeek-R1:1.5b
model downloaded to Ollama
# Clone the repository
git clone https://github.com/Ne0bliviscaris/Ollama-SQLite-RAG.git
cd Ollama-SQLite-RAG
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start Ollama in the background and install the model
ollama run deepseek-r1:1.5b
# Run the application
python main.py
- SQL Murder Mystery for the original game concept
- LangChain for the RAG framework
- Ollama for local language model support
- DeepSeek for their R1:1.5b model
- Streamlit for the interactive web interface