NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Structured Case-Based Reasoning for Inference-Time Adaptation of Text-to-SQL Parsers

Abhijeet Awasthi, Soumen Chakrabarti, Sunita Sarawagi

Introduction

Translating natural language questions into executable SQL queries (Text-to-SQL) is a cornerstone of accessible data analytics. However, the utility of these systems is often limited by their inability to generalize to new, unseen database schemas. When a model encounters a database structure it was not exposed to during training, it frequently fails to map linguistic nuances to specific table columns or complex join logic.

Traditional solutions involve fine-tuning the model on the new domain, a process that is computationally expensive, slow, and risks "catastrophic forgetting" of previously learned domains. This paper introduces StructCBR, a novel approach that enables instant inference-time adaptation by leveraging structured case-based reasoning. By utilizing a memory of successful query examples and a trainable similarity function, StructCBR allows bottom-up parsers to adapt to new schemas without the need for weight updates.

The Challenge of Domain Adaptation

In cross-domain Text-to-SQL tasks, the primary hurdle is the "zero-shot" gap. While a model might understand the general syntax of SQL, it lacks the specific context of a new database's schema.

Previous attempts at inference-time adaptation, such as ConcatCBR, attempted to bridge this gap by prepending example queries to the model's input prompt. However, this "bag-of-examples" approach fails to account for the hierarchical, tree-like structure of SQL. By treating examples as flat text, these models struggle to identify and reuse specific logical sub-structures that are relevant to the current user query. StructCBR addresses this by treating SQL as a structured composition of sub-trees rather than a linear sequence of tokens.

Methodology: StructCBR

StructCBR is built upon SmBoP, a state-of-the-art bottom-up parser that decodes SQL queries as trees. The framework introduces four key components to the parsing process:

1. Case Memory

For any new database, a small "case memory" is established, consisting of a few dozen natural language questions paired with their correct SQL trees. This memory acts as a reference for the model to find analogous patterns during inference.

2. Contextual Tree Representations

To compare candidate SQL fragments against the case memory, the system uses a specialized transformer to generate embeddings for SQL sub-trees. These embeddings are "contextualized," meaning they represent the SQL code (e.g., a specific WHERE clause) in direct relation to the specific terms used in the user's natural language question. This ensures that the similarity is based on both logic and linguistic intent.

3. Compositional Similarity

Efficiency is a core requirement for inference-time adaptation. StructCBR employs a compositional similarity function where the similarity score of a large candidate tree is calculated by summing the similarities of its constituent sub-trees. This additive approach allows the model to efficiently evaluate thousands of potential query fragments in real-time.

4. Score Boosting

During the beam search for the optimal SQL query, the parser combines its internal log-probability score with a "CBR score" retrieved from the memory. If a candidate sub-tree closely matches a successful pattern found in the case memory, its score is boosted, guiding the model toward a more accurate construction based on proven examples.

Experimental Evaluation

The researchers evaluated StructCBR using the Spider dataset, the standard benchmark for complex, cross-domain Text-to-SQL tasks. The base model was trained on 140 databases, while adaptation was tested on five distinct, unseen databases: world_1, car_1, cre_Doc_Template_Mgt, dog_kennels, and flight_2.

To simulate a realistic low-resource deployment, the case memory for each test database was limited to just 30 example queries—a small enough set to be curated by a domain expert in a matter of minutes.

Key Results and Insights

StructCBR demonstrated significant improvements over both the base SmBoP model and existing adaptation methods:

  • Accuracy Improvement: The method achieved an average increase of 4.6 points in Exact Match (EM) accuracy across the test databases.
  • Efficiency vs. Fine-Tuning: StructCBR captured approximately 43% of the accuracy gains provided by full fine-tuning (100 epochs) but did so 5000x faster. While fine-tuning requires significant GPU time, StructCBR's overhead is a mere 0.1 seconds per query.
  • Robustness: Unlike ConcatCBR, which occasionally degraded performance on certain schemas due to prompt noise, StructCBR provided consistent, positive gains across all tested metrics and databases.

Conclusion

StructCBR represents a significant step toward "instant" adaptation for Text-to-SQL systems. By recognizing that SQL is inherently structured, the authors have created a mechanism that allows models to learn from examples at the moment of inference.

While a performance gap remains between this method and exhaustive fine-tuning, StructCBR serves as a powerful "stop-gap" solution for real-world applications where immediate deployment to new schemas is required. Future work may involve extending this structured similarity approach to sequence-to-sequence architectures and Large Language Models (LLMs) to further narrow the gap between instant adaptation and specialized training.

Summary updated

BibTeX
@inproceedings{awasthi2023structured,
  author = {Abhijeet Awasthi and Soumen Chakrabarti and Sunita Sarawagi},
  title = {{Structured Case-Based Reasoning for Inference-Time Adaptation of Text-to-SQL Parsers}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i11.26476},
}
Figure