Concept guide · RAG foundations
How do you answer questions that require database values?
A slower explanation for when the short interview answer is not enough. Start with the intuition, then connect it to the technical idea and the way an interviewer expects you to reason about it.
ML area
Generative AI → Structured-data and SQL RAG
Interview format
Core · Concept
Question
GENAI-054
Start with the idea
In simple terms
If the answer depends on exact numbers, a database or analytics tool is often safer than searching text chunks. The model can help translate a question into a query, but application code must restrict and validate that query.
Make it concrete
“How many paid orders did region X have last month?” should use a read-only query over the orders table, not a vector search over a monthly report paragraph.
Build the answer
How to reason about it
- 1Classify whether the question needs documents, structured computation, or both.
- 2Use read-only, least-privilege access with query validation and limits.
- 3Show the result and definitions clearly so the answer is auditable.
Go one level deeper
The technical explanation
Provide the model with only the schema and business definitions it needs, restrict tables and columns, validate the generated query, enforce row and time limits, and handle errors within a bounded retry policy. The result may then be combined with policy documents for interpretation, but keep numeric computation and explanatory context distinguishable.
Say this in the interview
Route structured questions to a read-only database or analytics tool, provide the schema and business definitions, validate generated queries, restrict tables and rows, and show the calculation or source. Combine database results with documents only when the question needs both facts and policy context.
Keep preparing