用查询模板提升文本转SQL准确率,解决复杂数据库查询难题
Reliable Answers for Recurring Questions: Boosting Text-to-SQL Accuracy with Template Constrained Decoding

- 将历史查询转化为可复用模板,匹配新问题并约束生成
- 相比上下文学习提升36%执行准确率,匹配查询延迟降低2.2倍
- 适合需要高可靠性的企业级数据库查询系统
大型语言模型(LLMs)已革新文本转SQL生成,使用户能以自然语言查询结构化数据。然而,在真实部署中仍面临挑战,尤其在复杂或未见模式的数据库上,存在准确率不稳和生成无效SQL的风险。本文提出模板约束解码(TeCoD),利用标注工作负载中查询模式的重复性。TeCoD将历史自然语言-SQL对转换为可复用模板,并引入基于微调自然语言推理模型的模板选择模块,高效匹配或排除查询。选定模板后,通过新颖的分段策略实现语法约束解码,确保生成语句的语法正确性和效率。该方法在匹配查询上相较上下文学习(ICL)提升最高36%的执行准确率,且延迟降低2.2倍。
原文摘要 · Abstract (English)
Large language models (LLMs) have revolutionized Text-to-SQL generation, allowing users to query structured data using natural language with growing ease. Yet, real-world deployment remains challenging, especially in complex or unseen schemas, due to inconsistent accuracy and the risk of generating invalid SQL. We introduce Template Constrained Decoding (TeCoD), a system that addresses these limitations by harnessing the recurrence of query patterns in labeled workloads. TeCoD converts historical NL-SQL pairs into reusable templates and introduces a robust template selection module that uses a fine-tuned natural language inference model to match or reject queries efficiently. Once the template is selected, TeCoD enforces it during SQL generation through grammar-constrained decoding, implemented via a novel partitioned strategy that ensures both syntactic validity and efficiency. Together, these components yield up to 36% higher execution accuracy than in-context learning (ICL) and 2.2x lower latency on matched queries.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。