Light-SQL: A Small Language Model Based Approach Using In-Context Learning for Natural Language to SQL
摘要
The transformation of natural language queries into SQL commands (NL-to-SQL) is a critical task for democratizing data access. While large language models (LLMs) have shown promising results, their deployment is often hindered by high computational costs and resource demands. This paper explores the potential of high-performance small language models (SLMs) as efficient alternatives. We propose a novel approach tailored for SLMs to address the NL-to-SQL task. Particularly, our approach leverages in-context learning (ICL) augmented by semantic retrieval to dynamically select relevant few-shot examples without the need for fine-tuning. Experimental results on the complex CORDIS scientific dataset demonstrate that the proposed method achieves a competitive execution accuracy of 41% with 3-shot learning. This performance surpasses several baselines, proving that SLMs combined with prompt engineering can effectively handle complex database schema logic on a single consumer-grade GPU. We share our experimental setup of this work on Github repository ( https://github.com/gilchea/Light-SQL ).