Text-to-SQL generation aims to translate natural language questions into SQL statements. In large language models (LLMs) based Text-to-SQL, schema linking is a widely adopted strategy to streamline the input for LLMs by selecting only relevant schema elements, therefore reducing noise and computational overhead. However, schema linking faces risks that requires caution, including the potential omission of necessary elements and disruption of database structural integrity. To address these challenges, we propose a novel framework called RSL-SQL that combines bidirectional schema linking, contextual information augmentation, binary selection strategy, and multi-turn self-correction. Our approach improves the recall of schema linking through forward and backward pruning and hedges the risk by voting between full schema and contextual information augmented simplified schema. Experiments on the BIRD and Spider benchmarks demonstrate that our approach achieves state-of-the-art execution accuracy among open-source solutions, with 67.2% on BIRD and 87.9% on Spider using GPT-4o. Furthermore, our approach outperforms a series of GPT-4 based Text-to-SQL systems when adopting DeepSeek (much cheaper) with same intact prompts. Extensive analysis and ablation studies confirm the effectiveness of each component in our framework. The codes are available at https://github.com/Laqcce-cao/RSL-SQL.
翻译:文本到SQL生成旨在将自然语言问题翻译为SQL语句。在基于大语言模型(LLM)的文本到SQL任务中,模式链接是一种广泛采用的策略,通过仅选择相关的模式元素来精简LLM的输入,从而减少噪声和计算开销。然而,模式链接面临着需要谨慎对待的风险,包括可能遗漏必要元素以及破坏数据库结构完整性。为应对这些挑战,我们提出了一个名为RSL-SQL的新框架,该框架结合了双向模式链接、上下文信息增强、二元选择策略和多轮自我校正。我们的方法通过前向和后向剪枝提高了模式链接的召回率,并通过在全模式与上下文信息增强的简化模式之间进行投票来对冲风险。在BIRD和Spider基准测试上的实验表明,我们的方法在开源解决方案中实现了最先进的执行准确率,使用GPT-4o时在BIRD上达到67.2%,在Spider上达到87.9%。此外,当采用DeepSeek(成本低得多)并保持相同完整提示时,我们的方法优于一系列基于GPT-4的文本到SQL系统。广泛的分析和消融研究证实了我们框架中每个组件的有效性。代码可在 https://github.com/Laqcce-cao/RSL-SQL 获取。