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.
翻译:文本到SQL已成为一个重要的研究领域,特别是在大语言模型快速发展的背景下。该技术使用户能够通过自然语言而非SQL查询数据库,显著降低了数据分析的门槛。然而,由于用户查询的歧义性、模式链接的复杂性、跨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(基于精炼-评判-行动-规划智能体的SQL框架),以应对日益复杂的企业数据库和现实世界文本到SQL任务。该框架集成了多个专门智能体,分别负责规划、外部知识检索、评判、行动生成、自我精炼、模式链接和结果验证,通过智能体协作实现SQL预测的迭代精炼。ReCAPAgent-SQL的加权多数投票结果在Spider 2.0-Lite的前100个查询上实现了31%的执行准确率,在处理现实企业场景方面展现出显著改进。总体而言,我们的工作促进了可扩展文本到SQL系统在实际环境中的部署,以更低的成本和更高的效率支持更好的数据驱动决策。