# hkustdial/deepeye-sql architecture

> Architecture diagram of the GitHub repository hkustdial/deepeye-sql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hkustdial/deepeye-sql
- Repository: https://github.com/hkustdial/deepeye-sql

## Overview

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`](https://github.com/hkustdial/deepeye-sql/tree/master/config) (Config), [`app/pipeline/sql_revision`](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_revision) (SQL revision), [`app/pipeline/sql_generation`](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_generation) (SQL generation), [`app/pipeline/value_retrieval`](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/value_retrieval) (Value retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_ingest["Ingestion"]
  node_n_runner["Runners<br/>orchestration"]
  node_n_dataset["Datasets<br/>benchmark prep"]
end

subgraph group_g_pipeline["Pipeline"]
  node_n_artifacts["Artifacts<br/>snapshot store<br/>[artifacts.py]"]
  node_n_value["Value retrieval<br/>retrieval stage"]
  node_n_schema_link["Schema linking<br/>linking stage"]
  node_n_sql_gen["SQL generation<br/>candidate stage"]
  node_n_sql_rev["SQL revision<br/>repair stage"]
  node_n_sql_sel["SQL selection<br/>ranking stage"]
end

subgraph group_g_infra["Infra"]
  node_n_config["Config<br/>toml settings"]
  node_n_vector[("Vector DB<br/>indexing")]
  node_n_prompt["Prompts<br/>templates"]
  node_n_llm["LLM<br/>model client"]
  node_n_extract["Extractor<br/>llm parsing"]
  node_n_services["Services<br/>runtime boundary"]
  node_n_schema["Schema utils<br/>schema metadata<br/>[schema.py]"]
  node_n_exec["Execution utils<br/>sql execution<br/>[execution.py]"]
end

subgraph group_g_outputs["Outputs"]
  node_n_cloud[("Cloud DBs<br/>spider2 backend")]
  node_n_results["Results<br/>released outputs"]
end

node_n_runner -->|"preprocesses"| node_n_dataset
node_n_dataset -->|"writes"| node_n_artifacts
node_n_config -->|"drives"| node_n_runner
node_n_config -->|"configures"| node_n_value
node_n_config -->|"configures"| node_n_sql_gen
node_n_config -->|"configures"| node_n_sql_rev
node_n_config -->|"configures"| node_n_sql_sel
node_n_artifacts -->|"handoff"| node_n_value
node_n_value -->|"queries"| node_n_vector
node_n_value -->|"handoff"| node_n_schema_link
node_n_schema_link -->|"handoff"| node_n_sql_gen
node_n_prompt -->|"templates"| node_n_sql_gen
node_n_llm -->|"invokes"| node_n_sql_gen
node_n_extract -->|"parses"| node_n_llm
node_n_sql_gen -->|"candidates"| node_n_sql_rev
node_n_prompt -->|"templates"| node_n_sql_rev
node_n_sql_rev -->|"exec feedback"| node_n_exec
node_n_sql_rev -->|"revised candidates"| node_n_sql_sel
node_n_sql_sel -->|"exec aware"| node_n_exec
node_n_services -->|"loads"| node_n_schema
node_n_services -->|"runs"| node_n_exec
node_n_services -->|"stores"| node_n_artifacts
node_n_exec -->|"adapts to"| node_n_cloud
node_n_runner -->|"exports"| node_n_results

click node_n_config "https://github.com/hkustdial/deepeye-sql/tree/master/config"
click node_n_runner "https://github.com/hkustdial/deepeye-sql/tree/master/runner"
click node_n_dataset "https://github.com/hkustdial/deepeye-sql/tree/master/app/dataset"
click node_n_artifacts "https://github.com/hkustdial/deepeye-sql/blob/master/app/dataset/artifacts.py"
click node_n_value "https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/value_retrieval"
click node_n_vector "https://github.com/hkustdial/deepeye-sql/tree/master/app/vector_db"
click node_n_schema_link "https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/schema_linking"
click node_n_sql_gen "https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_generation"
click node_n_prompt "https://github.com/hkustdial/deepeye-sql/tree/master/app/prompt"
click node_n_llm "https://github.com/hkustdial/deepeye-sql/tree/master/app/llm"
click node_n_extract "https://github.com/hkustdial/deepeye-sql/tree/master/app/llm_extractor"
click node_n_sql_rev "https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_revision"
click node_n_sql_sel "https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_selection"
click node_n_services "https://github.com/hkustdial/deepeye-sql/tree/master/app/services"
click node_n_schema "https://github.com/hkustdial/deepeye-sql/blob/master/app/db_utils/schema.py"
click node_n_exec "https://github.com/hkustdial/deepeye-sql/blob/master/app/db_utils/execution.py"
click node_n_results "https://github.com/hkustdial/deepeye-sql/tree/master/results"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_runner,node_n_dataset toneBlue
class node_n_artifacts,node_n_value,node_n_schema_link,node_n_sql_gen,node_n_sql_rev,node_n_sql_sel toneAmber
class node_n_config,node_n_vector,node_n_prompt,node_n_llm,node_n_extract,node_n_services,node_n_schema,node_n_exec toneMint
class node_n_cloud,node_n_results toneRose
```

