laterabhi commited on
Commit
ab92c58
·
verified ·
1 Parent(s): 60dfa24

Remove build artifact uploaded by mistake (gitignored *.egg-info/)

Browse files
sql_optim_env.egg-info/PKG-INFO DELETED
@@ -1,466 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sql-optim-env
3
- Version: 2.0.0
4
- Summary: OpenEnv-compliant RL environment for AI SQL query optimization agents.
5
- License: MIT
6
- Keywords: openenv,sql,database,optimization,rl,reinforcement-learning,llm-agent
7
- Requires-Python: >=3.10
8
- Description-Content-Type: text/markdown
9
- License-File: LICENSE
10
- Requires-Dist: fastapi==0.115.0
11
- Requires-Dist: uvicorn[standard]==0.30.6
12
- Requires-Dist: pydantic==2.8.2
13
- Requires-Dist: openai>=1.0.0
14
- Requires-Dist: pyyaml==6.0.2
15
- Requires-Dist: requests==2.32.3
16
- Requires-Dist: openenv-core>=0.2.0
17
- Provides-Extra: dev
18
- Requires-Dist: pytest; extra == "dev"
19
- Requires-Dist: httpx; extra == "dev"
20
- Dynamic: license-file
21
-
22
- ---
23
- title: SQL Query Optimization Env
24
- emoji: 🗄️
25
- colorFrom: indigo
26
- colorTo: blue
27
- sdk: docker
28
- app_file: server/app.py
29
- pinned: false
30
- tags:
31
- - openenv
32
- - sql
33
- - world-modeling
34
- - llm-training
35
- - duckdb
36
- - reinforcement-learning
37
- ---
38
-
39
- <div align="center">
40
-
41
- # 🗄️ SQL Query Optimization Environment
42
-
43
- ### *Teaching LLMs to write fast SQL — grounded by a real database engine*
44
-
45
- [![OpenEnv](https://img.shields.io/badge/OpenEnv-compliant-brightgreen)](https://github.com/open-env)
46
- [![DeepWiki](https://img.shields.io/badge/DeepWiki-Docs-3b82f6)](https://deepwiki.com/OfficialAbhinavSingh/SQL-Query-Optimization-Environment/4-reward-and-grading-system)
47
- [![HF Space](https://img.shields.io/badge/🤗%20HuggingFace-Space-orange)](https://huggingface.co/spaces/laterabhi/grpo-sql-optimizer)
48
- [![HF Model](https://img.shields.io/badge/🤗%20HuggingFace-Model-blue)](https://huggingface.co/laterabhi/grpo-sql-optimizer)
49
- [![Theme](https://img.shields.io/badge/Theme-World%20Modeling%20%233.1-blueviolet)](#theme)
50
- [![DuckDB](https://img.shields.io/badge/Engine-DuckDB%20real%20execution-yellow)](https://duckdb.org)
51
- [![Training](https://img.shields.io/badge/Training-GRPO%20%7C%20Kaggle-red)](https://www.kaggle.com/code/officialabhinavsingh/train-kaggle)
52
- [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
53
-
54
- **Meta PyTorch OpenEnv Hackathon × Scaler School of Technology — Grand Finale 2026**
55
-
56
- *Team: Abhinav Singh · Pranjay Srivastava · Ujjwal Prakash — Scaler School of Technology, Bangalore*
57
-
58
- </div>
59
-
60
- ---
61
-
62
- ## Documentation map
63
-
64
- | Doc | Purpose |
65
- |-----|---------|
66
- | [WHERE_TO_LOOK.md](WHERE_TO_LOOK.md) | Short file index for reviewers |
67
- | [docs/design.md](docs/design.md) | Reward design, limitations, anti-gaming |
68
- | [docs/results.md](docs/results.md) | Frozen baselines and how to reproduce |
69
- | [docs/training.md](docs/training.md) | GRPO / `train.py` hyperparameters |
70
- | [train_colab.ipynb](train_colab.ipynb) | One-click Colab rerun for judges |
71
- | [scripts/ablation.py](scripts/ablation.py) | Reward-component ablation (`--quick` for CI) |
72
- | [scripts/export_replay.py](scripts/export_replay.py) | Regenerate offline `runs/demo_fallback/replay.html` |
73
-
74
- **30-second judge path:** Open the [Hugging Face Space](https://huggingface.co/spaces/laterabhi/grpo-sql-optimizer) → call **GET /** then **POST /execute** with the sample body in the API Reference section → open [`runs/demo_fallback/replay.html`](runs/demo_fallback/replay.html) in a browser (offline step scrubber over five deterministic steps; regenerate with `python scripts/export_replay.py`).
75
-
76
- ---
77
-
78
- ## 📌 About This Project
79
-
80
- SQL is the universal language of data — used by millions of engineers, analysts, and data scientists every day. Yet **LLMs consistently write SQL that is syntactically correct but computationally catastrophic at scale**. A query that returns results in milliseconds on a 1,000-row test table can bring a production system to its knees when faced with 500,000 orders or 1 million events.
81
-
82
- This project is **orthogonal to multi-agent governance / SOC-style environments**: here the **database engine** is the ground-truth critic for SQL—execution timing and result parity—not a second LLM overseer.
83
-
84
- The root cause? **LLMs have never been trained with feedback from a real database.** They've learned SQL from textbooks and Stack Overflow posts — not from watching their queries time out, studying execution plans, or experiencing the 50x slowdown of a correlated subquery on real data.
85
-
86
- **SQL Query Optimization Environment** is a reinforcement learning training environment that changes this. Every query an agent submits is **actually executed** against a live DuckDB instance. The reward signal comes directly from the database engine — real timing numbers, real result sets, real anti-pattern detection. An agent trained here doesn't just know that `JOIN` is "better than" a correlated subquery; it has *felt* the 14x speedup difference and learned to seek it.
87
-
88
- ### What makes this unique:
89
-
90
- | | Typical SQL Training | **This Environment** |
91
- |---|---|---|
92
- | **Feedback Source** | Keyword matching / syntax check | ✅ Real DuckDB execution |
93
- | **Reward Signal** | Pattern match (gameable) | ✅ Timing ratio + result equality |
94
- | **Agent Sees** | SQL text | ✅ Actual ms timings + execution plans |
95
- | **Anti-Gaming** | None — keyword stuffing works | ✅ Wrong SQL = penalized regardless |
96
- | **Scale** | Small toy data | ✅ 10k users, 500k orders, 1M events |
97
- | **Learning Loop** | Single shot | ✅ Multi-step iterative refinement |
98
-
99
- This is not a benchmark. It is a **training environment** — a closed-loop feedback system where an LLM can learn the craft of query optimization the same way a senior DBA does: by running queries, watching the numbers, and iterating.
100
-
101
- ---
102
-
103
- ## 🎯 The Problem: LLMs Can't Write Optimal SQL
104
-
105
- LLMs write *syntactically correct* SQL. They don't write *fast* SQL.
106
-
107
- Why? Because they've never received feedback from a real database. They've never seen a query plan. They've never watched their query time out on 500k rows while a rewritten version returns in 12ms.
108
-
109
- **Most training environments for SQL tasks use keyword matching.** If the model says "JOIN" instead of a subquery, it gets a reward — even if the rewritten query is slower or wrong.
110
-
111
- This environment fixes that. Every optimized query the agent submits is **actually executed** against a real DuckDB database. The reward comes from the database engine itself.
112
-
113
- ---
114
-
115
- ## 💡 The Core Innovation: Execution-Grounded Reward
116
-
117
- ```
118
- Agent submits optimized SQL
119
- ↓
120
- DuckDB executes both original AND optimized query
121
- ↓
122
- Real timing measured: original_ms / optimized_ms = speedup ratio
123
- ↓
124
- Result sets compared: are the outputs identical?
125
- ↓
126
- Reward = f(speedup, correctness, issue_detection, analysis_quality)
127
- ```
128
-
129
- **This reward signal cannot be gamed.** An agent that writes fast-but-wrong SQL gets penalized. An agent that writes correct-but-slow SQL gets partial credit but is pushed to improve. Only genuine optimization earns maximum reward.
130
-
131
- ---
132
-
133
- ## 🏗️ Environment Architecture
134
-
135
- ```
136
- ┌─────────────────────────────────────────────────────────┐
137
- │ LLM Agent │
138
- │ Input: bad SQL + schema + execution feedback │
139
- │ Output: optimized SQL + suggestions + analysis │
140
- └────────────────────┬────────────────────────────────────┘
141
- │ POST /step (Action)
142
- ▼
143
- ┌─────────────────────────────────────────────────────────┐
144
- │ SQLOptimEnv (FastAPI) │
145
- │ • Validates action structure │
146
- │ • Dispatches to grader │
147
- │ • Accumulates issues_found_so_far │
148
- │ • Returns Observation with last_execution feedback │
149
- └────────────────────┬────────────────────────────────────┘
150
- │ compare(original, optimized)
151
- ▼
152
- ┌─────────────────────────────────────────────────────────┐
153
- │ QueryExecutor (DuckDB) │
154
- │ Tables: users(10k) · orders(500k) · events(1M) │
155
- │ • Runs each query 3× → median timing │
156
- │ • Checks result-set equality (sorted row comparison) │
157
- │ • Returns: speedup, results_match, verdict │
158
- └────────────────────┬────────────────────────────────────┘
159
- │ Reward signal
160
- ▼
161
- ┌─────────────────────────────────────────────────────────┐
162
- │ Grader (Reward Function) │
163
- │ Real Speedup 35% — DuckDB timing ratio │
164
- │ Result Correctness 20% — identical data? │
165
- │ Issue Detection 25% — keyword vs ground truth │
166
- │ Approval 8% — correct flag? │
167
- │ Summary Quality 7% — analysis depth │
168
- │ Severity Labels 5% — structured tagging │
169
- └─────────────────────────────────────────────────────────┘
170
- ```
171
-
172
- ---
173
-
174
- ## 📦 Environment at a Glance
175
-
176
- | Property | Value |
177
- |---|---|
178
- | **Theme** | World Modeling — Professional Tasks (Theme #3.1) |
179
- | **SQL Engine** | DuckDB in-memory (real execution, not simulation) |
180
- | **Database Size** | users(10k) · orders(500k) · products(1k) · events(1M) |
181
- | **Tasks** | 5 tasks: easy → medium → medium-hard → hard → expert |
182
- | **Reward Range** | Float 0.0–1.0 (execution-grounded, cannot be gamed) |
183
- | **Multi-step** | Agent refines its query using real DuckDB feedback each step |
184
- | **Anti-gaming** | Wrong results and regressions are penalized numerically |
185
-
186
- ---
187
-
188
- ## 🧠 Observation Space
189
-
190
- ```json
191
- {
192
- "task_id": "task_2_correlated_subqueries",
193
- "task_name": "N+1 Correlated Subquery Elimination",
194
- "task_description": "The query uses 3 correlated subqueries...",
195
- "sql_query": "SELECT u.email, (SELECT COUNT(*) FROM orders o WHERE o.customer_id = u.id ...",
196
- "schema_info": "Table: orders (500,000 rows)\n id INT, customer_id INT ...",
197
- "difficulty": "medium",
198
- "step_count": 1,
199
- "max_steps": 4,
200
- "issues_found_so_far": ["correlated_subquery_count"],
201
- "last_execution": {
202
- "original_ms": 1847.3,
203
- "optimized_ms": 94.2,
204
- "speedup": 19.61,
205
- "results_match": true,
206
- "verdict": "✅ 19.6x faster with correct results"
207
- }
208
- }
209
- ```
210
-
211
- The `last_execution` field is the key differentiator: the agent sees **real performance numbers** from DuckDB and can refine its query in the next step — creating a genuine iterative optimization loop.
212
-
213
- ---
214
-
215
- ## ⚡ Action Space
216
-
217
- ```json
218
- {
219
- "suggestions": [
220
- {
221
- "issue_type": "correlated_subquery",
222
- "line": 4,
223
- "description": "Scans 500k orders for each of 3,300 premium users — N+1 pattern",
224
- "severity": "critical",
225
- "fix": "Rewrite as LEFT JOIN with GROUP BY aggregation"
226
- }
227
- ],
228
- "optimized_query": "WITH order_stats AS (SELECT customer_id, COUNT(*) ...) SELECT ...",
229
- "summary": "Three correlated subqueries cause ~5B row reads. A single CTE with GROUP BY reduces this to one 500k-row scan.",
230
- "estimated_improvement": "15-20x faster — eliminates N+1 subquery pattern",
231
- "approved": false
232
- }
233
- ```
234
-
235
- ---
236
-
237
- ## 📋 Five Tasks (Easy → Expert)
238
-
239
- | # | Task | Difficulty | Key Anti-Pattern | Expected Speedup |
240
- |---|---|---|---|---|
241
- | 1 | Basic Anti-pattern Detection | **Easy** | SELECT *, CAST on filter, YEAR() function | 3–5x |
242
- | 2 | N+1 Correlated Subquery Elimination | **Medium** | 3 correlated subqueries → single JOIN | 10–25x |
243
- | 3 | Wildcard LIKE & Projection | **Medium-Hard** | `LIKE '%purchase%'` on 1M rows | 4–10x |
244
- | 4 | Implicit Cross Join & Scalar Subqueries | **Hard** | Comma-syntax join + 2 global aggregates | 8–20x |
245
- | 5 | Window Function Full-Scan Audit | **Expert** | 5 OVER() on unfiltered 1M-row table | 5–15x |
246
-
247
- ---
248
-
249
- ## 🏆 Reward Function
250
-
251
- | Component | Weight | How It's Measured |
252
- |---|---|---|
253
- | 🏎️ **Real Execution Speedup** | **35%** | `original_ms / optimized_ms` via DuckDB timing |
254
- | ✅ **Result Correctness** | **20%** | Sorted row-set equality — wrong results penalized |
255
- | 🔍 **Issue Detection** | **25%** | Keyword match vs ground-truth anti-patterns |
256
- | ✅ **Approval Correctness** | **8%** | Boolean flag must match expected value |
257
- | 📝 **Summary Quality** | **7%** | Analysis length & depth scoring |
258
- | 🏷️ **Severity Labels** | **5%** | Structured severity values present |
259
-
260
- **Why this reward can't be gamed:**
261
- - Fast but wrong SQL: `correctness_score = 0` (20% penalty)
262
- - Slow but correct SQL: low speedup score, agent is pushed to improve
263
- - Keyword stuffing without real SQL: `speedup = 1.0`, `results_match = false`
264
-
265
- ---
266
-
267
- ## 📊 Results & Benchmarks
268
-
269
- ### Policy 1: Deterministic Fallback (No LLM Required)
270
-
271
- Hand-crafted rule-based policy. Reproducible with no API key. Run: `python baseline_runner.py`
272
-
273
- | Task | Difficulty | Score | Speedup | Correct? |
274
- |---|---|---|---|---|
275
- | Basic Anti-patterns | Easy | **0.8300** | 3.77x | ✅ YES |
276
- | N+1 Subqueries | Medium | **0.6900** | 0.98x | ✅ YES |
277
- | Wildcard LIKE | Medium-Hard | **0.6900** | 1.01x | ✅ YES |
278
- | Implicit Cross Join | Hard | **0.6500** | 0.85x | ✅ YES |
279
- | Window Functions | Expert | **0.7500** | 1.92x | ✅ YES |
280
- | **Average** | | **0.7220** | **1.71x** | **5/5** |
281
-
282
- ### Policy 2: LLM Agent (Qwen2.5-72B-Instruct via HF Router)
283
-
284
- Multi-step LLM agent with execution feedback loop. Run: `HF_TOKEN=hf_xxx python baseline_runner.py`
285
-
286
- | Task | Difficulty | Score | Speedup | Correct? | Δ vs Fallback |
287
- |---|---|---|---|---|---|
288
- | Basic Anti-patterns | Easy | **0.8200** | 4.80x | ✅ YES | -0.0100 |
289
- | N+1 Subqueries | Medium | **0.8100** | 14.20x | ✅ YES | +0.1200 |
290
- | Wildcard LIKE | Medium-Hard | **0.7800** | 6.90x | ✅ YES | +0.0900 |
291
- | Implicit Cross Join | Hard | **0.7200** | 9.40x | ✅ YES | +0.0700 |
292
- | Window Functions | Expert | **0.6900** | 7.60x | ✅ YES | -0.0600 |
293
- | **Average** | | **0.7640** | **8.58x** | **5/5** | **+0.0420** |
294
-
295
- **Key observations:**
296
- - LLM scores **5.8% higher** than fallback on average (0.764 vs 0.722)
297
- - LLM achieves **401% better speedup** on average (8.6x vs 1.7x) — the core differentiator
298
- - Both policies achieve correct results on all 5 tasks
299
- - The environment's execution-grounded reward captures the gap between "identifies the problem" and "produces a query with meaningful real speedup"
300
-
301
- ### 📈 Visual Performance Comparison
302
-
303
- ![Policy Comparison — Reward Scores](results/policy_comparison_chart.png)
304
- *Grouped bar chart: Reward scores for Deterministic Fallback vs LLM Agent across all 5 tasks.*
305
-
306
- ![Real DuckDB Execution Speedup](results/speedup_chart.png)
307
- *The LLM Agent achieves up to **14.2×** speedup on N+1 Correlated Subqueries — tasks where pattern-matching fallback completely fails (0.98×).*
308
-
309
- ---
310
-
311
- ## 🤖 GRPO Fine-Tuning Results
312
-
313
- Fine-tuned `Qwen/Qwen2.5-0.5B-Instruct` using GRPO on this environment. Published model: [laterabhi/grpo-sql-optimizer](https://huggingface.co/laterabhi/grpo-sql-optimizer)
314
-
315
- | Metric | Value |
316
- |---|---|
317
- | Start avg (ep 1–10) | 0.3090 |
318
- | End avg (ep 91–100) | 0.5962 |
319
- | **Improvement** | **+93%** |
320
-
321
- | Task | Difficulty | Score |
322
- |---|---|---|
323
- | task_1_basic_antipatterns | easy | **0.7500** ✅ |
324
- | task_2_correlated_subqueries | medium | **0.8313** ✅ |
325
- | task_3_wildcard_scan | medium-hard | **0.6563** ✅ |
326
- | task_4_implicit_join | hard | **0.6563** ✅ |
327
- | task_5_window_functions | expert | **0.6500** ✅ |
328
-
329
- **Why task 5 should not show a “warning” or error icon:** `task_5_window_functions` is the **expert** scenario (five window passes over 1M rows). It is normal for its post-training score to sit at the **low end** of the table (~0.62–0.70 depending on eval seed and checkpoint). That is still **strong fine-tuning**, not a broken run. If your Hugging Face Space or model card renders a yellow warning for the lowest row, remove that heuristic or replace it with the same ✅ as the other tasks whenever the score is **≥ ~0.60**.
330
-
331
- **Hugging Face “Video preview” / “Preview not found”:** The Hub does not auto-generate demo videos. That slot stays empty until you add one. Optional fixes: (1) ignore it, (2) in the model or Space **Settings**, add a **YouTube** or **MP4** link / upload a short screen recording, or (3) add a **thumbnail** image in the README frontmatter / model card. None of this affects weights or the OpenEnv API.
332
-
333
- ### 📈 Training Reward Curve
334
-
335
- ![GRPO Training Reward Curve](results/grpo_reward_curve.png)
336
- *Clear learning signal: model converged from random policy (0.309) to 0.596 by episode 100 — surpassing 93% of the gap to the deterministic baseline. The execution-grounded reward prevents reward hacking throughout training.*
337
-
338
- ---
339
-
340
- ## 🧪 Why GRPO?
341
-
342
- We train using **Group Relative Policy Optimization (GRPO)** — the same algorithm used by DeepSeek-R1. The model generates G candidate SQL rewrites per prompt, the environment scores each against DuckDB, and the policy is updated to prefer higher-reward completions.
343
-
344
- ### Why GRPO?
345
- GRPO is ideal for this environment because:
346
- - **No reference dataset needed** — the DuckDB engine is the ground truth
347
- - **Dense reward signal** — partial credit across 6 components guides learning
348
- - **Anti-gaming built-in** — the relative advantage normalisation means the model must genuinely improve, not just score higher than a weak baseline
349
-
350
- ### Training Script
351
- ```bash
352
- # Install dependencies
353
- pip install trl transformers torch duckdb matplotlib
354
-
355
- # Run GRPO training (200 episodes, group size 4)
356
- python train.py
357
-
358
- # Or use HF TRL's GRPOTrainer directly (KL-penalised)
359
- python train.py --use-trl
360
- ```
361
-
362
- See [`train.py`](train.py) for the full implementation.
363
-
364
- ### Training Notebook (Kaggle)
365
- [![Open In Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://www.kaggle.com/code/officialabhinavsingh/train-kaggle)
366
-
367
- Full 100-episode GRPO training run on a Kaggle P100 GPU. Generates reward curves and before/after evaluation automatically.
368
- Produced the model at [laterabhi/grpo-sql-optimizer](https://huggingface.co/laterabhi/grpo-sql-optimizer) — **+93% improvement** (start avg 0.309 → end avg 0.596).
369
-
370
- ---
371
-
372
- ## 🔌 API Reference
373
-
374
- | Endpoint | Method | Description |
375
- |---|---|---|
376
- | `/` | GET | Health check + table stats |
377
- | `/reset` | POST | Start episode `{"task_id": "task_1_basic_antipatterns"}` |
378
- | `/step` | POST | Submit action → real DuckDB execution |
379
- | `/state` | GET | Current episode state |
380
- | `/tasks` | GET | All 5 tasks with full schema |
381
- | `/grader` | POST | Grade action without advancing episode |
382
- | **`/execute`** | POST | **Run your SQL against DuckDB → get real timing + verdict** |
383
- | **`/leaderboard`** | GET | **Real-time best scores & speedups per task** |
384
-
385
- ### Try it live:
386
- ```bash
387
- # Test the /execute endpoint directly
388
- curl -X POST https://laterabhi-grpo-sql-optimizer.hf.space/execute \
389
- -H "Content-Type: application/json" \
390
- -d '{
391
- "task_id": "task_1_basic_antipatterns",
392
- "optimized_query": "SELECT id, customer_id, status, total FROM orders WHERE customer_id = 5000 AND created_at >= DATE '\''2024-01-01'\'' AND created_at < DATE '\''2025-01-01'\''"
393
- }'
394
- ```
395
-
396
- ### Full Episode Example:
397
- ```bash
398
- # 1. Start an episode
399
- curl -X POST https://laterabhi-grpo-sql-optimizer.hf.space/reset \
400
- -H "Content-Type: application/json" \
401
- -d '{"task_id": "task_2_correlated_subqueries"}'
402
-
403
- # 2. Submit your optimized SQL
404
- curl -X POST https://laterabhi-grpo-sql-optimizer.hf.space/step \
405
- -H "Content-Type: application/json" \
406
- -d '{"suggestions": [...], "optimized_query": "WITH ...", "summary": "...", "approved": false}'
407
-
408
- # 3. See your real speedup in the response
409
- ```
410
-
411
- ---
412
-
413
- ## 🚀 Local Setup
414
-
415
- ```bash
416
- git clone https://github.com/OfficialAbhinavSingh/SQL-Query-Optimization-Environment
417
- cd SQL-Query-Optimization-Environment
418
-
419
- pip install -r requirements.txt
420
-
421
- # Start the API server
422
- uvicorn server.app:app --host 0.0.0.0 --port 7860
423
-
424
- # In a separate terminal — run baseline comparison
425
- python baseline_runner.py
426
-
427
- # Run inference with an LLM
428
- export HF_TOKEN=hf_your_token_here
429
- export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
430
- python inference.py
431
- ```
432
-
433
- ---
434
-
435
- ## 🐳 Docker
436
-
437
- ```bash
438
- docker build -t sql-optim-env .
439
- docker run -p 7860:7860 sql-optim-env
440
- ```
441
-
442
- ---
443
-
444
- ## 🔗 Links
445
-
446
- | Resource | Link |
447
- |---|---|
448
- | 🤗 HuggingFace Space (live API + demo) | https://huggingface.co/spaces/laterabhi/grpo-sql-optimizer |
449
- | 🤗 Trained Model (GRPO fine-tuned Qwen2.5) | https://huggingface.co/laterabhi/grpo-sql-optimizer |
450
- | 📓 Training Notebook (Kaggle) | https://www.kaggle.com/code/officialabhinavsingh/train-kaggle |
451
- | 📊 Baseline Results | [`results/baseline_results.json`](results/baseline_results.json) |
452
- | ⚙️ OpenEnv Manifest | [`openenv.yaml`](openenv.yaml) |
453
- | 🐍 Training Script | [`train.py`](train.py) |
454
-
455
- ---
456
-
457
- ## ❓ Why This Matters
458
-
459
- SQL is the language of data. Every analyst, data scientist, and backend engineer writes SQL. But LLMs consistently produce queries that work correctly on small test data and time out in production. The cost is real: slow queries mean slow dashboards, slow APIs, and real money spent on compute.
460
-
461
- An LLM trained on this environment has received feedback from a real database engine. It has learned not just that JOINs are "better than" correlated subqueries, but *how much* better, and *when* the rewrite matters. That's a capability that doesn't exist yet — and this environment is designed to create it.
462
-
463
- ---
464
-
465
- *Built with ❤️ for the Meta PyTorch OpenEnv Hackathon Grand Finale — Scaler School of Technology, Bangalore, April 2026*
466
- *Team: Abhinav Singh · Pranjay Srivastava · Ujjwal Prakash*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sql_optim_env.egg-info/SOURCES.txt DELETED
@@ -1,15 +0,0 @@
1
- LICENSE
2
- README.md
3
- pyproject.toml
4
- scripts/ablation.py
5
- scripts/export_replay.py
6
- server/__init__.py
7
- server/app.py
8
- sql_optim_env.egg-info/PKG-INFO
9
- sql_optim_env.egg-info/SOURCES.txt
10
- sql_optim_env.egg-info/dependency_links.txt
11
- sql_optim_env.egg-info/entry_points.txt
12
- sql_optim_env.egg-info/requires.txt
13
- sql_optim_env.egg-info/top_level.txt
14
- tests/test_smoke.py
15
- training/eval_before_after.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sql_optim_env.egg-info/dependency_links.txt DELETED
@@ -1 +0,0 @@
1
-
 
 
sql_optim_env.egg-info/entry_points.txt DELETED
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- server = server.app:main
 
 
 
sql_optim_env.egg-info/requires.txt DELETED
@@ -1,11 +0,0 @@
1
- fastapi==0.115.0
2
- uvicorn[standard]==0.30.6
3
- pydantic==2.8.2
4
- openai>=1.0.0
5
- pyyaml==6.0.2
6
- requests==2.32.3
7
- openenv-core>=0.2.0
8
-
9
- [dev]
10
- pytest
11
- httpx
 
 
 
 
 
 
 
 
 
 
 
 
sql_optim_env.egg-info/top_level.txt DELETED
@@ -1,8 +0,0 @@
1
- dist
2
- docs
3
- results
4
- runs
5
- scripts
6
- server
7
- tests
8
- training