arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.02055cs.DB
收藏

MageSQL:利用大语言模型增强Text-to-SQL应用的上下文学习

MageSQL: Enhancing In-context Learning for Text-to-SQL Applications with Large Language Models

Chen Shen, Jin Wang, Sajjadur Rahman, Eser Kandogan

AI总结:

提出MageSQL,一种基于LLM上下文学习的Text-to-SQL方法,通过结合SQL特定数据增强策略的图对比学习选择少样本示例,并引入错误纠正模块,在多个基准数据集上显著优于现有方法。

摘要:

Text-to-SQL问题旨在将自然语言问题转化为SQL语句,以简化数据库系统与终端用户之间的交互。近期,大语言模型(LLM)在包括Text-to-SQL在内的多种任务中展现出卓越的能力。尽管已有研究探索了多种提示LLM生成SQL语句的策略,但由于缺乏(1)构建提示时的高质量上下文信息,以及(2)纠正翻译错误的鲁棒反馈机制,它们仍未能充分利用LLM的能力。为应对这些挑战,我们提出了MageSQL,一种基于LLM上下文学习的Text-to-SQL方法。MageSQL探索了一系列技术,利用SQL查询的语法和语义来识别相关的少样本示例,作为提示LLM的上下文。具体而言,我们引入了一种基于图的示例选择方法——这是Text-to-SQL问题中首创的方法——该方法利用了结合SQL特定数据增强策略的图对比学习。此外,还提出了一个错误纠正模块,用于检测并修复生成SQL查询中的潜在不准确之处。我们在多个基准数据集上进行了全面评估。结果表明,我们提出的方法以明显优势优于现有最先进的方法。

英文摘要:

The text-to-SQL problem aims to translate natural language questions into SQL statements to ease the interaction between database systems and end users. Recently, Large Language Models (LLMs) have exhibited impressive capabilities in a variety of tasks, including text-to-SQL. While prior works have explored various strategies for prompting LLMs to generate SQL statements, they still fall short of fully harnessing the power of LLM due to the lack of (1) high-quality contextual information when constructing the prompts and (2) robust feedback mechanisms to correct translation errors. To address these challenges, we propose MageSQL, a text-to-SQL approach based on in-context learning over LLMs. MageSQL explores a suite of techniques that leverage the syntax and semantics of SQL queries to identify relevant few-shot demonstrations as context for prompting LLMs. In particular, we introduce a graph-based demonstration selection method -- the first of its kind in the text-to-SQL problem -- that leverages graph contrastive learning adapted with SQL-specific data augmentation strategies. Furthermore, an error correction module is proposed to detect and fix potential inaccuracies in the generated SQL query. We conduct comprehensive evaluations on several benchmarking datasets. The results show that our proposed methods outperform state-of-the-art methods by an obvious margin.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