Two-Layer RAG for Value Grounding and Schema Linking in LLM-Based Text-to-SQL Systems
Abstract
Large Language Models translate natural language into SQL. In environments with dynamic schemas, models hallucinate column names and filter values absent from the target database. We present a two-layer Retrieval-Augmented Generation architecture that addresses schema linking and value grounding within an orchestration pipeline. The structural layer retrieves validated SQL examples via cosine similarity over dense embeddings, while the semantic layer extracts entities from the user query and matches them against real column values through a MinHash-then-Embedding cascade. The architecture improved Execution Accuracy from 23.6% to 42.5%. By successfully grounding filter values, the semantic layer reduced the Empty Result Rate from 26.4% to 7.5%.