RAG Without the Hype: Chunking, Embeddings and the Retrieval Eval You Skip
Retrieval-augmented generation demos beautifully and fails quietly in production. The chunking decisions that matter, why your embedding model choice barely does, and the 50-question eval that tells you the truth.

Every RAG demo works. Point a vector database at some documents, ask a question, watch the model cite the right paragraph. Then you ship it, and within a week users are getting confident answers sourced from the wrong document, the right document's wrong section, or — the classic — a paragraph that mentions the keyword but has nothing to do with the question.
The model is not the problem. Retrieval is the problem, and retrieval is an engineering discipline that the demo skips entirely.
Chunking is the whole game
Your documents do not fit in a context window, so you split them into chunks. Every RAG failure we have debugged traces back to this step.
Fixed-size chunking (every 500 tokens, split) is the default and the worst option. It cuts through sentences, separates a heading from its content, and splits tables in half. The chunk that contains "the refund window is 30 days" and the chunk that contains "for annual plans" end up in different rows of the database, and the answer to "what is the refund window for annual plans?" is now unanswerable.
Structure-aware chunking respects the document's own boundaries: split on headings first, then paragraphs, then sentences, and only fall back to token counts when a section is genuinely too long. Keep the heading path with every chunk — "Pricing > Annual Plans > Refunds" — because that context is what lets the model disambiguate.
def chunk_markdown(text: str, max_tokens: int = 400):
sections = split_on_headings(text) # keep heading path
for heading_path, body in sections:
for para in split_paragraphs(body):
if token_count(para) > max_tokens:
yield from split_sentences(para, heading_path)
else:
yield Chunk(text=para, context=heading_path)Overlap of 10–15% between chunks is cheap insurance against boundary effects. A sentence that straddles two chunks exists fully in at least one of them.
The embedding model matters less than you think
Teams spend weeks benchmarking embedding models and minutes on chunking. The returns are inverted. Moving from a mid-tier embedding model to the top of the leaderboard buys you a few points of recall. Fixing your chunking buys you the difference between "works" and "does not."
Pick a solid, cheap embedding model. Spend the saved budget on retrieval quality: hybrid search (vector plus keyword, because embeddings are bad at exact strings like error codes and SKUs), metadata filters, and a reranker on the top 20 results before they reach the prompt.
The eval you are not running
You would not deploy search without testing it. RAG is search with a parrot attached, and the parrot gets all the attention.
Build the eval before you tune anything:
1. Write 50 real questions — from support tickets, from sales calls, from the things users actually ask. 2. For each, mark which document sections contain the answer. This is the tedious part. Do it anyway. 3. Run retrieval only — no generation — and measure: did the right chunk appear in the top 5?
def recall_at_5(eval_set, retriever):
hits = 0
for q, gold_chunks in eval_set:
retrieved = retriever(q, k=5)
if any(g.id in {r.id for r in retrieved} for g in gold_chunks):
hits += 1
return hits / len(eval_set)If retrieval recall is 60%, no prompt engineering on earth will save you — the model never sees the answer. Get retrieval above 90% first. Only then look at generation, and only with the same discipline: did the answer use the retrieved chunk, and is it faithful to it?
The boring pipeline that works
Structure-aware chunks with heading context. Hybrid retrieval with a reranker. A 50-question eval run in CI on every chunking or model change. A system prompt that says "if the context does not contain the answer, say so" — and an eval that checks it does.
None of this is a product you can buy. It is a week of unglamorous engineering, and it is the entire difference between a demo and a feature.
Paj Digital Labs
The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.
Related reading

Streaming AI Responses: Partial Text Is Not a Completed Result
Streaming improves perceived speed but adds cancellation and partial-output states. Keep tool actions, structured results and saved answers behind a verified completion boundary.

Human Review Queues for AI: Confidence Is Not a Permission Slip
A model’s self-reported confidence does not establish accuracy. Route uncertain and consequential cases using tested rules, show reviewers the evidence and record their decisions without rubber-stamping.

AI Evaluation Sets: Keep the Test Data Out of the Tuning Loop
An evaluation stops being independent when every prompt revision is shaped around its answers. Separate development examples from held-out cases and measure meaningful failure categories.