Abstract
XiYan-SQL represents a significant advancement in the Text-to-SQL domain, shifting the paradigm from simple prompt engineering toward a robust ensemble of specialized, fine-tuned models. By integrating an iterative schema filter, a multi-task generator ensemble, and a sophisticated candidate selection model, XiYan-SQL achieves record-breaking performance on the BIRD (75.63%) and Spider (89.65%) benchmarks.
Introduction
Translating natural language into SQL (Text-to-SQL) is a cornerstone of democratizing data access. However, Large Language Models (LLMs) often struggle with complex, real-world databases due to three primary hurdles: schema noise, a lack of candidate diversity, and selection failure. Current "In-Context Learning" (ICL) methods, while flexible, frequently lack the robustness required for large-scale schemas where hundreds of irrelevant columns can distract the model. XiYan-SQL addresses these challenges through a structured three-stage pipeline designed to maximize both precision and recall in query generation.
The XiYan-SQL Framework
The framework operates through a sequential pipeline that refines the database schema, generates a diverse set of SQL candidates, and selects the optimal query based on execution consistency and model reliability.
1. Schema Filter
To mitigate the "distraction" caused by irrelevant database columns, XiYan-SQL employs a multi-path retrieval system using keyword extraction and embedding similarity. A key innovation is the Iterative Column Selection algorithm. Instead of a single pass, this module generates multiple distinct "views" of the schema. This iterative approach ensures that the model is exposed to various potential table and column combinations, significantly increasing the likelihood that the correct schema elements are included in at least one candidate generation path.
2. Multiple SQL Generation
Rather than relying on a single prompt or model, XiYan-SQL utilizes Supervised Fine-Tuning (SFT) on high-performance models like Qwen2.5-Coder. Two core strategies are employed to ensure the quality and diversity of the candidate pool:
- Multi-task Joint Fine-tuning: The model is trained on auxiliary tasks, such as inferring the original question from a SQL query (reverse inference) or identifying relevant evidence. This bidirectional training strengthens the semantic mapping between natural language and code, acting as a powerful regularizer.
- Multi-format Enhancement: Different generators are trained to produce SQL in various "writing styles" (e.g., modular CTEs vs. standard joins). This ensures that the candidate pool is not just large, but diverse in its logic and presentation.
3. SQL Selection with Candidate Reorganization
The final stage involves a specialized selection model (Qwen2.5-Coder-7B). To overcome the "order bias" common in LLMs—where models favor the first options presented—XiYan-SQL implements a reorganization strategy. Candidates are grouped by their execution results and sorted by group size and generator reliability. This effectively guides the selector's attention toward the most consistent and high-quality answers rather than relying on simple majority voting.
Experimental Results
XiYan-SQL was evaluated on the BIRD and Spider benchmarks, the two most rigorous standards in the field. On the BIRD test set, it achieved a state-of-the-art (SOTA) Execution Accuracy (EX) of 75.63%, outperforming previous leaders like CHASE-SQL and DSAIR.
Ablation studies confirm the necessity of each component. Removing the Schema Filter resulted in a 1.24% performance drop, while relying on a single generator instead of the ensemble caused a significant 4% decline. Furthermore, the framework maintains practical efficiency, with an end-to-end latency of approximately 40.5 seconds for generating and selecting from 10 candidates, making it viable for enterprise applications.
Conclusion
XiYan-SQL demonstrates that the key to solving complex Text-to-SQL tasks lies in the synergy between specialized fine-tuning and structured ensemble strategies. By treating SQL generation as a multi-task, multi-view problem, the framework achieves unprecedented accuracy and robustness. Future work will focus on integrating these capabilities into a unified "all-in-one" architecture to further reduce latency and enhance cognitive reasoning.
Summary updated