An AI-powered SQL autocompletion assistant that helps developers write complex SQL queries faster and more efficiently using intelligent, context-aware suggestions.
Query-Pilot is a desktop application that acts as your SQL copilot, providing real-time autocompletion suggestions while you work in MySQL Workbench or pgAdmin 4. By combining Retrieval-Augmented Generation (RAG) with Large Language Models and your actual database schema, it delivers accurate and contextually relevant SQL completions.
- Intelligent SQL Autocompletion: Real-time suggestion generation based on partial queries using advanced RAG architecture
- Database Schema Integration: Automatically extracts and incorporates your database schema with sample data for accurate suggestions
- Multi-Database Support: Works with both MySQL and PostgreSQL databases
- Flexible Vector Store Options: Choose between FAISS (local), Pinecone (cloud), or ChromaDB (persistent local)
- Session Memory: Remembers recent queries within your session for better context awareness
- Non-Intrusive Interface: Displays suggestions as SQL comments that you can accept or dismiss
- Comprehensive Logging: Tracks all interactions, acceptance rates, and performance metrics
- MLflow Integration: Monitors model performance and tracks key metrics over time
- Keyboard-Driven Workflow: Efficient hotkey-based interaction
Query-Pilot follows a modular architecture with the following workflow:
- Trigger: User presses
Ctrl+Cto capture SQL text from clipboard - Context Retrieval: Searches vector store for similar SQL query examples
- Schema Extraction: Fetches current database schema with sample data
- LLM Generation: Sends combined context to Llama model via Groq API
- Suggestion Display: Shows completion as a SQL comment
- User Action: Accept with
Tabor dismiss with any other key - Logging: Records interaction details for analysis and improvement
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ User │──────│ Clipboard │──────│ Vector │
│ Trigger │ │ Capture │ │ Store │
└─────────────┘ └──────────────┘ └─────────────┘
│ │
│ │
▼ ▼
┌─────────────────────────────────┐
│ Context Aggregation │
│ (Query + Schema + Examples) │
└─────────────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ LLM (Groq/Llama 3.3) │
└─────────────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ Ghost Text Suggestion │
└─────────────────────────────────┘
│
┌──────────┴──────────┐
▼ ▼
┌────────────┐ ┌───────────┐
│ Accept │ │ Dismiss │
│ (Tab) │ │ (Any Key) │
└────────────┘ └───────────┘
│ │
└──────────┬──────────┘
▼
┌─────────────────────┐
│ MLflow Logging │
└─────────────────────┘
- Python 3.11 or higher
- MySQL Workbench or pgAdmin 4
- MySQL or PostgreSQL database (for schema extraction)
- Groq API key (for LLM access)
- Pinecone API key (optional, only if using Pinecone vector store)
git clone https://github.com/yourusername/Query-Pilot.git
cd Query-Pilotpython -m venv venv
# On Windows
venv\Scripts\activate
# On Linux/Mac
source venv/bin/activatepip install -r requirements.txtCopy the example environment file and configure it:
cp .env.example .envEdit .env file with your credentials:
GROQ_API_KEY=your_groq_api_key_here
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
PINECONE_API_KEY=your_pinecone_api_key_here # Optional, only for PineconeCopy the example database config and configure it:
cp db_config.yaml.example db_config.yamlThe db_config.yaml file uses environment variables for sensitive data:
db:
type: mysql # or postgres
user: root
password: ${DB_PASSWORD} # Reads from .env
host: localhost
port: 3306 # 5432 for PostgreSQL
name: ${DB_NAME} # Reads from .env
sample_rows: 2Note: The actual db_config.yaml file is gitignored for security. Always use the template file as a reference.
# Download SQL dataset from HuggingFace
python src/loading_data.py --config params.yaml
# Build vector store index
python src/build_vector_stores.py --config params.yamlThe main configuration file is params.yaml. Key sections include:
Choose your preferred vector store by setting vector_store.type:
vector_store:
type: faiss # Options: faiss, pinecone, chromadb
top_k: 5 # Number of similar examples to retrieveFAISS (recommended for local development):
vector_store:
type: faiss
path_to_save: data/processed/sql_faiss_index.index
metadata_path: data/processed/sql_metadata.pklPinecone (for cloud-based scalability):
vector_store:
type: pinecone
index_name: sql-index
dimension: 384
namespace: default
metric: cosineChromaDB (for persistent local storage):
vector_store:
type: chromadb
persist_directory: data/processed/chroma
collection_name_chroma: sql_collectionllm:
model_name: llama-3.3-70b-versatile # Groq modelmemory:
enable: true
limit: 3 # Remember last 3 queries in sessiontriggers:
initiater: ctrl+c # Trigger suggestion
filler: tab # Accept suggestion
quiting: esc # Quit application
remove_ghost:
c: ctrl
key: z # Remove ghost textpython src/sql_mcp.py --config params.yaml- Open MySQL Workbench or pgAdmin 4
- Write a partial SQL query:
SELECT * FROM users WHERE
- Press
Ctrl+Cto trigger autocompletion - Review the suggestion (appears as SQL comment):
SELECT * FROM users WHERE /* suggestion: email LIKE '%@example.com' ORDER BY created_at DESC */
- Accept or dismiss:
- Press
Tabto accept and insert the suggestion - Press any other key to dismiss
- Press
- Clear session memory (if needed): Press
Ctrl+Shift+C - Exit the application: Press
Esc
python test_schema.pyThis will verify your database configuration and display the extracted schema.
# Build and run
docker-compose up --build
# Run in detached mode
docker-compose up -d
# Stop
docker-compose downQuery-Pilot/
├── src/ # Source code
│ ├── sql_mcp.py # Main entry point - keyboard listener & orchestrator
│ ├── llm.py # LLM integration (Groq/Llama)
│ ├── retrieve_context.py # Vector store retrieval logic
│ ├── build_vector_stores.py # Vector store creation and management
│ ├── db_schema_utils.py # Database schema extraction utilities
│ ├── loading_data.py # Dataset loading from HuggingFace
│ └── mlflow_config.py # MLflow experiment tracking
├── data/ # Data directory
│ ├── raw/ # Original dataset from HuggingFace
│ ├── processed/ # Vector store indexes and metadata
│ └── logs/ # Application and suggestion logs
├── params.yaml # Main configuration file
├── db_config.yaml # Database connection configuration
├── requirements.txt # Python dependencies
├── docker-compose.yaml # Docker deployment configuration
├── Makefile # Build automation commands
└── README.md # This file
- LLM: Llama 3.3 (70B) via Groq API
- Embeddings: Sentence Transformers (all-MiniLM-L6-v2)
- Vector Stores: FAISS, Pinecone, ChromaDB
- Framework: LangChain
- ORM: SQLAlchemy 2.0+
- Connectors: PyMySQL (MySQL), psycopg2 (PostgreSQL)
- Keyboard Events: keyboard library
- Automation: PyAutoGUI
- Clipboard: pyperclip
- Window Detection: pygetwindow
- Dataset: HuggingFace Datasets (gretelai/synthetic_text_to_sql)
- Manipulation: pandas
- Experiment Tracking: MLflow
- Logging: CSV-based suggestion logs
| Shortcut | Action |
|---|---|
Ctrl+C |
Trigger SQL autocompletion |
Tab |
Accept suggested completion |
Esc |
Quit the application |
Ctrl+Z |
Remove ghost text suggestion |
Ctrl+Shift+C |
Clear session memory |
Query-Pilot logs all interactions to CSV files in the data/logs/ directory:
Log Fields:
- Timestamp
- Model name
- Status (ACCEPTED/DISMISSED)
- Latency (ms)
- User query
- LLM suggestion
- Retrieved context
- Database schema
Track model performance metrics:
# Start MLflow UI
mlflow ui
# Access dashboard
# Open browser to http://127.0.0.1:5000Tracked Metrics:
- Acceptance rate
- Average latency
- Min/Max latency
- Total suggestions generated
# Run linting
make lint
# Format code
flake8 src/# Test database connection
python test_schema.py
# Test vector store retrieval
python src/retrieve_context.py --config params.yamlmake requirements # Install dependencies
make data # Download and prepare dataset
make clean # Remove compiled files and cache
make lint # Run code quality checksSolution: Run the vector store build script:
python src/build_vector_stores.py --config params.yamlSolution:
- Check credentials in
db_config.yaml - Ensure database server is running
- Verify network connectivity and port accessibility
- Test connection:
python test_schema.py
Solution:
- Verify
GROQ_API_KEYin.envfile - Check API key validity on Groq console
- Monitor rate limits and quotas
Solution:
- Ensure MySQL Workbench or pgAdmin 4 is the active window
- Check if another application is capturing the same hotkeys
- Run application with administrator/sudo privileges (for keyboard access)
- Verify
params.yamltrigger configuration
Solution:
- Check clipboard contains valid SQL text
- Verify window detection: ensure you're in MySQL Workbench or pgAdmin 4
- Check application logs in
data/logs/ - Increase
sleep_timeinparams.yamlif timing issues occur
Solution:
- Verify
PINECONE_API_KEYandPINECONE_ENVIRONMENTin.env - Ensure Pinecone index exists: check Pinecone console
- Verify index dimension matches embedding model (384 for all-MiniLM-L6-v2)
- Consider switching to FAISS for local development
- Vector Store: Use FAISS for fastest local performance, Pinecone for scalability
- Top-K Setting: Reduce
vector_store.top_kfor faster retrieval (default: 5) - Memory Limit: Adjust
memory.limitbased on query complexity needs - LLM Temperature: Currently set to 0.3 for deterministic output (configured in
llm.py)
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow PEP 8 style guidelines
- Add tests for new functionality
- Update documentation as needed
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- API Keys: Never commit
.envfile to version control - Database Credentials: Use environment variables or secure vaults for production
- SQL Injection: Review all LLM-generated SQL before execution
- Rate Limiting: Monitor Groq API usage to avoid quota exhaustion
- Currently supports only MySQL Workbench and pgAdmin 4
- Requires clipboard access for query capture
- Windows-specific paths in default configuration (update
params.yamlfor Linux/Mac) - LLM suggestions should be reviewed before execution in production environments
- Support for additional SQL clients (DBeaver, DataGrip, etc.)
- Multi-language support
- Custom fine-tuned models
- Query optimization suggestions
- Syntax error detection and fixing
- Integration with additional LLM providers
This project is based on the Cookiecutter Data Science project template.
- Dataset: gretelai/synthetic_text_to_sql
- LLM Provider: Groq API (Llama 3.3)
- Embedding Model: Sentence Transformers
For issues, questions, or feature requests, please open an issue on the GitHub repository.