Why vector search fails on analytical questions
A vector index is built for semantic similarity. It finds documents that are conceptually close to a query. That works well for "what is our refund policy" or "summarize the Q3 earnings call." It breaks on "how many prior authorization denials did we receive in September" or "what was the average claim processing time by payer last quarter." Those are not semantic questions. They are aggregation queries over structured data that lives in a database, not in a document. Embedding that database into a vector index does not make it queryable the way SQL makes it queryable; it makes it retrievable the way text makes text retrievable, which is the wrong tool for the job.
The failure is usually silent. A vector search against a database table that has been chunked and embedded will return rows that are semantically similar to the query. Those rows may be real data. They are not the answer to an aggregation question. A user asking "how many claims were denied last month" gets back rows containing denial records, possibly accurate ones, but not the count they asked for. The system looks like it is working. The answer is wrong. In a production environment where users trust the system, silent wrong answers are more damaging than visible failures.
SQL generation solves a different part of the problem and introduces its own failure modes. On clean benchmarks with simple schemas, GPT-4o reaches 86.6% execution accuracy. On Spider 2.0, which uses enterprise-style schemas with hundreds of tables and complex join logic, that number drops to 10.1%. The best model on that leaderboard peaks at around 23%. The gap is not a model quality problem; it is a schema complexity problem. A model that has never seen your schema, passed the full schema as a prompt, has to select the right tables and columns from hundreds of candidates while reasoning about their relationships. Failure on multi-table analytical queries at enterprise schema scale is the norm, not the exception.
"A vector index embedded with database rows does not answer aggregation questions. It answers questions about individual rows. Those are different problems, and only one of them needs SQL."
The 5 structured data retrieval approaches compared: what each one handles and where each one fails
Most teams try these approaches in order, discovering the failure mode of each only after it reaches a user. The table maps where each breaks so you can skip the sequence.
| Retrieval approach | What it handles | Where it fails | Failure mode | Production risk |
|---|---|---|---|---|
| Vector-only on all data | Semantic questions about documents and policies | Any aggregation, count, filter, or comparison over structured data | Returns plausible rows instead of computed answers; users trust wrong results | Critical |
| Full-schema text-to-SQL | Simple schemas with few tables; direct lookups | Enterprise schemas with 50+ tables; multi-table joins; ambiguous column names | 10.1% execution accuracy on enterprise schemas; plausible-but-incorrect SQL runs without error | High |
| Schema-aware table retrieval | Selecting relevant tables before SQL generation on large schemas | Column-level disambiguation; queries requiring cross-domain joins not visible at table level | Correct table, wrong columns; still silent failure on complex aggregations | High |
| Hybrid query routing | Analytical queries go to SQL; semantic questions go to vector; results merged | Queries that span structured and unstructured data simultaneously; routing classifier errors | Misrouted queries fail silently; combined answers need validation logic to avoid contradictions | Moderate |
| Validated hybrid with semantic layer | Full analytical query coverage; cross-domain question answering; result validation before output | High build cost; semantic layer requires ongoing maintenance as schema evolves | Validation catches errors before users see them; schema drift requires maintenance cadence | Lower |
The failure mode that causes the most production damage is not the one that breaks visibly. It is the one that produces a plausible answer based on incorrect SQL. A query that returns an error is caught immediately. A query that selects the wrong table, applies an aggregation to the wrong column, and returns a number that looks reasonable is not caught until someone checks it against the source system. In a healthcare revenue cycle or financial reporting context, that discovery usually happens too late to be routine.
Not sure where your structured data retrieval gaps are?
10decoders audits your RAG pipeline against your actual query distribution, identifies which analytical questions your vector index is answering incorrectly, and builds the SQL hybrid retrieval architecture your data types require. Our DocuFindr and CheiAI platforms handle structured and unstructured retrieval at production scale.
Book a Free AI Assessment →Why schema retrieval matters more than model capability
The most common assumption when text-to-SQL fails is that the model needs to be smarter or better prompted. The research evidence says otherwise. When a frontier LLM is given the full schema of a large enterprise database as context, it produces SQL that fails on complex queries not because it cannot reason about SQL, but because retrieving the right tables and columns from a 200-table schema within a limited context window is a retrieval problem, not a reasoning problem. Passing the full schema as a prompt is not retrieval; it is the absence of retrieval, and it pushes the table-selection problem into the model's context window where it competes with the user's actual question.
Schema retrieval addresses this directly. Before SQL generation, a retrieval step identifies the subset of tables and columns most relevant to the incoming query and passes only that subset to the model. Pinterest's text-to-SQL system uses this pattern: it retrieves relevant tables from thousands of candidates before the query is generated. The CSR-RAG paper reports 80% recall on table retrieval for enterprise schemas, meaning 8 of 10 relevant tables are correctly identified before the model writes a single line of SQL. Getting the right tables in front of the model before generation produces the largest accuracy gain of any single change, and it is the step most teams skip when they first add text-to-SQL to a RAG pipeline.
Column-level retrieval goes one step further. Similar column names across tables are one of the most common sources of wrong-table selection: a schema with claims.amount, payments.amount, and adjustments.amountwill produce inconsistent results when the query just asks for "amount" without specifying which context. A schema-aware retrieval step that includes column-level descriptions and disambiguates by query context removes this class of error before generation. It adds latency. On most enterprise query distributions, the accuracy gain justifies it.
Unstructured queries only
All queries hit the vector index. Analytical questions return rows rather than computed answers. Failure is silent and users trust incorrect results.
Full schema in context
SQL generation added with full schema as prompt. Works on simple schemas. Fails on large schemas without table retrieval. No validation of SQL output before it reaches users.
Routed retrieval with validation
Query router classifies analytical vs. semantic questions. Schema retrieval selects relevant tables before SQL generation. Output validation catches wrong answers before users see them.
The SQL hybrid retrieval readiness checklist
Before deploying a hybrid RAG pipeline that answers analytical questions over structured data, each item below should be in place. These are the controls that catch wrong-answer failures before they reach production users.
"SQL that executes without error but returns the wrong number is not a failed query. It is a wrong answer delivered with confidence, and those are harder to catch than errors."
What to do this week
Classify your last 200 production queries by type
Pull 200 recent queries from your RAG pipeline's logs and label each one: semantic question (answered from document content) or analytical question (requires computation over structured data). Count what share is analytical. If it is above 10%, your vector-only pipeline is failing on a material fraction of your production queries right now. That number is the starting point for any hybrid retrieval conversation with your team or with a vendor.
Document your schema in plain language before touching the retrieval architecture
Take the ten tables most likely to be involved in analytical queries and write a one-paragraph description of each one: what it contains, what the primary business entity is, what each column means in the context of your domain, and which other tables it joins to most commonly. That documentation becomes the input to schema retrieval. A retrieval system matching against documented business descriptions outperforms one matching against bare table and column names on every benchmark that uses realistic enterprise schemas.
Test SQL generation on your schema with the full schema as context, then with schema retrieval
Write 20 analytical questions that real users have asked or would ask about your structured data. Run them through your current SQL generation setup with the full schema passed as context and measure how many produce correct results. Then run the same questions with schema retrieval limited to 3-5 tables per query and measure again. The gap between those two numbers tells you whether schema retrieval is worth building for your data. On large schemas, the gap is typically large enough to decide the question on its own.
Add result validation before connecting SQL output to user-facing answers
Before going further in hybrid retrieval architecture, add a basic sanity check to any SQL result that reaches users. Check that numeric results fall within historical ranges for that metric, that row counts are non-zero when the question implies data should exist, and that the result's data type matches what the question asked for. These checks catch the most common silent failure modes: wrong aggregation column, wrong filter applied, wrong table joined, without requiring a semantic layer. They are an afternoon of engineering that catches the class of errors that damages user trust most.
Let 10decoders build your SQL hybrid retrieval layer
We audit your current RAG pipeline against your actual query distribution, identify which analytical questions are returning wrong answers from vector search, and design the schema retrieval and SQL hybrid architecture your data requires. Our teams have shipped production hybrid RAG systems for healthcare and fintech clients where analytical accuracy is a compliance requirement, not a preference.
