Chiosa
Search & Data

Verified query history improves Text-to-SQL accuracy

MEM-SQL: Memory-Empowered Text-to-SQL · arXiv:2611.18338

2 min
Updated
HARE construction with a live example that combines structural changes and shared joins.
HARE construction with a live example that combines structural changes and shared joins.Figure 2 · MEM-SQL: Memory-Empowered Text-to-SQL · Xiaoqi Wang et al. · CC BY 4.0

In plain words

The paper introduces MEM-SQL, a method for writing SQL from natural-language requests. It keeps verified question-and-SQL examples from the same database, storing whole queries, reusable parts, and facts about the database’s columns and relationships.

When a new request arrives, MEM-SQL checks whether its stored examples cover what the request needs. On the HARE test, its average accuracy across six language models was higher than generating SQL without history, while using fewer input tokens and less time.

The research

For a database queried repeatedly, a new request may not need SQL rebuilt from scratch: earlier verified work can help, but a query that still runs may encode logic that no longer fits.

These results make query history worth testing as a source of guidance, while keeping accuracy on requests that combine several sources in view.

MEM-SQL organizes verified SQL history into reusable levels and checks whether retrieved evidence covers a new request before generating SQL.

On HARE, a test designed for requests that reuse whole queries, parts of queries, or schema knowledge, the authors compared MEM-SQL with direct generation without history across six language models. Execution accuracy counted requests whose SQL returned the reference result.

MEM-SQL averaged 50.0% versus 37.1%, while also using 76.6% fewer input tokens and 68.8% less latency on average. The result supports a benefit in this test, though the averages do not describe every model.

HARE keeps the memory fixed and does not test changing database schemas. Execution accuracy can reject answers that differ only in format and cannot tell whether correct rows came from the intended reasoning.

What the evidence shows

  • A test for query reuse

    MEM-SQL is a Text-to-SQL method that uses verified query history to answer new requests. HARE tests whether systems can reuse that history when a request retains a whole query, part of one, or schema knowledge.

    Tests that treat every question independently miss cases where earlier verified SQL could supply some of the needed computation.

  • Accuracy rose on average

    On HARE, execution accuracy measures the share of requests for which generated SQL returns the reference result. Averaged across six language models, MEM-SQL reached 50.0% execution accuracy, compared with 37.1% for direct generation without history.

    This comparison supports the conclusion that using verified history improved the average result in this test, though the mean does not describe every model or request.

  • Combining sources is harder

    The advantage was smaller on requests that required combining multiple historical sources. Across all six evaluated model backbones, accuracy on multiple-source requests was at least 21.7 percentage points below accuracy on one-source requests.

    The comparison locates a difficulty in composing evidence from several queries, while not showing what caused the lower accuracy.

  • Retrieval does not ensure accuracy

    A structural-change group makes the distinction between retrieval and successful SQL especially clear: MEM-SQL retrieved all required sources for 90.8% of those requests, but execution accuracy was 9.9%. Thus, finding the relevant earlier queries was not enough to produce correct SQL in this group.

    The result bounds the broader accuracy gain, particularly for requests that combine historical computations.

Deep

Next paperTraining retrievers on their own search histories