Skip to main content
AI Engineering

RAG that actually retrieves: fix the retrieval layer first

Most retrieval-augmented generation problems are retrieval problems wearing a generation costume. Fix chunking, hybrid search and reranking before you touch the prompt.

2 min readBy Ravi Menon
Syntax-highlighted source code on a dark editor screen
Cover image for RAG that actually retrieves: fix the retrieval layer first

Key takeaways

  • If the right document is not in the context window, no prompt can save the answer.
  • Hybrid search plus a reranker beats pure vector similarity on almost every business corpus.
  • Measure retrieval separately from generation, or you will keep tuning the wrong layer.

Why do RAG systems return wrong answers?

Because retrieval failed before generation started. If the passage containing the answer is not in the context window, the model can only guess fluently. Fixing chunking, adding keyword search alongside embeddings and reranking the candidate set resolves more hallucinations than any prompt change.

Measure the two layers separately

A retrieval-augmented system has two failure surfaces and one output. When the answer is wrong, teams almost always debug the prompt, because the prompt is the part they can see.

Split the measurement. Retrieval gets recall at k against a labelled set of question-to-passage pairs. Generation gets faithfulness scored only on the passages that were actually supplied. Once those two numbers exist independently, the argument about what to fix ends in about ten minutes.

Chunk on structure, not on character count

Fixed-size chunking is the default in every tutorial and it is wrong for most real corpora. A contract clause split across two chunks retrieves as two half-answers. A specification table split mid-row retrieves as noise.

Chunk on the document's own structure where it has one — headings, clauses, table rows, list items — and attach the parent heading path to each chunk so it stays interpretable when it arrives alone in a context window.

Hybrid retrieval, then rerank

Embeddings are good at paraphrase and bad at identifiers. Ask a dense index for the warranty terms on model SX-4400 and it will happily return the warranty terms for a different model, because the sentences are nearly identical.

Run dense and sparse retrieval together, fuse the candidate lists, then rerank the top fifty with a cross-encoder and keep the top five. On the corpora we work with, that sequence moves recall at five from roughly 0.6 to above 0.9 without touching the generation prompt at all.

0.61
Recall@5 before
0.92
Recall@5 after hybrid + rerank
-68%
Unfaithful answers

Every hour spent on the prompt before retrieval is measured is an hour spent tuning the loudest layer instead of the broken one.

FAQFAQ

Frequently asked questions

About the author

RM

Principal AI Engineer

Previously ML platform engineering at scale

Ravi builds the applied AI systems we ship: retrieval pipelines, evaluation harnesses and the guardrails that keep a model useful once real users reach it. He writes about the engineering that decides whether an AI feature survives production.

  • LLM evaluation
  • Retrieval-augmented generation
  • Prompt engineering
  • AI cost modelling
All articles by Ravi

Read next

More on the same problem, from the same team.

  • The letters A and I rendered above a circuit-patterned surface
    AI Engineering

    Evaluating LLM features before you ship them

    Most AI features fail in production because nobody built a way to tell whether a prompt change made things better or worse. Here is the evaluation harness we build first.

    RMRavi Menon2 min read
  • Small humanoid robot seated on a wooden bench
    AI Engineering

    What an AI agent actually costs per completed task

    Token pricing is not the interesting number. Cost per successfully completed task, including retries and human escalation, is the one that decides whether an agent ships.

    RMRavi Menon2 min read
  • Close-up of a circuit board with processors and surface-mounted components
    AI Engineering

    Chatbot guardrails that hold up in front of customers

    Refusals, scope limits and escalation are product decisions, not prompt lines. Here is the guardrail stack we ship on customer-facing assistants.

    RMRavi Menon1 min read

Want this built, not just read about?

Tell us the outcome you need. We reply within one business day with a plan, a timeline and a price.

ExploreKeep exploring

Related pages

Guides

Subscribe Newsletter

Practical playbooks on AI, product engineering, growth marketing and creator campaigns. One email a month, no filler.