## Components

### Ingestion

Benchmark data, preprocessing, and dataset snapshots

- [Runners](https://github.com/hkustdial/deepeye-sql/tree/master/runner): orchestration · Entry-point scripts for preprocessing, each pipeline stage, evaluation, and benchmarking · `runner`
- [Datasets](https://github.com/hkustdial/deepeye-sql/tree/master/app/dataset): benchmark prep · Central dataset handling for Spider, BIRD, and Spider2 snapshot preparation · `app/dataset`

### Pipeline

Snapshot-driven Text-to-SQL stages

- [Artifacts](https://github.com/hkustdial/deepeye-sql/blob/master/app/dataset/artifacts.py): snapshot store · Dataset artifact construction and persisted pipeline snapshots · `app/dataset/artifacts.py`
- [Value retrieval](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/value_retrieval): retrieval stage · Grounds question mentions to concrete database values using embeddings and vector lookup · `app/pipeline/value_retrieval`
- [Schema linking](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/schema_linking): linking stage · Refines schema context through direct, reversed, and value-based linkers · `app/pipeline/schema_linking`
- [SQL generation](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_generation): candidate stage · Produces diversified SQL candidates using skeleton, ICL, and domain-constrained generators · `app/pipeline/sql_generation`
- [SQL revision](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_revision): repair stage · Validates and repairs candidate SQL with syntax, join, aggregate, ordering, and result checks · `app/pipeline/sql_revision`
- [SQL selection](https://github.com/hkustdial/deepeye-sql/tree/master/app/pipeline/sql_selection): ranking stage · Chooses the final query from revised candidates using execution-aware comparison · `app/pipeline/sql_selection`

### Infra

LLM, execution, schema, and storage services

- [Config](https://github.com/hkustdial/deepeye-sql/tree/master/config): toml settings · External TOML configuration for datasets, paths, models, embeddings, and stage parameters · `config`
- [Vector DB](https://github.com/hkustdial/deepeye-sql/tree/master/app/vector_db): indexing · Local value index and embedding function used by retrieval · `app/vector_db`
- [Prompts](https://github.com/hkustdial/deepeye-sql/tree/master/app/prompt): templates · Prompt factory and templates used to steer generation and revision · `app/prompt`
- [LLM](https://github.com/hkustdial/deepeye-sql/tree/master/app/llm): model client · OpenAI-compatible model invocation layer · `app/llm`
- [Extractor](https://github.com/hkustdial/deepeye-sql/tree/master/app/llm_extractor): llm parsing · LLM extraction helper for structured outputs · `app/llm_extractor`
- [Services](https://github.com/hkustdial/deepeye-sql/tree/master/app/services): runtime boundary · Coordinates persisted artifacts, schema lookup, execution, and bounded cache · `app/services`
- [Schema utils](https://github.com/hkustdial/deepeye-sql/blob/master/app/db_utils/schema.py): schema metadata · Loads schema metadata for local and cloud-backed databases · `app/db_utils/schema.py`
- [Execution utils](https://github.com/hkustdial/deepeye-sql/blob/master/app/db_utils/execution.py): sql execution · Executes SQL against benchmark databases and cloud adapters · `app/db_utils/execution.py`

### Outputs

Released SQL and benchmark artifacts

- **Cloud DBs**: spider2 backend · Spider2 cloud-backed execution targets such as BigQuery and Snowflake
- [Results](https://github.com/hkustdial/deepeye-sql/tree/master/results): released outputs · Published SQL outputs and benchmark result files · `results`

## Connections

- 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
