GRAY: Enhancing Few-Shot NL2SQL Translation Through Incremental SQL Log-Based Demonstration Expansion
摘要
The Natural Language to SQL (NL2SQL) task enables non-technical users to access databases. Recently, advancements in Large Language Models (LLMs) have driven progress in NL2SQL. However, existing methods still face challenges when dealing with domain-specific data due to limited domain knowledge and database adaptability. Numerous methods leverage schema information and query data to enhance performance, yet they remain inadequate for effective domain adaptation. To address the challenge of limited domain-specific knowledge, this paper proposes GRAY, a method that employs SQL logs to provide domain-specific knowledge. SQL logs capture domain-specific knowledge by reflecting the unique structure and semantics of each database, but their limited quantity restricts this knowledge, making incremental expansion necessary. GRAY proposes a two-phase incremental expansion method, utilizing LLM-driven query generation to enrich the domain-specific knowledge in SQL logs, enabling the LLM to understand the semantics of the specific database. To provide more relevant domain knowledge in the limited context window of LLMs, GRAY designs a high-quality demonstration selection algorithm. Through experiments on multiple real-world databases, GRAY improves the performance of the NL2SQL tasks. The experimental results show that GRAY performs effectively on complex databases and has broad application potential.