Spaces:
Running
Running
Melika Kheirieh
commited on
Commit
·
cc371b0
1
Parent(s):
c9bbfcd
fix(ui): remove all mock/Spider fallbacks and route queries to real backend only
Browse files- README.md +264 -109
- benchmarks/results_pro/20251109-125509/eval.jsonl +0 -5
- benchmarks/results_pro/20251109-125509/latency_histogram.png +0 -0
- benchmarks/results_pro/20251109-125509/latency_per_stage.png +0 -0
- benchmarks/results_pro/20251109-125509/metrics_overview.png +0 -0
- benchmarks/results_pro/20251109-125509/results.csv +0 -6
- benchmarks/results_pro/20251109-125509/summary.json +0 -21
- benchmarks/results_pro/20251113-113600/eval.jsonl +20 -0
- benchmarks/results_pro/20251113-113600/latency_histogram.png +0 -0
- benchmarks/results_pro/20251113-113600/latency_per_stage.png +0 -0
- benchmarks/results_pro/20251113-113600/metrics_overview.png +0 -0
- benchmarks/results_pro/20251113-113600/results.csv +21 -0
- benchmarks/results_pro/20251113-113600/summary.json +21 -0
- demo/app.py +172 -123
README.md
CHANGED
|
@@ -6,193 +6,348 @@ colorTo: blue
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
-
# 🧩 NL2SQL Copilot
|
| 10 |
|
|
|
|
| 11 |
[](https://github.com/melika-kheirieh/nl2sql-copilot/actions/workflows/ci.yml)
|
| 12 |
[](#)
|
| 13 |
[](LICENSE)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
---
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
---
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
↓
|
| 41 |
-
[ Safety ]
|
| 42 |
-
↓
|
| 43 |
-
[ Executor ]
|
| 44 |
-
↓
|
| 45 |
-
[ Verifier ]
|
| 46 |
-
↓
|
| 47 |
-
[ Repair ]
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
| **Repair** | Self-healing loop triggered on failure |
|
| 62 |
|
| 63 |
---
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
Evaluated on the **Spider dev subset (20 samples)** using the reproducible evaluation toolkit.
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|--------|--------|
|
| 72 |
-
| EM (Exact Match) | 0.15 |
|
| 73 |
-
| SM (Structural Match) | 0.70 |
|
| 74 |
-
| ExecAcc (Execution Accuracy) | 0.73 |
|
| 75 |
-
| Avg Latency | 8.11 s |
|
| 76 |
-
| p50 Latency | 9.42 s |
|
| 77 |
-
| p95 Latency | 13.88 s |
|
| 78 |
|
| 79 |
-
|
| 80 |
-
> lower EM reflects harmless formatting differences.
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
---
|
| 95 |
|
| 96 |
-
|
|
|
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
|
| 102 |
-
|
| 103 |
|
| 104 |
-
📊
|
| 105 |
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
|
|
|
| 115 |
|
| 116 |
---
|
| 117 |
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
```bash
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
```
|
| 135 |
|
|
|
|
|
|
|
| 136 |
---
|
| 137 |
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
|
| 142 |
```bash
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
```
|
| 147 |
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
```bash
|
| 151 |
-
|
| 152 |
-
|
|
|
|
| 153 |
```
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
---
|
| 159 |
|
| 160 |
-
##
|
| 161 |
|
| 162 |
```bash
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
make test # Pytest
|
| 166 |
-
make bench # Run benchmark suite
|
| 167 |
```
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
---
|
| 176 |
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
| 180 |
-
* Provides **reproducible evaluation** for continuous model tracking
|
| 181 |
-
* Delivers **production-level resilience** via self-repair and observability
|
| 182 |
-
* Demonstrates **AI software engineering** beyond prompt design
|
| 183 |
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
|
| 187 |
|
| 188 |
-
|
| 189 |
-
AI Engineer & Researcher in Natural Language Interfaces for Databases
|
| 190 |
-
[GitHub](https://github.com/melika-kheirieh) · [LinkedIn](https://www.linkedin.com/in/melika-kheirieh-03a7b5176/)
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
---
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
MIT
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
|
|
|
| 9 |
|
| 10 |
+
# 🧩 **NL2SQL Copilot — Natural-Language → Safe SQL**
|
| 11 |
[](https://github.com/melika-kheirieh/nl2sql-copilot/actions/workflows/ci.yml)
|
| 12 |
[](#)
|
| 13 |
[](LICENSE)
|
| 14 |
|
| 15 |
+
**Modular Text-to-SQL Copilot built with FastAPI & Pydantic-AI.**
|
| 16 |
+
Generates *safe, verified, executable SQL* via a multi-stage agentic pipeline.
|
| 17 |
+
Includes: self-repair, Spider benchmarks, Prometheus metrics, and a full demo UI.
|
| 18 |
+
|
| 19 |
+
🚀 **Live Demo (Hugging Face Space):**
|
| 20 |
+
👉 *(your HF link here)*
|
| 21 |
|
| 22 |
---
|
| 23 |
|
| 24 |
+
# **1) Quick Start**
|
| 25 |
|
| 26 |
+
```bash
|
| 27 |
+
git clone https://github.com/melika-kheirieh/nl2sql-copilot
|
| 28 |
+
cd nl2sql-copilot
|
| 29 |
+
make setup # install deps
|
| 30 |
+
make run # start API + UI
|
| 31 |
+
```
|
| 32 |
|
| 33 |
+
Open:
|
| 34 |
+
👉 [http://localhost:8000](http://localhost:8000)
|
| 35 |
+
👉 [http://localhost:8000/docs](http://localhost:8000/docs) (Swagger UI)
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
+
# **2) Demo (Gradio UI)**
|
| 40 |
|
| 41 |
+
The live UI supports:
|
| 42 |
|
| 43 |
+
* Uploading a SQLite database
|
| 44 |
+
* Asking natural-language questions
|
| 45 |
+
* Viewing generated SQL
|
| 46 |
+
* Viewing execution results
|
| 47 |
+
* Full trace per pipeline stage
|
| 48 |
+
* Example queries for quick testing
|
| 49 |
+
* No need to upload a DB for the demo (ships with a small example DB)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
Everything runs through the same agentic backend as the API.
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
# **3) Architecture Overview**
|
| 56 |
|
| 57 |
+
```
|
| 58 |
+
user query
|
| 59 |
+
↓
|
| 60 |
+
detector (ambiguous? dataset missing?)
|
| 61 |
+
planner (task decomposition + schema reasoning)
|
| 62 |
+
generator (SQL generation)
|
| 63 |
+
safety (SELECT-only, no mutations)
|
| 64 |
+
executor (SQLiteAdapter with sandboxing)
|
| 65 |
+
verifier (semantic + execution checks)
|
| 66 |
+
repair (minimal-diff SQL repair loop)
|
| 67 |
+
↓
|
| 68 |
+
final SQL + result + traces
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### 🔧 Technical Stack
|
| 72 |
|
| 73 |
+
* **FastAPI** — HTTP API
|
| 74 |
+
* **Pydantic-AI** — agentic stages
|
| 75 |
+
* **SQLiteAdapter** — isolated DB execution
|
| 76 |
+
* **Prometheus** — metrics
|
| 77 |
+
* **Grafana** — dashboard
|
| 78 |
+
* **Makefile + pytest + mypy** — dev workflow
|
| 79 |
+
|
| 80 |
+
The entire pipeline is modular; each stage has a clean interface and can be swapped (e.g., planner or generator model).
|
|
|
|
| 81 |
|
| 82 |
---
|
| 83 |
|
| 84 |
+
# **4) Key Features**
|
| 85 |
|
| 86 |
+
### ✔ Multi-Stage Agentic Pipeline
|
|
|
|
| 87 |
|
| 88 |
+
Planner → Generator → Safety → Executor → Verifier → Repair.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
### ✔ Safety by Design
|
|
|
|
| 91 |
|
| 92 |
+
* Only `SELECT` queries allowed
|
| 93 |
+
* Column/table validation
|
| 94 |
+
* No multi-table hallucination
|
| 95 |
+
* Deterministic schema preview
|
| 96 |
|
| 97 |
+
### ✔ Repair Loop
|
| 98 |
+
|
| 99 |
+
Automatically fixes malformed or non-executable SQL using minimal edits and retries.
|
| 100 |
+
|
| 101 |
+
### ✔ Caching
|
| 102 |
|
| 103 |
+
* TTL-based
|
| 104 |
+
* Exact query deduplication
|
| 105 |
+
* Miss/hit metrics
|
| 106 |
|
| 107 |
+
### ✔ Observability
|
| 108 |
+
|
| 109 |
+
* Per-stage latency
|
| 110 |
+
* Pipeline success ratio
|
| 111 |
+
* Repair success rate
|
| 112 |
+
* p95 latency
|
| 113 |
+
* Cache hit ratio
|
| 114 |
+
* Full Grafana dashboard
|
| 115 |
+
|
| 116 |
+
### ✔ Spider Benchmarks
|
| 117 |
+
|
| 118 |
+
Reproducible evaluation on Spider (dev split).
|
| 119 |
+
Comes with plotting utilities, histogram, latency per stage, and summary.json.
|
| 120 |
|
| 121 |
---
|
| 122 |
|
| 123 |
+
باشه—الان **همین بخش Benchmarks که ساختم** را برایت
|
| 124 |
+
**کاملاً آمادهٔ قرار گرفتن در README** میکنم:
|
| 125 |
|
| 126 |
+
* با heading درست
|
| 127 |
+
* با anchor مناسب
|
| 128 |
+
* با ساختار کاملاً همتراز با بقیهٔ README تو
|
| 129 |
+
* با badge
|
| 130 |
+
* بدون هیچ وابستگی اضافی
|
| 131 |
+
* ۱۰۰٪ کپیـپیست مستقیم
|
| 132 |
|
| 133 |
+
این نسخه **نهایی، آمادهٔ چسباندن** است:
|
| 134 |
|
| 135 |
+
---
|
| 136 |
|
| 137 |
+
# 📊 Benchmarks (Spider dev, 20 samples)
|
| 138 |
|
| 139 |
+
[](#benchmarks-spider-dev-20-samples)
|
| 140 |
|
| 141 |
+
This copilot is evaluated on a 20-sample slice of the Spider **dev** split
|
| 142 |
+
(focused on the `concert_singer` schema) using the production pipeline end-to-end.
|
| 143 |
|
| 144 |
+
### 🧮 Summary
|
| 145 |
|
| 146 |
+
- **Total samples:** 20
|
| 147 |
+
- **Successful runs:** 20 / 20 (**100%**)
|
| 148 |
+
- **Exact Match (EM):** **0.10**
|
| 149 |
+
- **Structural Match (SM):** **0.70**
|
| 150 |
+
- **Execution Accuracy (ExecAcc):** **0.725**
|
| 151 |
|
| 152 |
+
These results reflect a *production-oriented Text-to-SQL system*:
|
| 153 |
+
the model optimizes for **valid, executable SQL**, not strict syntactic match.
|
| 154 |
|
| 155 |
---
|
| 156 |
|
| 157 |
+
### ⏱ Latency
|
| 158 |
+
|
| 159 |
+
End-to-end pipeline time (all stages):
|
| 160 |
+
|
| 161 |
+
- **Avg latency:** ~**8066 ms**
|
| 162 |
+
- **p50 latency:** ~**9229 ms**
|
| 163 |
+
- **p95 latency:** ~**14936 ms**
|
| 164 |
+
|
| 165 |
+
Latency distribution is **bimodal**:
|
| 166 |
+
1) fast lookups,
|
| 167 |
+
2) multi-hop reasoning dominated by the planner stage.
|
| 168 |
+
|
| 169 |
+
(See `latency_histogram.png` in the benchmark folder.)
|
| 170 |
+
|
| 171 |
+
---
|
| 172 |
+
|
| 173 |
+
### ⚙️ Per-Stage Latency (from Prometheus histograms)
|
| 174 |
+
|
| 175 |
+
| Stage | Avg latency (ms) |
|
| 176 |
+
|------------|------------------|
|
| 177 |
+
| detector | ~1 |
|
| 178 |
+
| planner | ~8360 |
|
| 179 |
+
| generator | ~1645 |
|
| 180 |
+
| safety | ~2 |
|
| 181 |
+
| executor | ~1 |
|
| 182 |
+
| verifier | ~1 |
|
| 183 |
+
| repair | ~1200 |
|
| 184 |
+
|
| 185 |
+
The **planner** is the dominant contributor—expected for a reasoning-heavy
|
| 186 |
+
agentic pipeline. Safety/executor/verifier remain **single-digit ms**.
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
### ❌ Failure Modes (Why EM is low but ExecAcc is high)
|
| 191 |
+
|
| 192 |
+
Even when EM=0, **SM و ExecAcc غالباً 1.0** هستند.
|
| 193 |
|
| 194 |
+
Typical causes:
|
| 195 |
|
| 196 |
+
- Column name capitalization differences
|
| 197 |
+
- Different LIMIT usage
|
| 198 |
+
- Different column order
|
| 199 |
+
- Aliases not matching the gold query
|
| 200 |
+
- Spider gold query being `EMPTY`, but the model (correctly) infers a SQL query
|
| 201 |
|
| 202 |
+
In real systems, **execution correctness** matters more than literal match.
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
|
| 206 |
+
### 📂 Reproducibility
|
| 207 |
+
|
| 208 |
+
Run the exact same benchmark:
|
| 209 |
|
| 210 |
```bash
|
| 211 |
+
export SPIDER_ROOT="$PWD/data/spider"
|
| 212 |
+
|
| 213 |
+
PYTHONPATH=$PWD \
|
| 214 |
+
python benchmarks/evaluate_spider_pro.py --spider --split dev --limit 20 --debug
|
| 215 |
+
|
| 216 |
+
PYTHONPATH=$PWD \
|
| 217 |
+
python benchmarks/plot_results.py
|
| 218 |
+
````
|
| 219 |
+
|
| 220 |
+
Artifacts stored under:
|
| 221 |
+
|
| 222 |
+
```
|
| 223 |
+
benchmarks/results_pro/20251113-113600/
|
| 224 |
+
summary.json
|
| 225 |
+
eval.jsonl
|
| 226 |
+
metrics_overview.png
|
| 227 |
+
latency_histogram.png
|
| 228 |
+
latency_per_stage.png
|
| 229 |
+
errors_overview.png
|
| 230 |
```
|
| 231 |
|
| 232 |
+
These plots are directly embedded into the README if needed.
|
| 233 |
+
|
| 234 |
---
|
| 235 |
|
| 236 |
+
# **6) API Usage**
|
| 237 |
|
| 238 |
+
## 🔍 NL → SQL
|
| 239 |
|
| 240 |
```bash
|
| 241 |
+
curl -X POST "http://localhost:8000/api/v1/nl2sql" \
|
| 242 |
+
-H "Content-Type: application/json" \
|
| 243 |
+
-H "X-API-Key: dev-key" \
|
| 244 |
+
-d '{
|
| 245 |
+
"query": "Top 5 customers by total invoice amount",
|
| 246 |
+
"db_id": null
|
| 247 |
+
}'
|
| 248 |
```
|
| 249 |
|
| 250 |
+
Sample response:
|
| 251 |
+
|
| 252 |
+
```json
|
| 253 |
+
{
|
| 254 |
+
"ambiguous": false,
|
| 255 |
+
"sql": "...",
|
| 256 |
+
"rationale": "...",
|
| 257 |
+
"result": [...],
|
| 258 |
+
"traces": [
|
| 259 |
+
{"stage": "detector", "duration_ms": 1},
|
| 260 |
+
{"stage": "planner", "duration_ms": 8943},
|
| 261 |
+
{"stage": "generator", "duration_ms": 1722},
|
| 262 |
+
{"stage": "safety", "duration_ms": 2},
|
| 263 |
+
{"stage": "executor", "duration_ms": 1},
|
| 264 |
+
{"stage": "verifier", "duration_ms": 1},
|
| 265 |
+
{"stage": "repair", "duration_ms": 522}
|
| 266 |
+
]
|
| 267 |
+
}
|
| 268 |
+
```
|
| 269 |
+
|
| 270 |
+
---
|
| 271 |
+
|
| 272 |
+
## 📤 Upload SQLite DB
|
| 273 |
|
| 274 |
```bash
|
| 275 |
+
curl -X POST "http://localhost:8000/api/v1/nl2sql/upload_db" \
|
| 276 |
+
-H "X-API-Key: dev-key" \
|
| 277 |
+
-F "file=@/path/to/db.sqlite"
|
| 278 |
```
|
| 279 |
|
| 280 |
+
Response:
|
| 281 |
+
|
| 282 |
+
```json
|
| 283 |
+
{
|
| 284 |
+
"db_id": "9a21d49f-38d3-4ce0-a459-3688e02fd44a",
|
| 285 |
+
"message": "Database uploaded successfully."
|
| 286 |
+
}
|
| 287 |
+
```
|
| 288 |
|
| 289 |
---
|
| 290 |
|
| 291 |
+
## 📑 Schema Preview
|
| 292 |
|
| 293 |
```bash
|
| 294 |
+
curl "http://localhost:8000/api/v1/nl2sql/schema?db_id=<uuid>" \
|
| 295 |
+
-H "X-API-Key: dev-key"
|
|
|
|
|
|
|
| 296 |
```
|
| 297 |
|
| 298 |
+
---
|
| 299 |
|
| 300 |
+
## ⚙️ Environment Variables
|
| 301 |
+
|
| 302 |
+
| Variable | Purpose |
|
| 303 |
+
| ---------------------- | --------------------------------- |
|
| 304 |
+
| `API_KEYS` | Comma-separated auth keys |
|
| 305 |
+
| `DEV_MODE` | Enables strict ambiguity detector |
|
| 306 |
+
| `NL2SQL_CACHE_TTL_SEC` | Cache TTL |
|
| 307 |
+
| `NL2SQL_CACHE_MAX` | Cache size |
|
| 308 |
+
| `SPIDER_ROOT` | Spider dataset path |
|
| 309 |
+
| `USE_MOCK` | Skip DB execution |
|
| 310 |
|
| 311 |
---
|
| 312 |
|
| 313 |
+
# **7) Future Work**
|
| 314 |
|
| 315 |
+
The copilot is intentionally kept lean. Several scoped enhancements are planned:
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
+
### 1) Streaming SQL (SSE)
|
| 318 |
+
|
| 319 |
+
Show partial SQL generation live.
|
| 320 |
+
|
| 321 |
+
### 2) Redis Distributed Cache
|
| 322 |
+
|
| 323 |
+
Shared cache across replicas, eviction, warm-ups.
|
| 324 |
+
|
| 325 |
+
### 3) Multi-Model Planner/Generator
|
| 326 |
+
|
| 327 |
+
Support OpenAI, vLLM, LLaMA, hybrid pipelines.
|
| 328 |
+
|
| 329 |
+
### 4) A/B Testing Framework
|
| 330 |
+
|
| 331 |
+
Compare prompts/models with automated drift tracking.
|
| 332 |
+
|
| 333 |
+
### 5) Schema Embeddings
|
| 334 |
+
|
| 335 |
+
Vector-based reasoning for table/column retrieval.
|
| 336 |
+
|
| 337 |
+
### 6) Nightly CI Benchmarks
|
| 338 |
+
|
| 339 |
+
GitHub Actions → run Spider → save plots → detect drift.
|
| 340 |
+
|
| 341 |
+
### 7) Stronger Diff-based Repair
|
| 342 |
|
| 343 |
+
Trace-aware SQL recovery with history logging.
|
| 344 |
|
| 345 |
+
### 8) Deployment Template
|
|
|
|
|
|
|
| 346 |
|
| 347 |
+
Helm chart / compose stack for production rollout.
|
| 348 |
|
| 349 |
---
|
| 350 |
|
| 351 |
+
# **8) License**
|
| 352 |
|
| 353 |
+
MIT License.
|
benchmarks/results_pro/20251109-125509/eval.jsonl
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
{"source": "spider", "db_id": "concert_singer", "query": "How many singers do we have?", "gold_sql": "SELECT count(*) FROM singer", "pred_sql": "select count(*) from singer", "ok": true, "latency_ms": 7007, "em": 1.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 5977, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1019, "summary": "failed", "notes": {"rationale_len": 30}}, {"stage": "safety", "duration_ms": 3, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 4, "summary": "failed", "notes": {"row_count": 1, "col_count": 1, "sql_length": 27}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 27, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": false, "verified": true}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 2 |
-
{"source": "spider", "db_id": "concert_singer", "query": "What is the total number of singers?", "gold_sql": "SELECT count(*) FROM singer", "pred_sql": "select count(*) from singer", "ok": true, "latency_ms": 5715, "em": 1.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 4893, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 819, "summary": "failed", "notes": {"rationale_len": 30}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 1, "sql_length": 27}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 27, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": false, "verified": true}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 3 |
-
{"source": "spider", "db_id": "concert_singer", "query": "Show name, country, age for all singers ordered by age from the oldest to the youngest.", "gold_sql": "SELECT name , country , age FROM singer ORDER BY age DESC", "pred_sql": "", "ok": true, "latency_ms": 0, "em": 0.0, "sm": 0.0, "exec_acc": 0.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "ambiguous", "notes": {"ambiguous": true, "questions_len": 1}}]}
|
| 4 |
-
{"source": "spider", "db_id": "concert_singer", "query": "What are the names, countries, and ages for every singer in descending order of age?", "gold_sql": "SELECT name , country , age FROM singer ORDER BY age DESC", "pred_sql": "select Name, Country, Age from singer order by Age desc", "ok": true, "latency_ms": 7982, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 6702, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1278, "summary": "failed", "notes": {"rationale_len": 85}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 6, "col_count": 3, "sql_length": 55}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 55, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": false, "mixes_cols": false, "verified": true}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 5 |
-
{"source": "spider", "db_id": "concert_singer", "query": "What is the average, minimum, and maximum age of all singers from France?", "gold_sql": "SELECT avg(age) , min(age) , max(age) FROM singer WHERE country = 'France'", "pred_sql": "select avg(Age), min(Age), max(Age) from singer where Country = 'France'", "ok": true, "latency_ms": 11942, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 8334, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1279, "summary": "failed", "notes": {"rationale_len": 71}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 72, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false}}, {"stage": "repair", "duration_ms": 1242, "summary": "failed", "notes": {"old_sql_len": 72, "new_sql_len": 80}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 80}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 80, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false}}, {"stage": "repair", "duration_ms": 1075, "summary": "failed", "notes": {"old_sql_len": 80, "new_sql_len": 72}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 72, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false}}, {"stage": "pipeline", "duration_ms": 1, "summary": "auto-verified", "notes": {"reason": "executor succeeded, verifier silent"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
benchmarks/results_pro/20251109-125509/latency_histogram.png
DELETED
|
Binary file (18.6 kB)
|
|
|
benchmarks/results_pro/20251109-125509/latency_per_stage.png
DELETED
|
Binary file (27.8 kB)
|
|
|
benchmarks/results_pro/20251109-125509/metrics_overview.png
DELETED
|
Binary file (18.9 kB)
|
|
|
benchmarks/results_pro/20251109-125509/results.csv
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
db_id,query,ok,em,sm,exec_acc,latency_ms
|
| 2 |
-
concert_singer,"How many singers do we have?",✅,1.0,1.0,1.0,7007
|
| 3 |
-
concert_singer,"What is the total number of singers?",✅,1.0,1.0,1.0,5715
|
| 4 |
-
concert_singer,"Show name, country, age for all singers ordered by age from the oldest to the youngest.",✅,0.0,0.0,0.0,0
|
| 5 |
-
concert_singer,"What are the names, countries, and ages for every singer in descending order of age?",✅,0.0,1.0,1.0,7982
|
| 6 |
-
concert_singer,"What is the average, minimum, and maximum age of all singers from France?",✅,0.0,1.0,1.0,11942
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
benchmarks/results_pro/20251109-125509/summary.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"timestamp": "2025-11-09T12:55:42",
|
| 3 |
-
"split": "dev",
|
| 4 |
-
"config": "configs/sqlite_pipeline.yaml",
|
| 5 |
-
"total": 5,
|
| 6 |
-
"success": 5,
|
| 7 |
-
"success_rate": 1.0,
|
| 8 |
-
"avg_latency_ms": 6529.2,
|
| 9 |
-
"p50_latency_ms": 7007.0,
|
| 10 |
-
"p95_latency_ms": 11150.0,
|
| 11 |
-
"EM": 0.4,
|
| 12 |
-
"SM": 0.8,
|
| 13 |
-
"ExecAcc": 0.8,
|
| 14 |
-
"detector_avg_ms": 1.0,
|
| 15 |
-
"planner_avg_ms": 6476.5,
|
| 16 |
-
"generator_avg_ms": 1098.75,
|
| 17 |
-
"safety_avg_ms": 1.83,
|
| 18 |
-
"executor_avg_ms": 1.5,
|
| 19 |
-
"verifier_avg_ms": 1.0,
|
| 20 |
-
"repair_avg_ms": 1158.5
|
| 21 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
benchmarks/results_pro/20251113-113600/eval.jsonl
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"source": "spider", "db_id": "concert_singer", "query": "How many singers do we have?", "gold_sql": "SELECT count(*) FROM singer", "pred_sql": "select count(*) from singer", "ok": true, "latency_ms": 9216, "em": 1.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 5628, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 5628, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 3580, "summary": "failed", "notes": {"rationale_len": 30}}, {"stage": "generator", "duration_ms": 3580, "summary": "failed", "notes": {"rationale_len": 30}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 2, "summary": "failed", "notes": {"row_count": 1, "col_count": 1, "sql_length": 27}}, {"stage": "executor", "duration_ms": 2, "summary": "failed", "notes": {"row_count": 1, "col_count": 1, "sql_length": 27}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 27, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 2 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the total number of singers?", "gold_sql": "SELECT count(*) FROM singer", "pred_sql": "select count(*) from singer", "ok": true, "latency_ms": 12541, "em": 1.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 8831, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 8831, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 3708, "summary": "failed", "notes": {"rationale_len": 30}}, {"stage": "generator", "duration_ms": 3708, "summary": "failed", "notes": {"rationale_len": 30}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 1, "sql_length": 27}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 1, "sql_length": 27}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 27, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 3 |
+
{"source": "spider", "db_id": "concert_singer", "query": "Show name, country, age for all singers ordered by age from the oldest to the youngest.", "gold_sql": "SELECT name , country , age FROM singer ORDER BY age DESC", "pred_sql": "", "ok": true, "latency_ms": 0, "em": 0.0, "sm": 0.0, "exec_acc": 0.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "ambiguous", "notes": {"ambiguous": true, "questions_len": 1}}]}
|
| 4 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What are the names, countries, and ages for every singer in descending order of age?", "gold_sql": "SELECT name , country , age FROM singer ORDER BY age DESC", "pred_sql": "select Name, Country, Age from singer order by Age desc", "ok": true, "latency_ms": 10264, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 8666, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 8666, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1595, "summary": "failed", "notes": {"rationale_len": 85}}, {"stage": "generator", "duration_ms": 1595, "summary": "failed", "notes": {"rationale_len": 85}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 6, "col_count": 3, "sql_length": 55}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 6, "col_count": 3, "sql_length": 55}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 55, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": false, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 5 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the average, minimum, and maximum age of all singers from France?", "gold_sql": "SELECT avg(age) , min(age) , max(age) FROM singer WHERE country = 'France'", "pred_sql": "select avg(Age), min(Age), max(Age) from singer where Country = 'France'", "ok": true, "latency_ms": 16808, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 9384, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 9384, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 3773, "summary": "failed", "notes": {"rationale_len": 91}}, {"stage": "generator", "duration_ms": 3773, "summary": "failed", "notes": {"rationale_len": 91}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 72, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 1426, "summary": "failed", "notes": {"old_sql_len": 72, "new_sql_len": 80}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 80}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 80, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 2217, "summary": "failed", "notes": {"old_sql_len": 80, "new_sql_len": 72}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 72, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "auto-verified", "notes": {"reason": "executor succeeded, verifier silent"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 6 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the average, minimum, and maximum age for all French singers?", "gold_sql": "SELECT avg(age) , min(age) , max(age) FROM singer WHERE country = 'France'", "pred_sql": "select avg(Age), min(Age), max(Age) from singer where Country = 'France'", "ok": true, "latency_ms": 11794, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 7403, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 7403, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1536, "summary": "failed", "notes": {"rationale_len": 84}}, {"stage": "generator", "duration_ms": 1536, "summary": "failed", "notes": {"rationale_len": 84}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 72, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 1379, "summary": "failed", "notes": {"old_sql_len": 72, "new_sql_len": 80}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 80}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 80, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 1465, "summary": "failed", "notes": {"old_sql_len": 80, "new_sql_len": 72}}, {"stage": "safety", "duration_ms": 4, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 3, "sql_length": 72}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 72, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "auto-verified", "notes": {"reason": "executor succeeded, verifier silent"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 7 |
+
{"source": "spider", "db_id": "concert_singer", "query": "Show the name and the release year of the song by the youngest singer.", "gold_sql": "SELECT song_name , song_release_year FROM singer ORDER BY age LIMIT 1", "pred_sql": "", "ok": true, "latency_ms": 0, "em": 0.0, "sm": 0.0, "exec_acc": 0.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "ambiguous", "notes": {"ambiguous": true, "questions_len": 1}}]}
|
| 8 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What are the names and release years for all the songs of the youngest singer?", "gold_sql": "SELECT song_name , song_release_year FROM singer ORDER BY age LIMIT 1", "pred_sql": "select Song_Name, Song_release_year from singer where Age = (select min(Age) from singer) LIMIT 1", "ok": true, "latency_ms": 14837, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 10256, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 10256, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 2561, "summary": "failed", "notes": {"rationale_len": 105}}, {"stage": "generator", "duration_ms": 2561, "summary": "failed", "notes": {"rationale_len": 105}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 89}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 89}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 89, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 938, "summary": "failed", "notes": {"old_sql_len": 89, "new_sql_len": 97}}, {"stage": "safety", "duration_ms": 3, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 97}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 97, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 1069, "summary": "failed", "notes": {"old_sql_len": 97, "new_sql_len": 97}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 97}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 97, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "auto-verified", "notes": {"reason": "executor succeeded, verifier silent"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 9 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What are all distinct countries where singers above age 20 are from?", "gold_sql": "SELECT DISTINCT country FROM singer WHERE age > 20", "pred_sql": "select distinct Country from singer where Age > 20", "ok": true, "latency_ms": 9369, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 7097, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 7097, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 2270, "summary": "failed", "notes": {"rationale_len": 78}}, {"stage": "generator", "duration_ms": 2270, "summary": "failed", "notes": {"rationale_len": 78}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 50}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 50}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 50, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": true, "has_aggregate": false, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 10 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What are the different countries with singers above age 20?", "gold_sql": "SELECT DISTINCT country FROM singer WHERE age > 20", "pred_sql": "select distinct Country from singer where Age > 20", "ok": true, "latency_ms": 8819, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 6873, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 6873, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1944, "summary": "failed", "notes": {"rationale_len": 81}}, {"stage": "generator", "duration_ms": 1944, "summary": "failed", "notes": {"rationale_len": 81}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 50}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 50}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 50, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": true, "has_aggregate": false, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 11 |
+
{"source": "spider", "db_id": "concert_singer", "query": "Show all countries and the number of singers in each country.", "gold_sql": "SELECT country , count(*) FROM singer GROUP BY country", "pred_sql": "select Country, count(*) from singer group by Country", "ok": true, "latency_ms": 11564, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 10054, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 10054, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1506, "summary": "failed", "notes": {"rationale_len": 87}}, {"stage": "generator", "duration_ms": 1506, "summary": "failed", "notes": {"rationale_len": 87}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 2, "sql_length": 53}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 2, "sql_length": 53}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 53, "has_select": true, "has_from": true, "has_over": false, "has_group_by": true, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 12 |
+
{"source": "spider", "db_id": "concert_singer", "query": "How many singers are from each country?", "gold_sql": "SELECT country , count(*) FROM singer GROUP BY country", "pred_sql": "select Country, count(*) from singer group by Country", "ok": true, "latency_ms": 7353, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 6475, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 6475, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 875, "summary": "failed", "notes": {"rationale_len": 66}}, {"stage": "generator", "duration_ms": 875, "summary": "failed", "notes": {"rationale_len": 66}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 2, "sql_length": 53}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 2, "sql_length": 53}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 53, "has_select": true, "has_from": true, "has_over": false, "has_group_by": true, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 13 |
+
{"source": "spider", "db_id": "concert_singer", "query": "List all song names by singers above the average age.", "gold_sql": "SELECT song_name FROM singer WHERE age > (SELECT avg(age) FROM singer)", "pred_sql": "select Song_Name from singer where Age > (select avg(Age) from singer)", "ok": true, "latency_ms": 9242, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 7773, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 7773, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1467, "summary": "failed", "notes": {"rationale_len": 87}}, {"stage": "generator", "duration_ms": 1467, "summary": "failed", "notes": {"rationale_len": 87}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 70}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 70}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 70, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 14 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What are all the song names by singers who are older than average?", "gold_sql": "SELECT song_name FROM singer WHERE age > (SELECT avg(age) FROM singer)", "pred_sql": "select Song_Name from singer where Age > (select avg(Age) from singer)", "ok": true, "latency_ms": 13098, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 11292, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 11292, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1803, "summary": "failed", "notes": {"rationale_len": 81}}, {"stage": "generator", "duration_ms": 1803, "summary": "failed", "notes": {"rationale_len": 81}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 2, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 70}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 3, "col_count": 1, "sql_length": 70}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 70, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 15 |
+
{"source": "spider", "db_id": "concert_singer", "query": "Show location and name for all stadiums with a capacity between 5000 and 10000.", "gold_sql": "SELECT LOCATION , name FROM stadium WHERE capacity BETWEEN 5000 AND 10000", "pred_sql": "", "ok": true, "latency_ms": 0, "em": 0.0, "sm": 0.0, "exec_acc": 0.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "ambiguous", "notes": {"ambiguous": true, "questions_len": 1}}]}
|
| 16 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What are the locations and names of all stations with capacity between 5000 and 10000?", "gold_sql": "SELECT LOCATION , name FROM stadium WHERE capacity BETWEEN 5000 AND 10000", "pred_sql": "select Location, Name from stadium where Capacity >= 5000 and Capacity <= 10000", "ok": true, "latency_ms": 8719, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 7131, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 7131, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1531, "summary": "failed", "notes": {"rationale_len": 78}}, {"stage": "generator", "duration_ms": 1531, "summary": "failed", "notes": {"rationale_len": 78}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 55, "summary": "failed", "notes": {"row_count": 0, "col_count": 2, "sql_length": 79}}, {"stage": "executor", "duration_ms": 55, "summary": "failed", "notes": {"row_count": 0, "col_count": 2, "sql_length": 79}}, {"stage": "verifier", "duration_ms": 1, "summary": "ok", "notes": {"sql_length": 79, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": false, "mixes_cols": false, "verified": true, "reason": "ok"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 17 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the maximum capacity and the average of all stadiums ?", "gold_sql": "select max(capacity), average from stadium", "pred_sql": "select max(Capacity), avg(Capacity) from stadium", "ok": true, "latency_ms": 6426, "em": 0.0, "sm": 0.0, "exec_acc": 0.5, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 3432, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 3432, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1326, "summary": "failed", "notes": {"rationale_len": 77}}, {"stage": "generator", "duration_ms": 1326, "summary": "failed", "notes": {"rationale_len": 77}}, {"stage": "safety", "duration_ms": 5, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 5, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 48}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 48}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 48, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 869, "summary": "failed", "notes": {"old_sql_len": 48, "new_sql_len": 56}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 56}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 56, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 741, "summary": "failed", "notes": {"old_sql_len": 56, "new_sql_len": 48}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 49, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 48}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 48, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "auto-verified", "notes": {"reason": "executor succeeded, verifier silent"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 18 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the average and maximum capacities for all stadiums ?", "gold_sql": "select avg(capacity) , max(capacity) from stadium", "pred_sql": "select avg(Capacity), max(Capacity) from stadium LIMIT 1", "ok": true, "latency_ms": 11276, "em": 0.0, "sm": 1.0, "exec_acc": 1.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "clear", "notes": {"ambiguous": false, "questions_len": 0}}, {"stage": "planner", "duration_ms": 7807, "summary": "ok", "notes": {}}, {"stage": "planner", "duration_ms": 7807, "summary": "ok", "notes": {}}, {"stage": "generator", "duration_ms": 1611, "summary": "failed", "notes": {"rationale_len": 63}}, {"stage": "generator", "duration_ms": 1611, "summary": "failed", "notes": {"rationale_len": 63}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 48, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 48}}, {"stage": "executor", "duration_ms": 48, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 48}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 48, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 944, "summary": "failed", "notes": {"old_sql_len": 48, "new_sql_len": 48}}, {"stage": "safety", "duration_ms": 1, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 48}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 48, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "repair", "duration_ms": 859, "summary": "failed", "notes": {"old_sql_len": 48, "new_sql_len": 56}}, {"stage": "safety", "duration_ms": 3, "summary": "failed", "notes": {}}, {"stage": "executor", "duration_ms": 1, "summary": "failed", "notes": {"row_count": 1, "col_count": 2, "sql_length": 56}}, {"stage": "verifier", "duration_ms": 1, "summary": "failed", "notes": {"sql_length": 56, "has_select": true, "has_from": true, "has_over": false, "has_group_by": false, "has_distinct": false, "has_aggregate": true, "mixes_cols": true, "verified": false, "reason": "aggregation-without-groupby"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "auto-verified", "notes": {"reason": "executor succeeded, verifier silent"}}, {"stage": "pipeline", "duration_ms": 1, "summary": "finalize", "notes": {"final_verified": true, "details_len": 0, "need_verification": false}}]}
|
| 19 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the name and capacity for the stadium with highest average attendance?", "gold_sql": "SELECT name , capacity FROM stadium ORDER BY average DESC LIMIT 1", "pred_sql": "", "ok": true, "latency_ms": 0, "em": 0.0, "sm": 0.0, "exec_acc": 0.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "ambiguous", "notes": {"ambiguous": true, "questions_len": 1}}]}
|
| 20 |
+
{"source": "spider", "db_id": "concert_singer", "query": "What is the name and capacity for the stadium with the highest average attendance?", "gold_sql": "SELECT name , capacity FROM stadium ORDER BY average DESC LIMIT 1", "pred_sql": "", "ok": true, "latency_ms": 0, "em": 0.0, "sm": 0.0, "exec_acc": 0.0, "error": null, "trace": [{"stage": "detector", "duration_ms": 1, "summary": "ambiguous", "notes": {"ambiguous": true, "questions_len": 1}}]}
|
benchmarks/results_pro/20251113-113600/latency_histogram.png
ADDED
|
benchmarks/results_pro/20251113-113600/latency_per_stage.png
ADDED
|
benchmarks/results_pro/20251113-113600/metrics_overview.png
ADDED
|
benchmarks/results_pro/20251113-113600/results.csv
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
db_id,query,ok,em,sm,exec_acc,latency_ms
|
| 2 |
+
concert_singer,"How many singers do we have?",✅,1.0,1.0,1.0,9216
|
| 3 |
+
concert_singer,"What is the total number of singers?",✅,1.0,1.0,1.0,12541
|
| 4 |
+
concert_singer,"Show name, country, age for all singers ordered by age from the oldest to the youngest.",✅,0.0,0.0,0.0,0
|
| 5 |
+
concert_singer,"What are the names, countries, and ages for every singer in descending order of age?",✅,0.0,1.0,1.0,10264
|
| 6 |
+
concert_singer,"What is the average, minimum, and maximum age of all singers from France?",✅,0.0,1.0,1.0,16808
|
| 7 |
+
concert_singer,"What is the average, minimum, and maximum age for all French singers?",✅,0.0,1.0,1.0,11794
|
| 8 |
+
concert_singer,"Show the name and the release year of the song by the youngest singer.",✅,0.0,0.0,0.0,0
|
| 9 |
+
concert_singer,"What are the names and release years for all the songs of the youngest singer?",✅,0.0,1.0,1.0,14837
|
| 10 |
+
concert_singer,"What are all distinct countries where singers above age 20 are from?",✅,0.0,1.0,1.0,9369
|
| 11 |
+
concert_singer,"What are the different countries with singers above age 20?",✅,0.0,1.0,1.0,8819
|
| 12 |
+
concert_singer,"Show all countries and the number of singers in each country.",✅,0.0,1.0,1.0,11564
|
| 13 |
+
concert_singer,"How many singers are from each country?",✅,0.0,1.0,1.0,7353
|
| 14 |
+
concert_singer,"List all song names by singers above the average age.",✅,0.0,1.0,1.0,9242
|
| 15 |
+
concert_singer,"What are all the song names by singers who are older than average?",✅,0.0,1.0,1.0,13098
|
| 16 |
+
concert_singer,"Show location and name for all stadiums with a capacity between 5000 and 10000.",✅,0.0,0.0,0.0,0
|
| 17 |
+
concert_singer,"What are the locations and names of all stations with capacity between 5000 and 10000?",✅,0.0,1.0,1.0,8719
|
| 18 |
+
concert_singer,"What is the maximum capacity and the average of all stadiums ?",✅,0.0,0.0,0.5,6426
|
| 19 |
+
concert_singer,"What is the average and maximum capacities for all stadiums ?",✅,0.0,1.0,1.0,11276
|
| 20 |
+
concert_singer,"What is the name and capacity for the stadium with highest average attendance?",✅,0.0,0.0,0.0,0
|
| 21 |
+
concert_singer,"What is the name and capacity for the stadium with the highest average attendance?",✅,0.0,0.0,0.0,0
|
benchmarks/results_pro/20251113-113600/summary.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"timestamp": "2025-11-13T11:38:42",
|
| 3 |
+
"split": "dev",
|
| 4 |
+
"config": "configs/sqlite_pipeline.yaml",
|
| 5 |
+
"total": 20,
|
| 6 |
+
"success": 20,
|
| 7 |
+
"success_rate": 1.0,
|
| 8 |
+
"avg_latency_ms": 8066.3,
|
| 9 |
+
"p50_latency_ms": 9229.0,
|
| 10 |
+
"p95_latency_ms": 14935.6,
|
| 11 |
+
"EM": 0.1,
|
| 12 |
+
"SM": 0.7,
|
| 13 |
+
"ExecAcc": 0.725,
|
| 14 |
+
"detector_avg_ms": 1.0,
|
| 15 |
+
"planner_avg_ms": 7873.47,
|
| 16 |
+
"generator_avg_ms": 2072.4,
|
| 17 |
+
"safety_avg_ms": 1.65,
|
| 18 |
+
"executor_avg_ms": 7.3,
|
| 19 |
+
"verifier_avg_ms": 1.0,
|
| 20 |
+
"repair_avg_ms": 1190.7
|
| 21 |
+
}
|
demo/app.py
CHANGED
|
@@ -1,156 +1,211 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import gradio as gr
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
API_HOST = os.getenv("API_HOST", "localhost")
|
| 9 |
API_PORT = os.getenv("API_PORT", "8000")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
USE_MOCK = os.environ.get("USE_MOCK", "0") == "1"
|
| 12 |
-
API_UPLOAD = f"http://{API_HOST}:{API_PORT}/api/v1/nl2sql/upload_db"
|
| 13 |
-
API_QUERY = f"http://{API_HOST}:{API_PORT}/api/v1/nl2sql"
|
| 14 |
-
|
| 15 |
-
HARDCODED_MOCK = {
|
| 16 |
-
"sql": "SELECT name, country FROM singer WHERE age > 20;",
|
| 17 |
-
"rationale": "Example: select singers older than 20.",
|
| 18 |
-
"result": {
|
| 19 |
-
"rows": 5,
|
| 20 |
-
"columns": ["name", "country"],
|
| 21 |
-
"rows_data": [["Alice", "France"], ["Bob", "USA"]],
|
| 22 |
-
},
|
| 23 |
-
"traces": [
|
| 24 |
-
{"stage": "detector", "summary": "ok", "duration_ms": 5},
|
| 25 |
-
{"stage": "planner", "summary": "intent parsed", "duration_ms": 120},
|
| 26 |
-
{"stage": "generator", "summary": "sql generated", "duration_ms": 420},
|
| 27 |
-
{"stage": "verifier", "summary": "passed", "duration_ms": 10},
|
| 28 |
-
],
|
| 29 |
-
"metrics": {"EM": 0.15, "SM": 0.70, "ExecAcc": 0.73, "avg_latency_ms": 8113},
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def load_mock_from_summary():
|
| 34 |
-
"""Try to read latest benchmark summary.json; fallback to hardcoded mock."""
|
| 35 |
-
try:
|
| 36 |
-
files = sorted(
|
| 37 |
-
Path("benchmarks/results_pro").glob("*/summary.json"),
|
| 38 |
-
key=lambda p: p.stat().st_mtime,
|
| 39 |
-
reverse=True,
|
| 40 |
-
)
|
| 41 |
-
if files:
|
| 42 |
-
p = files[0]
|
| 43 |
-
with open(p, "r", encoding="utf-8") as f:
|
| 44 |
-
sj = json.load(f)
|
| 45 |
-
return {
|
| 46 |
-
"sql": sj.get("example_sql", HARDCODED_MOCK["sql"]),
|
| 47 |
-
"rationale": sj.get("note", HARDCODED_MOCK["rationale"]),
|
| 48 |
-
"result": {"rows": sj.get("total_samples", 0), "columns": []},
|
| 49 |
-
"traces": HARDCODED_MOCK["traces"],
|
| 50 |
-
"metrics": {
|
| 51 |
-
"EM": sj.get("avg_em", HARDCODED_MOCK["metrics"]["EM"]),
|
| 52 |
-
"SM": sj.get("avg_sm", HARDCODED_MOCK["metrics"]["SM"]),
|
| 53 |
-
"ExecAcc": sj.get(
|
| 54 |
-
"avg_execacc", HARDCODED_MOCK["metrics"]["ExecAcc"]
|
| 55 |
-
),
|
| 56 |
-
"avg_latency_ms": sj.get(
|
| 57 |
-
"avg_latency_ms", HARDCODED_MOCK["metrics"]["avg_latency_ms"]
|
| 58 |
-
),
|
| 59 |
-
},
|
| 60 |
-
}
|
| 61 |
-
except Exception:
|
| 62 |
-
pass
|
| 63 |
-
return HARDCODED_MOCK
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
def call_pipeline_api_or_mock(query: str, db_id: str | None = None, timeout=10):
|
| 67 |
-
"""Call backend if available; otherwise return mock."""
|
| 68 |
-
if USE_MOCK:
|
| 69 |
-
return load_mock_from_summary()
|
| 70 |
-
try:
|
| 71 |
-
payload = {"query": query}
|
| 72 |
-
if db_id:
|
| 73 |
-
payload["db_id"] = db_id
|
| 74 |
-
r = requests.post(API_QUERY, json=payload, timeout=timeout)
|
| 75 |
-
r.raise_for_status()
|
| 76 |
-
return r.json()
|
| 77 |
-
except Exception as e:
|
| 78 |
-
print(f"[demo] API call failed ({e}); using mock instead.")
|
| 79 |
-
return load_mock_from_summary()
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if file_obj is None:
|
| 84 |
-
return None, "No DB uploaded.
|
|
|
|
| 85 |
name = getattr(file_obj, "name", "db.sqlite")
|
| 86 |
if not (name.endswith(".db") or name.endswith(".sqlite")):
|
| 87 |
return None, "Only .db or .sqlite files are allowed."
|
|
|
|
| 88 |
size = getattr(file_obj, "size", None)
|
| 89 |
if size and size > 20 * 1024 * 1024:
|
| 90 |
return None, "File too large (>20MB) for this demo."
|
| 91 |
|
| 92 |
-
|
| 93 |
try:
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
finally:
|
| 96 |
try:
|
| 97 |
-
|
| 98 |
except Exception:
|
| 99 |
pass
|
| 100 |
|
| 101 |
-
if
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
if not user_query.strip():
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
explanation = data.get("rationale") or ""
|
| 118 |
result = data.get("result", {})
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
-
badges_text =
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
-
return badges_text, sql, explanation, result, trace_list, timings_table
|
| 133 |
|
| 134 |
|
| 135 |
def build_ui() -> gr.Blocks:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
with gr.Blocks(title="NL2SQL Copilot") as demo:
|
| 137 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
db_state = gr.State(value=None)
|
| 139 |
|
|
|
|
| 140 |
with gr.Row():
|
| 141 |
db_file = gr.File(
|
| 142 |
-
label="Upload SQLite (.db/.sqlite)",
|
|
|
|
| 143 |
)
|
| 144 |
upload_btn = gr.Button("Upload DB")
|
|
|
|
| 145 |
db_msg = gr.Markdown()
|
| 146 |
-
upload_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
|
|
|
| 148 |
with gr.Row():
|
| 149 |
-
q = gr.Textbox(
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
run = gr.Button("Run")
|
| 152 |
|
| 153 |
-
# Example queries
|
| 154 |
gr.Examples(
|
| 155 |
examples=[
|
| 156 |
["List all artists"],
|
|
@@ -164,13 +219,13 @@ def build_ui() -> gr.Blocks:
|
|
| 164 |
|
| 165 |
badges = gr.Markdown()
|
| 166 |
sql_out = gr.Code(label="Final SQL", language="sql")
|
| 167 |
-
exp_out = gr.Textbox(label="Explanation", lines=
|
| 168 |
|
| 169 |
with gr.Tab("Result"):
|
| 170 |
res_out = gr.JSON()
|
| 171 |
|
| 172 |
with gr.Tab("Trace"):
|
| 173 |
-
|
| 174 |
|
| 175 |
with gr.Tab("Repair"):
|
| 176 |
gr.Markdown(
|
|
@@ -184,8 +239,8 @@ def build_ui() -> gr.Blocks:
|
|
| 184 |
* All repair attempts and outcomes are tracked in Prometheus
|
| 185 |
(for example, `nl2sql_repair_attempts_total` and related rates).
|
| 186 |
|
| 187 |
-
For now, detailed before/after SQL
|
| 188 |
-
are exposed via
|
| 189 |
|
| 190 |
This tab is reserved for a future, richer UI:
|
| 191 |
side-by-side SQL diff, repair candidates, and explanations.
|
|
@@ -194,25 +249,19 @@ def build_ui() -> gr.Blocks:
|
|
| 194 |
|
| 195 |
with gr.Tab("Timings"):
|
| 196 |
timings = gr.Dataframe(
|
| 197 |
-
headers=["stage", "duration_ms"],
|
|
|
|
| 198 |
)
|
| 199 |
|
| 200 |
run.click(
|
| 201 |
query_to_sql,
|
| 202 |
inputs=[q, db_state, debug],
|
| 203 |
-
outputs=[
|
| 204 |
-
badges,
|
| 205 |
-
sql_out,
|
| 206 |
-
exp_out,
|
| 207 |
-
res_out,
|
| 208 |
-
trace,
|
| 209 |
-
timings,
|
| 210 |
-
],
|
| 211 |
)
|
|
|
|
| 212 |
return demo
|
| 213 |
|
| 214 |
|
| 215 |
-
# expose for SDK mode (no Docker)
|
| 216 |
demo = build_ui()
|
| 217 |
|
| 218 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import requests
|
| 6 |
+
from requests.exceptions import ConnectionError, RequestException, Timeout
|
| 7 |
|
| 8 |
+
# Backend configuration
|
| 9 |
API_HOST = os.getenv("API_HOST", "localhost")
|
| 10 |
API_PORT = os.getenv("API_PORT", "8000")
|
| 11 |
+
API_BASE = f"http://{API_HOST}:{API_PORT}"
|
| 12 |
+
|
| 13 |
+
API_QUERY = f"{API_BASE}/api/v1/nl2sql"
|
| 14 |
+
API_UPLOAD = f"{API_BASE}/api/v1/nl2sql/upload_db"
|
| 15 |
+
API_KEY = os.getenv("API_KEY", "dev-key") # align with backend API_KEYS env
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
def call_pipeline_api(
|
| 19 |
+
query: str,
|
| 20 |
+
db_id: Optional[str] = None,
|
| 21 |
+
timeout: int = 30,
|
| 22 |
+
) -> Dict[str, Any]:
|
| 23 |
+
"""
|
| 24 |
+
Call the real FastAPI backend. No mock, no silent fallback.
|
| 25 |
|
| 26 |
+
If db_id is None, the backend will use its default database.
|
| 27 |
+
Any connection or HTTP error is surfaced back to the UI as an error payload.
|
| 28 |
+
"""
|
| 29 |
+
payload: Dict[str, Any] = {"query": query}
|
| 30 |
+
if db_id:
|
| 31 |
+
payload["db_id"] = db_id
|
| 32 |
+
|
| 33 |
+
headers: Dict[str, str] = {"Content-Type": "application/json"}
|
| 34 |
+
if API_KEY:
|
| 35 |
+
headers["X-API-Key"] = API_KEY
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
resp = requests.post(API_QUERY, json=payload, headers=headers, timeout=timeout)
|
| 39 |
+
resp.raise_for_status()
|
| 40 |
+
return resp.json()
|
| 41 |
+
except (ConnectionError, Timeout) as e:
|
| 42 |
+
msg = f"Backend not reachable: {e}"
|
| 43 |
+
print(f"[demo] {msg}", flush=True)
|
| 44 |
+
return {
|
| 45 |
+
"sql": "",
|
| 46 |
+
"rationale": msg,
|
| 47 |
+
"result": {},
|
| 48 |
+
"traces": [],
|
| 49 |
+
"error": msg,
|
| 50 |
+
}
|
| 51 |
+
except RequestException:
|
| 52 |
+
try:
|
| 53 |
+
body: Any = resp.json()
|
| 54 |
+
except Exception:
|
| 55 |
+
body = resp.text
|
| 56 |
+
msg = f"Backend error {resp.status_code}: {body}"
|
| 57 |
+
print(f"[demo] {msg}", flush=True)
|
| 58 |
+
return {
|
| 59 |
+
"sql": "",
|
| 60 |
+
"rationale": msg,
|
| 61 |
+
"result": {},
|
| 62 |
+
"traces": [],
|
| 63 |
+
"error": msg,
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def upload_db(file_obj: Any) -> Tuple[Optional[str], str]:
|
| 68 |
+
"""
|
| 69 |
+
Upload a SQLite database to the backend and return (db_id, message).
|
| 70 |
+
|
| 71 |
+
The returned db_id is stored in Gradio state and used for subsequent queries.
|
| 72 |
+
"""
|
| 73 |
if file_obj is None:
|
| 74 |
+
return None, "No DB uploaded. The backend default DB will be used."
|
| 75 |
+
|
| 76 |
name = getattr(file_obj, "name", "db.sqlite")
|
| 77 |
if not (name.endswith(".db") or name.endswith(".sqlite")):
|
| 78 |
return None, "Only .db or .sqlite files are allowed."
|
| 79 |
+
|
| 80 |
size = getattr(file_obj, "size", None)
|
| 81 |
if size and size > 20 * 1024 * 1024:
|
| 82 |
return None, "File too large (>20MB) for this demo."
|
| 83 |
|
| 84 |
+
# Gradio's File component provides a temporary file on disk.
|
| 85 |
try:
|
| 86 |
+
f = open(file_obj.name, "rb")
|
| 87 |
+
except Exception as e:
|
| 88 |
+
return None, f"Could not open uploaded file: {e}"
|
| 89 |
+
|
| 90 |
+
files = {"file": (os.path.basename(name), f, "application/octet-stream")}
|
| 91 |
+
|
| 92 |
+
headers: Dict[str, str] = {}
|
| 93 |
+
if API_KEY:
|
| 94 |
+
headers["X-API-Key"] = API_KEY
|
| 95 |
+
|
| 96 |
+
try:
|
| 97 |
+
resp = requests.post(API_UPLOAD, files=files, headers=headers, timeout=120)
|
| 98 |
finally:
|
| 99 |
try:
|
| 100 |
+
f.close()
|
| 101 |
except Exception:
|
| 102 |
pass
|
| 103 |
|
| 104 |
+
if resp.ok:
|
| 105 |
+
try:
|
| 106 |
+
data = resp.json()
|
| 107 |
+
except Exception:
|
| 108 |
+
return None, f"Upload succeeded but response was not JSON: {resp.text}"
|
| 109 |
+
db_id = data.get("db_id")
|
| 110 |
+
return db_id, f"Uploaded OK. db_id={db_id}"
|
| 111 |
+
else:
|
| 112 |
+
try:
|
| 113 |
+
body = resp.json()
|
| 114 |
+
except Exception:
|
| 115 |
+
body = resp.text
|
| 116 |
+
return None, f"Upload failed ({resp.status_code}): {body}"
|
| 117 |
+
|
| 118 |
|
| 119 |
+
def query_to_sql(
|
| 120 |
+
user_query: str,
|
| 121 |
+
db_id: Optional[str],
|
| 122 |
+
_debug_flag: bool,
|
| 123 |
+
) -> Tuple[str, str, str, Any, List[Dict[str, Any]], List[List[Any]]]:
|
| 124 |
+
"""
|
| 125 |
+
Run the full NL2SQL pipeline via the backend and format outputs for the UI.
|
| 126 |
|
| 127 |
+
Returns:
|
| 128 |
+
badges_text, sql, explanation, result_json, traces_json, timings_table
|
| 129 |
+
"""
|
| 130 |
if not user_query.strip():
|
| 131 |
+
msg = "❌ Please enter a query."
|
| 132 |
+
return msg, "", msg, {}, [], []
|
| 133 |
+
|
| 134 |
+
data = call_pipeline_api(user_query, db_id)
|
| 135 |
+
|
| 136 |
+
# Explicit error propagation from backend
|
| 137 |
+
if data.get("error") and not data.get("sql"):
|
| 138 |
+
err_msg = str(data.get("error"))
|
| 139 |
+
return f"❌ {err_msg}", "", err_msg, {}, [], []
|
| 140 |
|
| 141 |
+
sql = str(data.get("sql") or "")
|
| 142 |
+
explanation = str(data.get("rationale") or "")
|
|
|
|
| 143 |
result = data.get("result", {})
|
| 144 |
+
traces = data.get("traces", []) or []
|
| 145 |
|
| 146 |
+
# Compute simple latency badge from traces (sum of duration_ms)
|
| 147 |
+
badges_text = ""
|
| 148 |
+
if traces and all("duration_ms" in t for t in traces):
|
| 149 |
+
total_ms = sum(float(t.get("duration_ms", 0.0)) for t in traces)
|
| 150 |
+
badges_text = f"latency≈{int(total_ms)}ms"
|
| 151 |
|
| 152 |
+
# Build timings table for the Timings tab
|
| 153 |
+
timings_table: List[List[Any]] = []
|
| 154 |
+
if traces and all("duration_ms" in t for t in traces):
|
| 155 |
+
timings_table = [
|
| 156 |
+
[t.get("stage", "?"), t.get("duration_ms", 0.0)] for t in traces
|
| 157 |
+
]
|
| 158 |
|
| 159 |
+
return badges_text, sql, explanation, result, traces, timings_table
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
def build_ui() -> gr.Blocks:
|
| 163 |
+
"""
|
| 164 |
+
Build the Gradio UI for the NL2SQL Copilot demo.
|
| 165 |
+
|
| 166 |
+
- Optional DB upload (SQLite)
|
| 167 |
+
- Textbox for the natural language question
|
| 168 |
+
- Example queries aligned with the default Chinook DB
|
| 169 |
+
- Tabs for result, trace, repair notes, and per-stage timings
|
| 170 |
+
"""
|
| 171 |
with gr.Blocks(title="NL2SQL Copilot") as demo:
|
| 172 |
+
gr.Markdown(
|
| 173 |
+
"# NL2SQL Copilot\n"
|
| 174 |
+
"Upload a SQLite DB (optional) or use the backend default database."
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
db_state = gr.State(value=None)
|
| 178 |
|
| 179 |
+
# DB upload section
|
| 180 |
with gr.Row():
|
| 181 |
db_file = gr.File(
|
| 182 |
+
label="Upload SQLite (.db/.sqlite)",
|
| 183 |
+
file_types=[".db", ".sqlite"],
|
| 184 |
)
|
| 185 |
upload_btn = gr.Button("Upload DB")
|
| 186 |
+
|
| 187 |
db_msg = gr.Markdown()
|
| 188 |
+
upload_btn.click(
|
| 189 |
+
upload_db,
|
| 190 |
+
inputs=[db_file],
|
| 191 |
+
outputs=[db_state, db_msg],
|
| 192 |
+
)
|
| 193 |
|
| 194 |
+
# Query input and run button
|
| 195 |
with gr.Row():
|
| 196 |
+
q = gr.Textbox(
|
| 197 |
+
label="Question",
|
| 198 |
+
placeholder="e.g. Top 3 albums by total sales",
|
| 199 |
+
scale=4,
|
| 200 |
+
)
|
| 201 |
+
debug = gr.Checkbox(
|
| 202 |
+
label="Debug (UI only)",
|
| 203 |
+
value=True,
|
| 204 |
+
scale=1,
|
| 205 |
+
)
|
| 206 |
run = gr.Button("Run")
|
| 207 |
|
| 208 |
+
# Example queries compatible with the Chinook schema
|
| 209 |
gr.Examples(
|
| 210 |
examples=[
|
| 211 |
["List all artists"],
|
|
|
|
| 219 |
|
| 220 |
badges = gr.Markdown()
|
| 221 |
sql_out = gr.Code(label="Final SQL", language="sql")
|
| 222 |
+
exp_out = gr.Textbox(label="Explanation", lines=4)
|
| 223 |
|
| 224 |
with gr.Tab("Result"):
|
| 225 |
res_out = gr.JSON()
|
| 226 |
|
| 227 |
with gr.Tab("Trace"):
|
| 228 |
+
trace_out = gr.JSON(label="Stage trace")
|
| 229 |
|
| 230 |
with gr.Tab("Repair"):
|
| 231 |
gr.Markdown(
|
|
|
|
| 239 |
* All repair attempts and outcomes are tracked in Prometheus
|
| 240 |
(for example, `nl2sql_repair_attempts_total` and related rates).
|
| 241 |
|
| 242 |
+
For now, detailed before/after SQL diffs and repair candidates
|
| 243 |
+
are exposed via traces and metrics dashboards.
|
| 244 |
|
| 245 |
This tab is reserved for a future, richer UI:
|
| 246 |
side-by-side SQL diff, repair candidates, and explanations.
|
|
|
|
| 249 |
|
| 250 |
with gr.Tab("Timings"):
|
| 251 |
timings = gr.Dataframe(
|
| 252 |
+
headers=["stage", "duration_ms"],
|
| 253 |
+
datatype=["str", "number"],
|
| 254 |
)
|
| 255 |
|
| 256 |
run.click(
|
| 257 |
query_to_sql,
|
| 258 |
inputs=[q, db_state, debug],
|
| 259 |
+
outputs=[badges, sql_out, exp_out, res_out, trace_out, timings],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
)
|
| 261 |
+
|
| 262 |
return demo
|
| 263 |
|
| 264 |
|
|
|
|
| 265 |
demo = build_ui()
|
| 266 |
|
| 267 |
if __name__ == "__main__":
|