MGRR-SQL: Multi-Granularity Relevant Retrieval-Based in-Context Learning Approach for Text-to-SQL Generation

Yiming Zhan, Zhao Li, Tong Chen, Shiwei Wu, Yang Li2025

Abstract

In-Context learning serves as a vital component for enhancing Text-to-SQL task performance. However, current in-context learning methodologies for Text-to-SQL applications fail to sufficiently bridge the significant cross-domain correlation gap that exists between few-shot examples and the intended query target. Our approach overcomes these challenges through a novel relevant retrieval-based in-context learning method, which operates across three distinct granularity levels: (1) semantic similarity retrieval for analogous questions, (2) query kernel entity matching for retrieving strongly relevant questions and (3) character-level similarity analysis for fine-grained question retrieval. Additionally, we introduce a novel Object-Relational Mapping (ORM)-based database prompt and a post cell value linking method that effectively describes the schema while avoiding error propagation common in traditional schema linking approaches. Our experimental evaluations conducted on the benchmark datasets BIRD and Spider reveal that our approach delivers strong performance, comparable to state-of-the-art methods.
BibTeX
@misc{zhan2025mgrr,
  author = {Yiming Zhan and Zhao Li and Tong Chen and Shiwei Wu and Yang Li},
  title = {{MGRR-SQL: Multi-Granularity Relevant Retrieval-Based in-Context Learning Approach for Text-to-SQL Generation}},
  year = {2025},
  doi = {10.1109/icaace65325.2025.11019241},
}

Loading related content...

Figure