RAG over financial reports returns wrong totals when asked to sum or compare figures — what is the right design?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Similarity search returns approximately relevant text, not the exact rows an aggregate needs; route numeric and aggregate questions to structured retrieval like text to SQL so totals are computed exactly.
Imagine asking a helper to total your monthly spending, but instead of handing them your bank statement, you hand them a stack of sticky notes that merely look related to money. They'll add up whatever notes they happened to grab and confidently give you a number — but it'll be wrong, because some receipts were never in the stack and they're doing the math in their head. The fix isn't a thicker stack of sticky notes or fancier handwriting. The fix is to pull up the actual statement in a spreadsheet and let the calculator add the column. For a system reading financial reports, that means turning 'what's the total revenue?' into a precise database query that runs over the real rows, instead of letting the language model eyeball a pile of similar-looking text.
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.
3-4 min: why similarity search can't guarantee a complete figure set, why LLM arithmetic over chunks is unreliable, and the route to structured retrieval (text to SQL / table extraction) fix versus the distractors.
| Question type | Right retrieval approach |
|---|---|
| Exact figures or aggregates (sum, count, max, compare) | Structured query: text to SQL or table extraction, executed for an exact result |
| Fuzzy or semantic lookup over prose | Vector retrieval over chunks |
| Mixed (narrative plus a number) | Route per sub-question, then combine the results |
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.
Trying to fix wrong totals by raising top-k or shrinking chunks; both keep the LLM doing unreliable mental math over an incomplete set of figures.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.