| title | SQL Query Optimizer |
|---|---|
| emoji | 🗄️ |
| colorFrom | blue |
| colorTo | green |
| sdk | docker |
| pinned | false |
An RL environment that trains AI agents to fix and optimize SQL queries using real SQLite execution feedback.
SQL bugs and slow queries cost companies millions daily. No existing RL environment trains agents on real SQL execution — they all use synthetic scoring.
Agent receives broken SQL query ↓ Submits fixed query via /step ↓ SQLite ACTUALLY executes it ↓ Grader scores real results (0.0–0.99) ↓ Reward = improvement over best score so far
Use live Space: curl -X POST https://alokrajkumar-sql-query-optimizer.hf.space/reset -H "Content-Type: application/json" -d '{"task_id": "task_easy"}'
Run locally: git clone https://github.com/Prince-Chakraborty/sql-query-optimizer cd sql-query-optimizer pip install -r server/requirements.txt uvicorn server.app:app --host 0.0.0.0 --port 7860
Example reward progression: Step 1: 0.10 → Step 2: 0.45 → Step 3: 0.99 Agent learned: always use explicit JOIN with ON clause This confirms a learnable, non-trivial reward signal.
5 SQL optimization tasks covering JOINs, subqueries, CTEs, aggregations, and window functions. Difficulty: easy → medium → hard.
POST /reset — Start new episode POST /step — Submit SQL query, get reward GET /state — Get episode metadata
Built with real SQL execution using SQLite instead of synthetic scoring. Applicable to enterprise query optimization, developer tooling, and SQL education at scale.
Unlike traditional SQL evaluation (string matching), this environment uses real execution-based rewards, making it suitable for training production-grade query optimization agents. This bridges the gap between academic RL environments and real-world database systems.
The environment handles partial correctness, multiple valid SQL outputs, and execution-based ambiguity — making reward design non-trivial.
Average Score: 0.99 across all 5 tasks
export API_BASE_URL=your_endpoint export API_KEY=your_key export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct export HF_SPACE_URL=https://alokrajkumar-sql-query-optimizer.hf.space python3 inference.py
OpenEnv 0.2.3 · FastAPI · SQLite · Pydantic 2.x · Docker · HuggingFace Spaces · Python 3.11
Single-session (not thread-safe). SQLite only. Fixed schema.
Multi-database support · Query execution plan analysis