用图算法高效链接数据库模式,提升大库文本转SQL准确率
SchemaGraphSQL: Efficient Schema Linking with Pathfinding Graph Algorithms for Text-to-SQL on Large-Scale Databases
- 构建外键关联的模式图,通过路径搜索定位表列连接顺序
- 在BIRD基准上超越复杂微调模型,零训练下达顶尖性能
- 适合需要快速部署、低资源消耗的生产级文本转SQL系统
文本转SQL系统将自然语言问题转化为可执行SQL查询,近年来大语言模型(LLMs)的进步显著提升了该任务性能。模式链接仍是关键环节,能减少模型上下文窗口受限时的提示长度,并增强模型聚焦能力。本文提出一种零样本、无需训练的模式链接方法:首先基于外键关系构建模式图,再用单个提示输入Gemini 2.5 Flash提取用户问题中的源表与目标表,随后应用经典路径查找算法及后处理,确定最优的表与列连接序列,使LLM生成更准确的SQL。尽管方法简单、成本低且高度可扩展,本方法在BIRD基准上仍达到最先进水平,优于以往专门设计、微调过的多步LLM方法。我们进行了详细的消融实验,分析框架中的精确率-召回率权衡。此外,还评估了不同模型规模下本方法的执行准确率,相较于其他方案表现更优。
原文摘要 · Abstract (English)
Text-to-SQL systems translate natural language questions into executable SQL queries, and recent progress with large language models (LLMs) has driven substantial improvements in this task. Schema linking remains a critical component in Text-to-SQL systems, reducing prompt size for models with narrow context windows and sharpening model focus even when the entire schema fits. We present a zero-shot, training-free schema linking approach that first constructs a schema graph based on foreign key relations, then uses a single prompt to Gemini 2.5 Flash to extract source and destination tables from the user query, followed by applying classical path-finding algorithms and post-processing to identify the optimal sequence of tables and columns that should be joined, enabling the LLM to generate more accurate SQL queries. Despite being simple, cost-effective, and highly scalable, our method achieves state-of-the-art results on the BIRD benchmark, outperforming previous specialized, fine-tuned, and complex multi-step LLM-based approaches. We conduct detailed ablation studies to examine the precision-recall trade-off in our framework. Additionally, we evaluate the execution accuracy of our schema filtering method compared to other approaches across various model sizes.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。