Juan Pablo García
All projects

Retrieval ablation of my RAG pipeline

Each stage of my RAG service's retrieval measured on 1,008 labeled questions. The biggest gain was a one-line tokenizer fix; fusion only helped once BM25 was fixed, and the reranker took over 95% of query time.

Personal projectAuthor2026

See it work

5 steps · scroll to play
  1. 1

    The pipeline under test

    Keyword search and vector search find candidates, rank fusion merges them, and a cross-encoder reranks the merged list. Each stage was measured alone.

  2. 2

    The tokenizer bug

    Production split on spaces, so “HTTPException,” never matched “HTTPException”. Fixing it lifted BM25 from 55% to 78% recall@5.

  3. 3

    Fusion needs two good lists

    With the broken keyword list, fusion pushed good vector results down: hybrid never beat dense retrieval significantly. With the fixed list it helped at depth 10, not at 5.

  4. 4

    The reranker's trade-off

    It improved ordering far more than recall, and took almost all of the query time on CPU.

  5. 5

    Chunk size

    512-token chunks didn't fit the embedder's 256-token input; smaller chunks looked better, within noise on 60 questions.

The pipeline under test

Keyword search and vector search find candidates, rank fusion merges them, and a cross-encoder reranks the merged list. Each stage was measured alone.

The tokenizer bug

Production split on spaces, so “HTTPException,” never matched “HTTPException”. Fixing it lifted BM25 from 55% to 78% recall@5.

Fusion needs two good lists

With the broken keyword list, fusion pushed good vector results down: hybrid never beat dense retrieval significantly. With the fixed list it helped at depth 10, not at 5.

The reranker's trade-off

It improved ordering far more than recall, and took almost all of the query time on CPU.

Chunk size

512-token chunks didn't fit the embedder's 256-token input; smaller chunks looked better, within noise on 60 questions.

Problem

My RAG service used the stack most guides recommend: BM25, dense vectors, rank fusion and a cross-encoder reranker. Its README said each piece helped, but none of that had been measured.

Solution

I rebuilt the retrieval in memory with production's exact settings and ran every combination on 60 questions I wrote over FastAPI's docs and on two public benchmarks, with paired comparisons, intervals, latency per stage and hypotheses written before the run.

Architecture

What was compared

  1. BM25as in production, and fixed
  2. Dense vectorsMiniLM embeddings
  3. Hybridboth, merged with RRF
  4. + Rerankercross-encoder on top

How it was measured

  1. 1,008 questions60 written + 2 benchmarks
  2. Recall, nDCG, MRRwith 95% intervals
  3. Latency per stageon a laptop CPU
  • Production split text on spaces, so punctuation stuck to words. Splitting on word characters raised BM25's recall@5 from 55% to 78%, and to 30 of 30 on questions with an exact term.
  • With the original tokenizer, hybrid search was never significantly better than dense retrieval alone, and on FiQA it was 3 points worse.
  • The reranker raised nDCG@10 by 4 to 12 points but recall@10 by only about 2, and reranking 10 candidates instead of 20 halved its time at the same quality.
  • The first three fixes (tokenizer, 10 rerank candidates, a BM25 index built once) are merged into the service.

Stack

Pythonsentence-transformersBM25PyTorchBEIRpytestGitHub Actions

Result

The best change was a one-line tokenizer fix: BM25 recall@5 from 55% to 78%. With it, hybrid search plus reranking reached 90% recall@5 on the FastAPI questions (production: 87%). Write-up: Does hybrid search plus reranking pay for itself? I measured my RAG pipeline

Want to work together?