Two-Layer RAG for Value Grounding and Schema Linking in LLM-Based Text-to-SQL Systems - Monteiro Macedo, João Victor; Miyaji, Renato; Moulin, Renato; Machado, Leonardo (Anais do Simpósio Brasileiro de Banco de Dados (SBBD); 2026: Anais do XLI Simpósio Brasileiro de Bancos de DadosDO - 10.5753/sbbd.2026.249462, 2026)
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%.