MEM-SQL:记忆增强的文本到SQL

·

研究论文 · 2026/11/16

Text-to-SQL系统将自然语言问题转换为SQL查询,但现有基准独立评估问题,忽略了历史查询可提供连接或计算信息的场景。本文提出HARE基准(包含1600个请求,源自823个已验证查询)来衡量适应历史SQL的准确性和成本,并记录每个请求保留和编辑的组件。作者提出MEM-SQL方法,存储整查询模板、可重用SQL块和领域概念到模式元素的映射,仅当某层所有需求匹配超过阈值时才使用该层,并采用按需模式链接(OSL)在无层合格或证据不足时查询模式。在HARE上对六个语言模型评估,MEM-SQL平均执行准确率从37.1%提升至50.0%,输入令牌减少76.6%,延迟降低68.8%。分析显示重用多个已验证查询的请求仍是瓶颈,准确率从56.7%降至29.7%,尤其在需要将重用组件放入新查询结构或与共享连接结合时。将OSL应用于其他三种记忆设计可一致降低生成成本,但准确率收益取决于记忆设计。

该研究针对Text-to-SQL中历史查询利用的空白,提出了首个评估基准和有效方法,在提升准确率的同时大幅降低计算成本,对实际数据库查询系统有重要价值。

Text-to-SQL systems translate natural language questions into SQL queries over increasingly complex databases. However, widely used benchmarks evaluate questions independently, overlooking settings where earlier queries over the same database can supply joins or calculations for a new question. We introduce HARE (History-AwaRe Text-to-SQL BEnchmark) to measure the accuracy and cost of adapting historical SQL. HARE comprises 1,600 requests derived from a fixed pool of 823 verified queries across four datasets. Annotations record which components each request preserves and which edits it requires, distinguishing whole-query adaptation from partial reuse. Our method, MEM-SQL (Memory-EMpowered Text-to-SQL), stores whole-query templates, reusable SQL blocks, and mappings from domain concepts to schema elements. MEM-SQL uses a layer only if every requirement assigned to it has a match above that layer's threshold. With On-demand Schema Linking (OSL), MEM-SQL consults the schema only when no layer qualifies or the generator judges retrieved evidence insufficient. Across six language models on HARE, mean execution accuracy rises from 37.1% for Direct Generation without history to 50.0% for MEM-SQL, with 76.6% fewer input tokens and 68.8% lower latency on average. Further analysis shows that requests reusing several verified queries remain a bottleneck, with accuracy falling from 56.7% to 29.7%, most sharply when reused components must be placed in a new query structure or combined with a shared join. Applying OSL to three other memory designs consistently reduces generation cost, while its accuracy benefit depends on the memory design. Verified history can thus make generation both more accurate and cheaper, but its value depends on the evidence retained and when the system consults the schema.

阅读原文

参与讨论