By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
When a RAG answer is wrong, teams reach for the prompt. Nine times out of ten the fault is upstream: a chunk that split a rule in half, an embedding model that cannot distinguish 'UK returns' from 'US returns', or a reranker that buried the right document under three generic ones.
| Layer | Decision | How it fails | Test |
|---|---|---|---|
| Chunking | Size, overlap, boundaries | A rule and its exception land in different chunks | Golden answers that require exception clauses |
| Embedding | Model choice, dimensions | Nearby-but-wrong documents rank first | Disambiguation set: UK vs US, sale vs full-price |
| Indexing | Metadata, filters | Multi-tenant leakage, wrong region | Filter assertions: a UK query never returns US docs |
| Retrieval | Top-k, hybrid, rerank | Right doc present but ranked fourth | MRR / hit@1 / hit@3 |
| Assembly | Order, budget | Top chunk truncated out | Budget test from Module 6 |
There is no correct chunk size. There is only 'does a chunk contain everything needed to answer the question?'. So write the test as questions whose answers span a boundary:
Document:
Returns Policy
Sale items may be returned within 14 days of delivery for store credit.
Exception: items marked FINAL SALE cannot be returned at all.
Bad chunking (boundary in the middle):
chunk A: 'Sale items may be returned within 14 days of delivery for store credit.'
chunk B: 'Exception: items marked FINAL SALE cannot be returned at all.'
-> a question about a FINAL SALE item may retrieve only chunk A and answer
'yes, 14 days', which is wrong.The test: ask 'Can I return a FINAL SALE jacket?' and assert the answer contains the exclusion. If it does not, your chunking is wrong — not your prompt.
The highest-value retrieval test is a small set of questions that differ by one crucial attribute. If your system cannot tell them apart, nothing downstream can help.
Q1: Can I return a sale item? -> returns-policy-sale
Q2: Can I return a full-price item? -> returns-policy-standard
Q3: Can I return an item bought in the UK? -> uk-returns
Q4: Can I return an item bought in the US? -> us-returns
Q5: Can I return a gift card? -> gift-cards-faq (non-returnable)
Assert hit@1 for each. If Q1 and Q2 both retrieve the same doc, your embeddings
are not capturing the distinction that matters to the business.| Metric | Plain meaning | Use it when |
|---|---|---|
| hit@k | Is the right doc anywhere in the top k? | You have limited context budget and need it present |
| hit@1 / MRR | Is the right doc first? | You only pass the top chunk or two |
| Context precision | Are the good chunks above the bad ones? | You pass many chunks and noise dilutes the answer |
| Context recall | Did we get everything needed? | Answers require combining two documents |
Start with hit@1 and hit@3. They are free, deterministic and immediately actionable.
If your index holds documents for several customers or regions, add an explicit leakage test. It is the highest-severity retrieval bug and the easiest to prevent with a filter — and the easiest to forget to test.
def test_no_cross_tenant_docs():
for tenant in ["acme_uk", "acme_us"]:
results = retrieve("returns policy", tenant=tenant, k=10)
assert all(r["tenant"] == tenant for r in results), tenantKey takeaways
Most RAG failures are upstream: chunking, embeddings, ranking, assembly.
Test chunking with questions whose answers span a boundary, not with a size parameter.
Disambiguation sets (UK vs US, sale vs full price) find embedding weaknesses fast.
hit@1/hit@3 are free, deterministic and actionable; add tenant leakage tests.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.