The Demo Always Works
Every RAG pipeline I have audited in the last two years had the same arc. A weekend prototype on 500 PDFs answered every test query perfectly. The team shipped. Six months later, the corpus crossed 30,000 documents, and the same questions started returning confidently wrong answers. Nothing in the pipeline changed. The pipeline was always broken — the small corpus just hid it.
The pattern is so consistent that I now assume any RAG system without a labeled eval set is silently regressing.
What Actually Breaks
The failure mode is not the LLM. It is retrieval. Specifically, recall@5 — the probability that at least one of the top five retrieved chunks is the chunk the answer requires.
On a 1,000-document corpus with reasonable chunking, recall@5 with a dense-only retriever (text-embedding-3-small, cosine similarity) lands around 0.92. Looks great. On the same query distribution at 50,000 documents, that same retriever drops to roughly 0.61. The model now hallucinates 40% of answers not because it is dumb, but because the relevant chunk was never in its context window.
There are three mechanical reasons for this:
- Semantic collisions multiply. At 50k documents, there are simply more chunks that look similar in embedding space to the query. Your target chunk gets out-competed by close-but-wrong neighbors.
- Chunk boundaries split the answer. A 512-token chunker will cut a key sentence in half once every few thousand documents. At scale, this becomes routine.
- Query-document asymmetry. Users write short questions ("how do I rotate a key?"). Documents are long, declarative passages. Cosine similarity over a single dense vector loses the lexical signal that BM25 would have caught instantly.
Hybrid Search Is Table Stakes
If you are running dense-only retrieval in production, stop reading and go fix that first. Hybrid (BM25 + dense, fused with RRF) is the single biggest recall lift I have measured. On one internal benchmark — a 120k-document technical support corpus — adding BM25 took recall@5 from 0.64 to 0.81 with no other changes.
A minimal pipeline looks like this:
from rank_bm25 import BM25Okapi
import numpy as np
def hybrid_search(query: str, k: int = 20) -> list[Hit]:
# Dense: typically ~30ms for 100k vectors on a hot pgvector index
dense_hits = vector_store.search(
embed(query), top_k=k, filter={"tenant_id": ctx.tenant_id}
)
# Sparse: BM25 over the same filtered subset, ~15ms
sparse_hits = bm25_index.search(query, top_k=k, tenant_id=ctx.tenant_id)
# Reciprocal Rank Fusion — no score normalization headaches
return rrf_merge(dense_hits, sparse_hits, k_constant=60)[:k]
def rrf_merge(a: list[Hit], b: list[Hit], k_constant: int) -> list[Hit]:
scores: dict[str, float] = {}
for rank, hit in enumerate(a):
scores[hit.id] = scores.get(hit.id, 0) + 1 / (k_constant + rank)
for rank, hit in enumerate(b):
scores[hit.id] = scores.get(hit.id, 0) + 1 / (k_constant + rank)
return sorted(all_hits_by_id(scores), key=lambda h: -scores[h.id])
RRF wins over weighted score fusion because BM25 scores and cosine similarities live in incompatible numeric ranges. Trying to normalize them is a rabbit hole. Rank fusion sidesteps the problem.
The Chunk Size Paradox
There is no correct chunk size. There is only a correct chunk size for your evaluation set, and the optimum shifts as your corpus grows.
| Chunk size | Recall@5 (1k docs) | Recall@5 (50k docs) | Answer faithfulness |
|---|---|---|---|
| 128 tokens | 0.78 | 0.42 | 0.61 (context loss) |
| 512 tokens | 0.91 | 0.74 | 0.83 |
| 1024 tokens | 0.93 | 0.69 | 0.79 (noise) |
| 2048 tokens | 0.94 | 0.58 | 0.71 (heavy noise) |
Numbers are illustrative but the shape is real across every corpus I have touched. Tiny chunks lose context — the answer needs surrounding sentences to make sense. Huge chunks add noise — the embedding becomes an average of too many ideas and stops being discriminative.
The workaround that actually scales is parent-document retrieval. Embed small chunks (256 tokens). When a small chunk hits, return the larger parent section (1024–2048 tokens) to the LLM. You get the precision of small chunks for retrieval and the context of large chunks for generation. This single change took faithfulness from 0.79 to 0.88 on the same eval set above.
Embedding Models Are Not Interchangeable
I still see teams running text-embedding-ada-002 in production. Stop. On technical content (API docs, code, RFCs), the gap between ada-002 and text-embedding-3-large is not subtle. On a 40k-document developer documentation corpus:
- ada-002: nDCG@10 = 0.51
- text-embedding-3-large: nDCG@10 = 0.67
- bge-large-en-v1.5: nDCG@10 = 0.69
- voyage-code-2 (on code-heavy queries): nDCG@10 = 0.74
The cost difference is rounding error compared to what you spend on the generation step. If you are embedding 50 million tokens, the delta between ada-002 and text-embedding-3-large is roughly $5 vs $65 one-time. Pick the better model.
For domain-specific corpora — medical, legal, code — a fine-tuned open-weight model often beats every API embedding. The training data for the big proprietary embedders is web-shaped, and your corpus is not.
Rerank Or Lose
After hybrid retrieval, you have a top-20 list that is roughly correct. Sending all 20 to the LLM wastes context and tanks faithfulness. Send the top 5. But the top 5 from hybrid search is not yet the right top 5.
A reranker — Cohere Rerank, a cross-encoder like bge-reranker-large, or Voyage rerank-2 — re-scores the top 20 against the query using a model that sees query and document together, not as separate embeddings. The recall lift is large.
On the 120k-doc support corpus:
| Stage | Recall@5 | Latency added |
|---|---|---|
| Dense only | 0.64 | 30ms |
| Hybrid (BM25 + dense, RRF) | 0.81 | +15ms |
| Hybrid + Cohere Rerank top-20→5 | 0.94 | +90ms |
| Hybrid + bge-reranker (local GPU) | 0.93 | +45ms |
90ms is real but acceptable for most agent workflows where the LLM call itself is 2–8 seconds. If you cannot afford the latency, run the reranker locally — a quantized bge-reranker-base on a single L4 gets you most of the lift at 30ms.
def retrieve(query: str, k: int = 5) -> list[Chunk]:
candidates = hybrid_search(query, k=20)
if len(candidates) <= k:
return candidates
pairs = [(query, c.text) for c in candidates]
scores = reranker.score(pairs) # cross-encoder, batched
ranked = sorted(zip(candidates, scores), key=lambda x: -x[1])
return [c for c, _ in ranked[:k]]
Metadata Filters Are The Cheapest Win
Before you tune anything else, look at how much of the index you can prune with a metadata filter. In multi-tenant systems, a tenant_id filter cuts the search space by 100x or more for free. Add document_type, language, created_after, and the effective corpus the vector search has to discriminate over shrinks to a few thousand chunks. At that scale, even ada-002 starts to look acceptable.
Most vector stores — pgvector with HNSW, Qdrant, Weaviate — support filtered ANN search efficiently. Make sure your store does pre-filtering, not post-filtering. Post-filtering applies the filter to the top-k results, which is useless if your tenant only has 50 of the 50,000 vectors and none of them made it into the unfiltered top-k.
What We Tried That Did Not Work
We spent two weeks fine-tuning a retrieval model on synthetic query-document pairs generated by Claude. It moved nDCG@10 by 0.01. The same week of effort spent on building a proper eval set and switching to hybrid + rerank moved it by 0.18.
We also tried summarizing every document with an LLM and embedding the summary. Recall went up by 6%, faithfulness went down by 11%, and we doubled our ingest cost. The summaries were embeddings of paraphrases — they retrieved well but the LLM then had to answer from the original chunk, which contained details the summary had dropped.
Lesson: do not optimize retrieval in isolation. Always measure the end-to-end faithfulness of the answer.
Build The Eval Set Before You Need It
A RAG eval set is 100–500 labeled (query, expected_doc_id, expected_answer) tuples drawn from real user queries. Run it nightly. Track recall@5, nDCG@10, and an LLM-judged faithfulness score against the expected answer.
Without this, every change is a vibe. With it, you can confidently ship a chunker change knowing that recall went from 0.81 to 0.84 and faithfulness held at 0.88. I will not work on a RAG system that does not have one. It is the difference between engineering and astrology.
A practical pattern: when a user thumbs-down an answer in production, automatically queue the query for labeling. Within a month you will have a representative eval set of exactly the queries that matter.
When To Stop Tuning Retrieval
If you have hybrid search, a reranker, tight metadata filters, parent-document retrieval, and a current-generation embedding model, and your recall@5 is still under 0.80, the problem is not retrieval. It is the query.
Real user queries are often underspecified. "How do I fix the login bug?" matches nothing because no document is titled "the login bug." The fix is to rewrite the query before retrieval.
Two patterns work:
HyDE (Hypothetical Document Embeddings): ask the LLM to generate a fake answer to the query, then embed and retrieve against the fake answer. The fake answer looks more like a document than the query did. Recall lift on ambiguous queries is real — I have seen 0.10 to 0.15 nDCG@10 improvements on conversational queries.
Multi-query: ask the LLM to generate three rephrasings of the query, retrieve for each, and union the results before reranking. Costs an extra LLM call but smoothes over awkward phrasing.
async def retrieve_with_rewrite(query: str, k: int = 5) -> list[Chunk]:
rewrites = await llm.generate_query_rewrites(query, n=3)
all_candidates: dict[str, Chunk] = {}
for q in [query, *rewrites]:
for hit in hybrid_search(q, k=10):
all_candidates[hit.id] = hit
return rerank(query, list(all_candidates.values()))[:k]
The extra LLM call adds ~400ms and roughly 200 tokens. For an agent that is already going to spend 5 seconds reasoning, it is a trivial cost for the quality lift.
The Takeaway
Retrieval is now a systems problem, not a model problem. The teams shipping good RAG are not the ones with the best embeddings — they are the ones with hybrid search, rerankers, parent-document retrieval, tight metadata filters, query rewriting, and most importantly, a labeled eval set running every night. The model you pick at the end matters less than the pipeline that feeds it.
If you cannot tell me your current recall@5, you do not have a RAG system. You have a demo.