Back to Feed
Agents / Benchmarks & Evals

Improving Text-to-SQL with Reusable Memory

Original: From Test-Time Scaling to Reusable Memory: Measuring Crystallization in Text-to-SQL

Listen to the summary

Uses a voice available on your device

Audio options
On this page 5 sections
Related concepts 1 concepts

Key Takeaways

  • Using verified memory improves held-out first-attempt accuracy by 4.34 percentage points on the BIRD dataset.
  • The approach captures 44.4% of the accuracy potential available through on-demand execution-guided repair.
  • Increasing the retrieval volume from one to ten memory cards provides a 3.18 percentage point gain in accuracy.
  • Richer card formats do not currently offer a proven advantage over standard verbatim memory cards.

Summary & Methodology Analysis

The researchers addressed the crystallization problem, which evaluates how verified test-time repairs generate value for subsequent unseen queries. The pipeline functions by capturing interaction traces, including the initial solver attempt and the final corrected SQL, as tuples in a database-specific memory bank. This bank acts as an external knowledge store where an oracle provides a correctness signal to validate entries. When a new query arrives, the system retrieves top-k relevant memory cards based on question-to-question cosine similarity, which are then used to augment the prompt for the model in a one-shot inference configuration. This process allows the system to build a persistent repository of successful fixes that the model leverages during subsequent request handling.

Interactive System Flowchart

Click diagram to expand and zoom

Illustrative Implementation

A short sketch of the paper's core idea, not the authors' own code.

# Illustrative sketch (not from the paper)
import torch
from torch.nn.functional import cosine_similarity

# Placeholder single-shot solver
def solve_one_shot(question):
    # returns initial SQL attempt (string)
    return "SELECT * FROM table WHERE ..."

# Execution‑guided repair loop (simplified)
def repair(sql, db):
    # pretend we get feedback and fix the query
    return sql.replace("...", "condition")

# Create an episode tuple
def make_episode(question, attempt, corrected, trace):
    return {
        "q": question,
        "attempt": attempt,
        "corrected": corrected,
        "trace": trace,
    }

# Memory bank per database (in‑memory list)
memory_bank = []

def add_to_memory(episode, correct_signal=True):
    # oracle correctness signal decides admission
    if correct_signal:
        memory_bank.append(episode)

# Simple card writing (verbatim storage)
def write_card(episode):
    return episode["corrected"]

# Retrieve top‑k cards by cosine similarity of question embeddings
def retrieve_cards(question, k=5):
    # dummy embedding: random vector (replace with real encoder)
    q_emb = torch.randn(1, 768)
    scores = []
    for ep in memory_bank:
        ep_emb = torch.randn(1, 768)  # placeholder for stored question embedding
        sim = cosine_similarity(q_emb, ep_emb).item()
        scores.append((sim, write_card(ep)))
    scores.sort(reverse=True, key=lambda x: x[0])
    return [card for _, card in scores[:k]]

# Example workflow
question = "How many orders were placed in 2023?"
first_attempt = solve_one_shot(question)
corrected = repair(first_attempt, db=None)
trace = "execution feedback"
episode = make_episode(question, first_attempt, corrected, trace)
add_to_memory(episode)
cards = retrieve_cards(question, k=3)
# Augment prompt with retrieved cards (omitted)

Cross-Examination & FAQs

A deeper dive clarifying mechanics, constraints, and baseline evaluations.

Q1. What is the core idea of this paper?

The paper investigates how to store and reuse successful SQL repair episodes to help models perform better on future, unseen database queries.

Q2. Does this approach require training the model again?

No, the research focuses on test-time memory retrieval rather than model weights update.

Q3. What is the primary benefit of this system?

It improves the first-attempt accuracy of SQL generation by referencing previously solved, verified examples.

Q4. What models were tested in this study?

The primary model used was Qwen3.5-27B. The pipeline was also replicated on Qwen3.5-9B, Gemma4-E4B, Gemma4-31B, gpt-oss-20b, and Hunyuan-A13B.

Q5. Which benchmarks were used to evaluate the memory system?

The study utilized the BIRD development set containing 1,534 questions and the Spider development set containing 1,034 questions.

Q6. How does increasing the number of retrieved cards affect accuracy?

Increasing retrieval from one to ten cards results in a 3.18 percentage point improvement in accuracy.

Q7. Do more complex card formats improve results?

No, the study does not establish that richer, more elaborate card formats provide an improvement over standard verbatim cards.

Q8. What are the economic costs of this implementation?

The paper does not provide estimates for dollar, latency, energy, or total-cost-of-ownership, as these factors remain in their native units of measurement.

Q9. What are the limitations of the current evaluation?

The evaluation does not account for total economic costs or the full lifecycle utility of the stored memory.

Flag an issue

What is wrong with this summary?

What is wrong?