用自反思与投票机制提升大模型生成SQL的准确性。
LLM-Based SQL Generation: Prompting, Self-Refinement, and Adaptive Weighted Majority Voting
- 采用自反思与加权投票融合的单代理框架,无需标注数据
- 在Spider和BIRD数据集上分别达到85.5%和66.3%执行准确率
- 适合企业级数据库复杂查询场景,支持可扩展部署
文本转SQL已成为重要研究方向,尤其得益于大语言模型(LLM)的快速发展。该技术使用户可通过自然语言查询数据库,降低数据分析门槛。然而,由于查询歧义、模式链接复杂、跨SQL方言泛化能力有限及领域知识需求,准确生成SQL仍具挑战。本文提出基于PET-SQL的单代理自反思与集成投票(SSEV)流水线,不依赖真实标签数据,融合自反思与加权多数投票(WMV)及其随机变体(RWMA)。实验表明,SSEV在多个基准上表现优异:Spider 1.0-Dev上达85.5%,Spider 1.0-Test上达86.4%,BIRD-Dev上达66.3%。基于SSEV洞察,进一步提出ReCAPAgent-SQL(基于反思-批判-行动-规划的代理框架),整合多个专用代理完成规划、外部知识检索、批判、动作生成、自反思、模式链接与结果验证,实现通过代理协作的迭代优化。其WMA方法在Spider 2.0-Lite前100个查询中取得31%执行准确率,显著提升对真实企业场景的处理能力。整体工作推动了可扩展文本转SQL系统在实际场景中的落地,支持更低成本、更高效率的数据驱动决策。
原文摘要 · Abstract (English)
Text-to-SQL has emerged as a prominent research area, particularly with the rapid advancement of large language models (LLMs). By enabling users to query databases through natural language rather than SQL, this technology significantly lowers the barrier to data analysis. However, generating accurate SQL from natural language remains challenging due to ambiguity in user queries, the complexity of schema linking, limited generalization across SQL dialects, and the need for domain-specific understanding. In this study, we propose a Single-Agent Self-Refinement with Ensemble Voting (SSEV) pipeline built on PET-SQL that operates without ground-truth data, integrating self-refinement with Weighted Majority Voting (WMV) and its randomized variant (RWMA). Experimental results show that the SSEV achieves competitive performance across multiple benchmarks, attaining execution accuracies of 85.5% on Spider 1.0-Dev, 86.4% on Spider 1.0-Test, and 66.3% on BIRD-Dev. Building on insights from the SSEV pipeline, we further propose ReCAPAgent-SQL (Refinement-Critique-Act-Plan agent-based SQL framework) to address the growing complexity of enterprise databases and real-world Text-to-SQL tasks. The framework integrates multiple specialized agents for planning, external knowledge retrieval, critique, action generation, self-refinement, schema linking, and result validation, enabling iterative refinement of SQL predictions through agent collaboration. ReCAPAgent-SQL's WMA results achieve 31% execution accuracy on the first 100 queries of Spider 2.0-Lite, demonstrating significant improvements in handling real-world enterprise scenarios. Overall, our work facilitates the deployment of scalable Text-to-SQL systems in practical settings, supporting better data-driven decision-making at lower cost and with greater efficiency.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。