让大模型先选对数据库再生成SQL,提升非技术用户查询准确率。
End-to-End Text-to-SQL with Dataset Selection: Leveraging LLMs for Adaptive Query Generation
- 用大模型从自然语言中提取规则,辅助判断用户要查哪个数据库。
- 在多个数据库场景下,数据库识别准确率和SQL生成效果均超越现有方法。
- 适合需要跨库查询、想用大模型自动补全复杂语义的开发者和数据工程师。
文本到SQL任务将自然语言查询转化为结构化数据库命令,使非技术人员也能轻松访问数据。传统方法将该任务视为直接翻译,但所有现有方案都要求目标数据库预先指定。当存在多个大型数据库时,确定正确数据库成为关键却常被忽视的步骤。本文提出一种三阶段端到端文本到SQL框架:首先利用大模型与提示工程,从自然语言查询(NLQ)中提取隐含规则;接着训练一个基于RoBERTa微调编码器的数据库标识预测模型,结合原始查询与生成规则预测正确的db_id;最后通过批评者代理修正生成的SQL错误。实验表明,该框架在数据库意图识别和SQL生成准确率上均优于当前最优模型。
原文摘要 · Abstract (English)
Text-to-SQL bridges the gap between natural language and structured database language, thus allowing non-technical users to easily query databases. Traditional approaches model text-to-SQL as a direct translation task, where a given Natural Language Query (NLQ) is mapped to an SQL command. Recent advances in large language models (LLMs) have significantly improved translation accuracy, however, these methods all require that the target database is pre-specified. This becomes problematic in scenarios with multiple extensive databases, where identifying the correct database becomes a crucial yet overlooked step. In this paper, we propose a three-stage end-to-end text-to-SQL framework to identify the user's intended database before generating SQL queries. Our approach leverages LLMs and prompt engineering to extract implicit information from natural language queries (NLQs) in the form of a ruleset. We then train a large db\_id prediction model, which includes a RoBERTa-based finetuned encoder, to predict the correct Database identifier (db\_id) based on both the NLQ and the LLM-generated rules. Finally, we refine the generated SQL by using critic agents to correct errors. Experimental results demonstrate that our framework outperforms the current state-of-the-art models in both database intent prediction and SQL generation accuracy.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。