TLDR: ORANGE is an online, self-evolutionary framework that enhances Text-to-SQL translation by building and validating database-specific knowledge bases from historical SQL queries. It addresses the semantic gap between general LLM knowledge and domain-specific database semantics through a nested Chain-of-Thought strategy with tuple-semantic tracking, a probability-based filter for knowledge validation, and knowledge-enhanced in-context learning. Experiments show ORANGE significantly improves SQL translation accuracy, especially for complex and domain-specific queries, and demonstrates self-evolutionary capabilities without human intervention.
Large Language Models (LLMs) have made significant strides in converting natural language into SQL queries, making it easier for non-technical users to interact with databases. However, a major hurdle remains: the semantic gap. This gap refers to the difference between an LLM’s general knowledge and the specific, often unique, meanings within a particular database’s schema. This can lead to SQL queries that are grammatically correct but semantically wrong, misinterpreting column meanings or operational intent.
Existing methods often focus on improving the reasoning for individual translations but don’t accumulate knowledge from past experiences. Each query is treated in isolation, missing the opportunity to learn from historical translation logs, which are a rich source of in-domain knowledge.
Introducing ORANGE: A Self-Evolving Framework
A new framework called ORANGE (Online Reflection ANd GEneration) aims to bridge this semantic gap. ORANGE is a self-evolutionary system designed to build database-specific knowledge bases by analyzing SQL queries from past translation logs. By continuously accumulating this in-domain knowledge, which includes schema and data semantics, ORANGE progressively enhances the accuracy of subsequent SQL translations without needing human intervention.
How ORANGE Works: Three Core Stages
ORANGE operates through three main stages:
1. Knowledge Decomposition: This stage extracts SQL queries from translation logs. It uses a clever ‘nested Chain-of-Thought’ (CoT) approach to break down complex SQL queries into smaller, more manageable components. For each sub-component, it generates a corresponding natural language question. A key aspect here is ‘tuple-semantic tracking,’ which monitors how each SQL operation changes the meaning of data tuples, ensuring the generated knowledge accurately reflects database-specific semantics.
2. Knowledge Validation: Not all generated knowledge is perfect. To ensure reliability, ORANGE employs a probability-based filter. This validator checks the correctness of the knowledge units and only retains the most reliable ones in its memory. This prevents low-quality or incorrect information from influencing future translations.
3. Knowledge-Enhanced Translation: In this final stage, ORANGE performs SQL translation using its accumulated and validated knowledge. It’s like having an expert guide for each database. When a new natural language question comes in, ORANGE retrieves the most relevant knowledge units from its memory to serve as ‘demonstrations.’ This in-domain learning, combined with multi-path generation and a self-consistency strategy, significantly boosts the accuracy and robustness of the generated SQL.
Also Read:
- GraphChain: A New Approach for Large Language Models to Analyze Complex Graph Data
- Understanding Knowledge Dynamics in LLM Explanations with a New Framework
Practicality and Performance
Experiments conducted on multiple benchmarks, including Bird, Spider, and Science, confirm ORANGE’s effectiveness. It consistently shows improved accuracy over other advanced methods, particularly excelling in handling complex and domain-specific queries. For instance, on challenging Text-to-SQL tasks, ORANGE significantly outperforms leading baselines. The framework’s ability to build and reuse domain-specific knowledge bases is a key factor in its superior performance.
ORANGE also demonstrates strong scalability and adaptability across different underlying Large Language Models, showing consistent performance gains whether using GPT-4o-mini, Qwen, or DeepSeek-V3. This highlights its architectural independence and potential for long-term learning and improvement as more historical data becomes available.
This self-evolutionary paradigm represents a significant step forward for Text-to-SQL systems, offering a practical and scalable solution for real-world deployments by continuously learning and refining its understanding of database semantics. For more details, you can refer to the research paper.


