Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

225 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ADAPT-SQL

Adaptive Decomposed And Pipeline-driven Text-to-SQL

Execution Accuracy License Python Ollama

A state-of-the-art Text-to-SQL generation system achieving 93.7% Execution Accuracy on the Spider benchmark using a fully local LLM pipeline.


Results

Performance on Spider Benchmark

Metric Score
Execution Accuracy (EX) 93.7%
Exact-Set-Match (EM) 35.6%
Valid SQL Rate 100%
Execution Success 99.3%

Comparison with State-of-the-Art

Rank Method Model Spider EX Cost/Query
1 ADAPT-SQL Qwen3-Coder (Local) 93.7% $0.00
2 MiniSeek - 91.2% -
3 DAIL-SQL + GPT-4 GPT-4 86.6% ~$0.12
4 DIN-SQL + GPT-4 GPT-4 85.3% ~$0.15
5 RESDSQL Fine-tuned T5 84.1% N/A
6 C3-SQL GPT-4 82.3% ~$0.10

Performance by Query Complexity

Complexity Queries Execution Accuracy
EASY 283 96.1%
NON_NESTED_COMPLEX 596 93.8%
NESTED_COMPLEX 121 88.4%

Architecture

ADAPT-SQL implements an 11-step pipeline that systematically transforms natural language into SQL:

thumbnail-text2sql

Key Innovations

1. Three-Layer Schema Linking

A multi-stage approach that reduces schema errors by 40%:

Layer 1: String Matching     →  High Recall (fuzzy token matching)
Layer 2: LLM Analysis        →  High Precision (semantic understanding)
Layer 3: Post-Validation     →  Error Correction (connectivity check)
Layer Avg Tables Avg Columns Purpose
Layer 1 (String) 4.2 18.3 Cast wide net
Layer 2 (LLM) 2.8 9.1 Focus selection
Layer 3 (Validation) 2.3 6.2 Final pruning

2. Adaptive Complexity Routing

Automatic classification routes queries to specialized generators:

Complexity Characteristics Strategy Accuracy
EASY Single table, basic WHERE Few-Shot 96.1%
NON_NESTED_COMPLEX JOINs, GROUP BY, aggregations NatSQL Intermediate 93.8%
NESTED_COMPLEX Subqueries, EXCEPT, correlated Decomposed Generation 88.4%

3. DAIL-SQL Structural Reranking

Enhanced example selection combining multiple similarity dimensions:

Combined Score = 0.5 × Semantic + 0.3 × Structural + 0.2 × Style

4. Validation-Feedback Retry

Automated error correction recovers 15%+ of initially incorrect predictions:

Retry Count Queries EX Before EX After Improvement
0 812 94.2% 94.2% -
1 142 78.3% 91.5% +13.2%
2 46 65.2% 84.8% +19.6%

Ablation Studies

Configuration EX Impact
Full ADAPT-SQL 93.7% -
w/o Three-Layer Schema Linking 87.2% -6.5%
w/o Structural Reranking 88.9% -4.8%
w/o NatSQL Intermediate 89.4% -4.3%
w/o Validation-Feedback Retry 91.1% -2.6%
w/o Rule-Based Complexity 92.1% -1.6%
w/o SQL Normalization 92.8% -0.9%

Quick Start

Prerequisites

# Install Ollama and required models
ollama pull qwen3-coder       # Primary LLM
ollama pull nomic-embed-text  # Embeddings

Installation

# Clone repository
git clone https://github.com/yourusername/adapt-sql.git
cd adapt-sql

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Build vector store (first time only)
python utils/vector_store.py

Usage

Python API

from core.adapt_baseline import ADAPTBaseline

# Initialize pipeline
adapt = ADAPTBaseline(
    model="qwen3-coder",
    vector_store_path="./vector_store",
    enable_sql_normalization=True,
    enable_structural_reranking=True
)

# Generate SQL
result = adapt.run_full_pipeline(
    natural_query="Find students with GPA higher than average",
    schema_dict=schema,
    foreign_keys=foreign_keys,
    enable_retry=True,
    enable_execution=True,
    db_path="path/to/database.db",
    gold_sql=ground_truth_sql
)

print(f"Generated SQL: {result['final_sql']}")
print(f"Execution Accuracy: {result['step11']['execution_accuracy']}")

Interactive UI

# Main interface
streamlit run ui/app.py

# Batch evaluation
streamlit run ui/pages/batch_processing.py

Project Structure

adapt-sql/
├── core/
│   └── adapt_baseline.py          # Main pipeline orchestrator
├── pipeline/
│   ├── schema_linking.py          # Step 1: Three-layer schema linking
│   ├── query_complexity.py        # Step 2: Complexity classification
│   ├── prel_sql_prediction.py     # Step 3: Preliminary SQL
│   ├── vector_search.py           # Step 4: Example retrieval
│   ├── routing_strategy.py        # Step 5: Strategy routing
│   ├── few_shot.py                # Step 6a: Simple queries
│   ├── intermediate_repr.py       # Step 6b: NatSQL generation
│   ├── decomposed_generation.py   # Step 6c: Nested queries
│   ├── validate_sql.py            # Step 7: SQL validation
│   ├── validation_feedback_retry.py # Step 8: Error retry
│   ├── sql_normalizer.py          # Step 9: Normalization
│   ├── execute_compare.py         # Step 10: Execution
│   └── evaluation.py              # Step 11: Metrics
├── utils/
│   ├── vector_store.py            # FAISS index management
│   ├── structural_similarity.py   # DAIL-SQL reranking
│   ├── fuzzy_schema_validator.py  # Fuzzy name matching
│   └── rule_based_complexity.py   # Rule-based classification
├── ui/
│   ├── app.py                     # Interactive Streamlit UI
│   └── pages/
│       ├── batch_processing.py    # Dataset evaluation
│       └── multimodel.py          # Model comparison
├── data/                          # Spider dataset
└── vector_store/                  # FAISS embeddings

Configuration

Parameter Default Description
model qwen3-coder Ollama model for generation
max_retries 2 Validation retry attempts
execution_timeout 30s SQL execution timeout
enable_sql_normalization True Post-generation formatting
enable_structural_reranking True DAIL-SQL style reranking
schema_linking_table_threshold 0.6 Fuzzy match threshold
validation_fuzzy_threshold 0.7 Correction suggestion threshold

Requirements

faiss-cpu
numpy
pandas
streamlit
ollama
plotly
sqlparse

Citation

If you use ADAPT-SQL in your research, please cite:

@software{adapt_sql_2026,
  title = {ADAPT-SQL: Adaptive Decomposed And Pipeline-driven Text-to-SQL},
  author = {More, Sidessh},
  year = {2026},
  url = {https://github.com/sidesshmore/ADAPT-SQL-Text2SQL}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.


Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages