Improving Text-to-SQL with Reusable Memory
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
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)
// Illustrative sketch (not from the paper)
const torch = require('torch-js'); // placeholder for tensor ops
// Single‑shot solver stub
function solveOneShot(question) {
// returns initial SQL attempt
return 'SELECT * FROM table WHERE ...';
}
// Execution‑guided repair stub
function repair(sql, db) {
// pretend we fix the query based on feedback
return sql.replace('...', 'condition');
}
// Assemble an episode object
function makeEpisode(question, attempt, corrected, trace) {
return { question, attempt, corrected, trace };
}
// In‑memory memory bank per database
const memoryBank = [];
function addToMemory(episode, correctSignal = true) {
if (correctSignal) memoryBank.push(episode);
}
// Card writing (verbatim storage)
function writeCard(episode) {
return episode.corrected;
}
// Retrieve top‑k cards using cosine similarity of dummy embeddings
function retrieveCards(question, k = 5) {
const qEmb = torch.randn([1, 768]); // placeholder embedding
const scores = memoryBank.map(ep => {
const epEmb = torch.randn([1, 768]); // placeholder stored embedding
const sim = torch.nn.functional.cosineSimilarity(qEmb, epEmb).dataSync()[0];
return { sim, card: writeCard(ep) };
});
scores.sort((a, b) => b.sim - a.sim);
return scores.slice(0, k).map(item => item.card);
}
// Example usage
const question = 'How many orders were placed in 2023?';
const firstAttempt = solveOneShot(question);
const corrected = repair(firstAttempt, null);
const trace = 'execution feedback';
const episode = makeEpisode(question, firstAttempt, corrected, trace);
addToMemory(episode);
const cards = retrieveCards(question, 3);
// Prompt augmentation with `cards` would follow (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.