Some questions are answered by your data warehouse, some by documents, and some need both. How do you design retrieval across structured and unstructured data?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Route by what the answer is made of. Counts, filters, aggregates and exact figures ("how many enterprise renewals slipped last quarter") belong to text-to-SQL, because a vector index cannot count and arithmetic in token space is unreliable. Policy, procedure and explanation belong to RAG. Mixed questions ("why did EMEA renewals slip, and what does the playbook say to do") run both paths and join at synthesis.
Full worked answer with diagram
Route by what the answer is made of. Counts, filters, aggregates and exact figures ("how many enterprise renewals slipped last quarter") belong to text-to-SQL, because a vector index cannot count and arithmetic in token space is unreliable. Policy, procedure and explanation belong to RAG. Mixed questions ("why did EMEA renewals slip, and what does the playbook say to do") run both paths and join at synthesis.
The pieces:
- A multi-label router: a classifier or small-LLM call that emits sql, docs or both. Log every decision, because a misroute looks like a retrieval failure in end-to-end metrics.
- Retrieve the schema, not just documents. A warehouse with thousands of tables does not fit in a prompt, so index table and column descriptions, metric definitions and known-good example queries, and retrieve the relevant slice per question. This is RAG over metadata, and it is usually where text-to-SQL quality is won or lost.
- Prefer a semantic layer when one exists. If revenue is defined once in a metrics layer, have the model pick metrics and dimensions instead of writing raw joins. Fewer invented joins, one definition of each number.
- Execute defensively. Read-only role, the requesting user's row-level security, a statement timeout and a row cap. Generated SQL never runs with more privilege than the user has.
- Cite both kinds of evidence. Pass the small result table and its SQL alongside the retrieved chunks into one generation, and show the SQL as the citation for any number.
Evaluate the paths separately: execution accuracy for SQL, comparing result sets rather than SQL strings, recall@k for documents, then end-to-end on a mixed slice.
The trap worth naming is a figure answered from a PDF that quoted last year's number. If a number has a system of record, route there and treat document-sourced figures as stale by default.
Worth sketching. One router feeding two evidence paths that rejoin at synthesis is the whole architecture.
flowchart TD
Q["User question"] --> R{"Router: what is<br/>the answer made of?"}
R -->|"counts, filters, figures"| S["Retrieve schema slice<br/>and metric definitions"]
S --> X["Generate SQL, run read-only<br/>under the user's row security"]
R -->|"policy, how-to, why"| D["Hybrid retrieval<br/>over documents"]
R -->|"both"| S
R -->|"both"| D
X --> G["Synthesise, citing the SQL<br/>and the chunks"]
D --> G
What a good answer covers
- Route by what the answer is made of
- Counts, filters, aggregates and exact figures ("how many enterprise renewals slipped last quarter")…
- Policy, procedure and explanation belong to RAG
- Mixed questions ("why did EMEA renewals slip, and what does the playbook say to do") run both paths and…
- A multi-label router: a classifier or small-LLM call that emits sql, docs or both
Key terms: A multi-label router · Execute defensively · Cite both kinds of evidence
Interviewer follow-ups to expect
How do you evaluate text-to-SQL when many different queries return the same correct result?
A mixed question needs a warehouse figure and a reason from a ticket the user may not be allowed to see: where is access enforced on each path?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep