MEM-SQL: Memory-Empowered Text-to-SQL

Xiaoqi Wang, Wenqi Pei, Shizheng Hou, Yilai Liu, Han Chen, Boyan Li, Yuyu Luo, Hongyang Du

The University of Hong Kong · National University of Singapore · The Hong Kong University of Science and Technology (Guangzhou)

Published November 13, 2026 · on the feed November 16, 2026 · ▲ 18 · arXiv 2611.18338

The abstract

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.

The Brief

3:21

A short podcast summary of the paper. Written and voiced by AI.

Transcript

MEM-SQL. Memory-Empowered Text-to-SQL. By Xiaoqi Wang and seven others, from the University of Hong Kong, the National University of Singapore, and one other institution. Published on the thirteenth of November.

Text-to-SQL systems translate natural language questions into SQL queries, and the databases they work over keep getting more complex. The benchmarks widely used to evaluate them treat each question independently. That overlooks a common situation. When earlier queries have already been run over the same database, they may supply the joins or calculations that a new question needs. A system that starts from scratch every time does that work again, and nothing in the standard evaluation measures whether reusing the earlier queries would have been more accurate or cheaper.

The paper contributes two things. The first is a way to measure the setting. HARE, the History-Aware Text-to-SQL Benchmark, measures both the accuracy and the cost of adapting historical SQL. It comprises one thousand six hundred requests, derived from a fixed pool of eight hundred and twenty-three verified queries across four datasets. Its annotations record which components each request preserves and which edits it requires, so whole-query adaptation can be told apart from partial reuse. The second contribution is the system itself, MEM-SQL, short for Memory-Empowered Text-to-SQL, which treats verified history as memory.

That memory has layers. It stores whole-query templates, reusable SQL blocks, and mappings from domain concepts to schema elements. Using a layer is strict: MEM-SQL uses a layer only if every requirement assigned to it has a match above that layer's threshold. A layer that matches only some of its requirements is not used. On top of this sits On-demand Schema Linking, or OSL. MEM-SQL consults the database schema only in two cases: when no memory layer qualifies, or when the generator judges the evidence it retrieved to be insufficient. The schema becomes a fallback rather than a fixed step.

Across six language models on HARE, mean execution accuracy rises from thirty-seven point one percent for Direct Generation without history, to fifty percent for MEM-SQL. That comes with seventy-six point six percent fewer input tokens, and sixty-eight point eight percent lower latency, on average.

The analysis also locates where the approach struggles. Requests that reuse several verified queries remain a bottleneck, with accuracy falling from fifty-six point seven percent to twenty-nine point seven percent. The drop is sharpest when the reused components must be placed in a new query structure, or combined with a shared join. Separately, OSL was applied to three other memory designs. It consistently reduced generation cost, while its accuracy benefit depended on the memory design it was paired with.

The conclusion the authors draw has two halves. Verified history can make generation both more accurate and cheaper, which is the headline. But its value depends on the evidence the memory retains, and on when the system chooses to consult the schema. Memory here is not a single switch to turn on. It is a set of decisions about what to keep, how strictly to match it, and when to look elsewhere.

More with an account

Listen to every day’s papers

Daily playlists, deep dives, quests for the papers, and quizzes on their key terms.

Join free
KipQuest: the day’s AI research, as podcasts and quests. All papers Android app Privacy Contact Episodes are written and voiced by AI from each paper. Summaries can contain mistakes: the paper is the source.