Knowledge lives in a SQL database, not documents: how does the RAG approach change?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Your answers must come from a relational database (sales figures, inventory, user records), not a corpus of text. Explain why naive vector retrieval over the rows is the wrong tool and what the RAG pattern looks like instead.
Vector search returns similar rows, but structured questions need exact aggregation. RAG becomes text to SQL: retrieve the schema and example queries, generate SQL, execute it, return the precise result.
Imagine you ask a librarian, 'how much did we earn last month?' If the librarian just hands you the three pages that sound most like your question, you still have to add the numbers up yourself — and you might get the wrong pages. What you actually want is for the librarian to walk to the ledger, run their finger down the right column, and add it up exactly. With a database, the trick is to teach the assistant the shape of the ledger (which tables and columns exist) and a few examples of how to look things up, then have it write the precise instruction the database can run. The database does the exact math; the assistant just translates your plain-English question into that instruction and reads back the answer.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Open with the mismatch: relational questions are exact and aggregative, while vector similarity returns approximately similar rows, so nearest-neighbor cannot sum, filter, join, or count. Introduce text to SQL as the right pattern — generate SQL, execute it, return the precise result — and stress that the exact computation belongs in the query engine. Reframe retrieval as over schema and exemplars, not data, and note that schema selection on a big database is itself a retrieval problem solved with embeddings. Cover correctness controls (grounding, validation, error-repair loop) and safety controls (read-only, timeouts, row limits, injection guards). Close on execution accuracy as the evaluation metric.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Embedding every row and doing nearest-neighbor search for a question like 'total revenue in Q3' — similarity returns rows that look like the question, not the exact sum, which the database could compute precisely.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.