How hkustdial/deepeye-sql works
1. DeepEye-SQL is a multi-stage Text-to-SQL system, not a single prompt-to-SQL app. The architecture decomposes one question into five sequential subsystems: value retrieval, schema linking, SQL generation, SQL revision, and SQL selection.
2. The main control boundary is the snapshot pipeline. Each stage reads a structured .snapshot artifact from the previous stage and writes a new snapshot under workspace/. This makes the workflow resumable, inspectable, and benchmarkable. Released outputs live separately under results/.
3. Configuration is externalized through TOML files in config/. These select the dataset family, paths, model endpoints, embedding settings, and stage-specific LLM parameters. The repo is built around Python 3.12+ and OpenAI-compatible model APIs.
4. Dataset handling is centralized in app/dataset/. It supports Spider, BIRD, and Spider2, with Spider2 requiring cloud-backed databases in some splits. This layer is responsible for preprocessing raw benchmark data into the structured dataset snapshot used by the rest of the pipeline.
5. Schema and execution concerns are abstracted in app/db_utils/ and app/services/. These modules load schema metadata, execute SQL, and adapt to local versus cloud-backed databases. The Spider2 path is special because it can involve BigQuery and Snowflake, so the execution layer has separate cloud adapters.
6. Value retrieval is a distinct subsystem in app/pipeline/value_retrieval/ backed by app/vector_db/. For Spider and BIRD, the pipeline builds a vector index over database values and uses embedding-based lookup to ground question mentions to concrete cell values. Spider2 skips this vector index path in the current workflow.
7. Schema linking is implemented in app/pipeline/schema_linking/. It combines three linkers: direct linking, reversed linking, and value-based linking. The output is a refined schema context that narrows which tables, columns, and values the generator should consider.
8. SQL generation lives in app/pipeline/sql_generation/ and is intentionally diversified. Multiple generators produce candidates using different prompting strategies, including skeleton-based, in-context learning, and domain-constrained generation. This stage is driven by prompt templates in app/prompt/ and LLM calls in app/llm/.
9. SQL revision in app/pipeline/sql_revision/ acts like a debugging pass. Checker modules validate syntax, joins, aggregates, ordering/limits, null ordering, selection correctness, max/min behavior, time-related issues, and result-level mismatches. The revision stage uses execution feedback to repair candidate SQL rather than only scoring it afterward.
10. SQL selection in app/pipeline/sql_selection/ compares revised candidates and chooses the final query. This stage is execution-aware: it uses actual database execution and comparison signals, not only string similarity or model confidence.
11. The runtime boundary between pipeline logic and external services is explicit. app/llm_extractor/ and app/llm/ handle model invocation, while app/services/execution_service.py, schema_service.py, and artifact_store.py coordinate database access, schema lookup, and persisted artifacts. A bounded cache is used to reduce repeated expensive operations.
12. The runner/ scripts are the orchestration entry points for reproducibility. They cover preprocessing, vector DB creation, each pipeline stage, conversion of snapshots to official SQL output, evaluation, and execution benchmarking. script/run_pipeline.sh ties these stages into a full end-to-end run.
13. For an architecture diagram, the key boundaries are: benchmark data ingestion, snapshot-based stage handoff, retrieval/linking/generation/revision/selection, and execution/LLM infrastructure. The external dependencies that materially affect the design are the benchmark databases, OpenAI-compatible LLM endpoints, embedding/indexing for value retrieval, and Spider2 cloud database credentials.
Main entry points: config Config · sql_revision SQL revision · sql_generation SQL generation · value_retrieval Value retrieval
Components 18
Ingestion
Benchmark data, preprocessing, and dataset snapshots
Pipeline
Snapshot-driven Text-to-SQL stages
- Artifacts · Dataset artifact construction and persisted pipeline snapshots
app/dataset/artifacts.py - Value retrieval · Grounds question mentions to concrete database values using embeddings and vector lookup
app/pipeline/value_retrieval - Schema linking · Refines schema context through direct, reversed, and value-based linkers
app/pipeline/schema_linking - SQL generation · Produces diversified SQL candidates using skeleton, ICL, and domain-constrained generators
app/pipeline/sql_generation - SQL revision · Validates and repairs candidate SQL with syntax, join, aggregate, ordering, and result checks
app/pipeline/sql_revision - SQL selection · Chooses the final query from revised candidates using execution-aware comparison
app/pipeline/sql_selection
Infra
LLM, execution, schema, and storage services
- Config · External TOML configuration for datasets, paths, models, embeddings, and stage parameters
config - Vector DB · Local value index and embedding function used by retrieval
app/vector_db - Prompts · Prompt factory and templates used to steer generation and revision
app/prompt - LLM · OpenAI-compatible model invocation layer
app/llm - Extractor · LLM extraction helper for structured outputs
app/llm_extractor - Services · Coordinates persisted artifacts, schema lookup, execution, and bounded cache
app/services - Schema utils · Loads schema metadata for local and cloud-backed databases
app/db_utils/schema.py - Execution utils · Executes SQL against benchmark databases and cloud adapters
app/db_utils/execution.py
Outputs
Released SQL and benchmark artifacts
- Cloud DBs · Spider2 cloud-backed execution targets such as BigQuery and Snowflake
- Results · Published SQL outputs and benchmark result files
results
Connections 24
- Runners → Datasets: preprocesses · Runner scripts prepare benchmark datasets into structured artifacts
- Datasets → Artifacts: writes · Dataset layer produces snapshot-ready artifacts
- Config → Runners: drives · Configuration selects dataset family, paths, and stage options
- Config → Value retrieval: configures · Retrieval parameters and paths are externally configured
- Config → SQL generation: configures · Generation stage uses model and prompt settings from config
- Config → SQL revision: configures · Revision stage uses stage-specific LLM and checker settings
- Config → SQL selection: configures · Selection stage is driven by external pipeline settings
- Artifacts → Value retrieval: handoff · Snapshot artifacts feed the value retrieval stage
- Value retrieval → Vector DB: queries · Spider and BIRD value retrieval queries the vector index
- Value retrieval → Schema linking: handoff · Retrieved values enrich the schema linking context
- Schema linking → SQL generation: handoff · Refined schema context feeds candidate generation
- Prompts → SQL generation: templates · Generation uses prompt templates and prompting strategies
- LLM → SQL generation: invokes · Generators call the model client for candidate SQL
- Extractor → LLM: parses · LLM extraction wraps model outputs into structured results
- SQL generation → SQL revision: candidates · Generated candidates flow into the repair stage
- Prompts → SQL revision: templates · Revision uses prompts for debugging and repair
- SQL revision → Execution utils: exec feedback · Revision relies on execution feedback and database checks
- SQL revision → SQL selection: revised candidates · Repaired SQL candidates are compared for final choice
- SQL selection → Execution utils: exec aware · Selection evaluates candidates with actual database execution
- Services → Schema utils: loads · Services layer retrieves schema metadata
- Services → Execution utils: runs · Services layer coordinates SQL execution
- Services → Artifacts: stores · Services layer persists and retrieves artifacts
- Execution utils → Cloud DBs: adapts to · Spider2 uses cloud-backed database adapters
- Runners → Results: exports · Runners convert snapshots into released SQL outputs and benchmark artifacts