Retrieval Optimization

By Ludovico Bessi, Senior ML Engineer at Google · Updated

Retrieval optimization improves which passages the first stage finds. Hybrid search combines BM25's exact term matching with dense embeddings' semantic matching, ColBERT's late interaction scores token-level matches with precomputed document vectors, and sentence window retrieval matches small units but returns their surrounding context.

Dense vs. Sparse: Complementary Failures

Sparse (lexical) retrieval — BM25 over an inverted index — scores documents by exact term matches, weighted by term rarity (IDF) and saturating term frequency, with document length normalization. It excels at exact identifiers, rare names, error codes and jargon, needs no training, and is fully explainable. It fails on paraphrases and synonyms ("car" vs. "automobile").

Dense retrieval embeds queries and documents with a neural bi-encoder and retrieves by vector similarity. It excels at meaning and paraphrase, across languages. It fails on exact rare tokens it never learned to represent (part numbers, new product names) and can return plausible but wrong neighbors.

Because their failures differ, combining them is one of the most reliable improvements in RAG.

Hybrid Search

Run BM25 and dense retrieval in parallel, then fuse:

Reciprocal Rank Fusion

score(d) = 1/(k + rank_bm25(d)) + 1/(k + rank_dense(d))

Rank-based, no calibration needed, robust default. Weighting each list differently is a simple extension.

Score fusion

score(d) = α · norm(dense(d)) + (1 − α) · norm(bm25(d))

Requires normalizing scores (min-max or z-score per query), since BM25 scores are unbounded and cosine scores are not. Tune α on your evaluation set; a value that favors dense with a meaningful lexical weight is typical, but it varies by corpus.

Learned sparse retrieval

Models like SPLADE produce sparse vectors over the vocabulary, with learned term weights and expansion terms ("car" also activates "vehicle"). They live in an inverted index with BM25-like efficiency but capture some semantics, often competitive with dense models, and can replace or complement BM25.

Hybrid search consistently beats either method alone on mixed real-world query traffic, particularly in enterprise corpora full of identifiers.

Improving Dense Retrieval Itself

  • Choose the embedding model on your data. Public leaderboards (MTEB) are a starting point; your corpus decides.
  • Fine-tune on in-domain pairs. Use real query-click data or synthetic queries generated by an LLM for each chunk, train with contrastive loss and hard negatives (similar but irrelevant passages, mined with BM25 or the current model). Even a few thousand pairs help.
  • Use query and document prefixes if the model expects them (e.g. "query:" / "passage:"); forgetting them silently hurts quality.
  • Match the similarity function to how the model was trained (cosine vs. dot product).

ColBERT and Late Interaction

Bi-encoders compress a whole passage into one vector — a bottleneck. Cross-encoders read query and passage together — accurate but too slow for retrieval over millions of documents. Late interaction sits between them.

ColBERT (Khattab and Zaharia, 2020) encodes query and document separately but keeps one vector per token. Relevance is computed with MaxSim:

score(q, d) = Σ over query tokens i   max over doc tokens j   (q_i · d_j)

Each query token finds its best-matching document token, and the matches are summed. This captures fine-grained term matching (like BM25) with contextual semantics (like dense models), and document token vectors can still be precomputed.

The cost is storage: one vector per token instead of per passage. ColBERTv2 (Santhanam et al., 2022) uses residual compression to shrink storage substantially, and the PLAID engine makes search fast by pruning with centroid interactions. ColBERT models generalize well to new domains, often better than single-vector models. Late interaction is also widely used as a reranker over BM25 or dense candidates, where storage is not an issue. See our deep dive on late interaction retrieval with ColBERT.

Sentence Window Retrieval

A precision/context trade-off: small chunks retrieve precisely, large chunks give the model context. Sentence window retrieval gets both:

  1. Index individual sentences (or very small chunks), each embedded on its own.
  2. Store each sentence's surrounding window (e.g. 2–5 sentences on each side) as metadata.
  3. Retrieve by sentence, then replace each hit with its window before passing to the LLM.

The related small-to-big / parent document retrieval retrieves small chunks but returns their parent section. Both decouple the unit of matching from the unit of reading. Watch for duplicate windows when several neighboring sentences are retrieved; merge overlapping windows.

Retrieval Depth and Filters

  • Retrieve generously, then rerank. First-stage recall at 50–200 matters more than precision at 5, because a reranker will fix the order.
  • Apply metadata filters in the index, not after, to avoid empty results under selective filters.
  • Deduplicate near-identical chunks before reranking so they do not crowd out diverse evidence.

Measuring Retrieval

Evaluate retrieval independently of generation with labeled query-chunk pairs: recall@k (is a relevant chunk in the top k?), MRR and NDCG. Track them per query type (keyword-like, conceptual, multi-hop); hybrid search usually shows its value on exactly the slices where one method fails. See Evaluation.

Key Takeaways

  1. BM25 and dense retrieval fail on different queries; hybrid search with RRF or normalized score fusion beats either alone.
  2. Learned sparse models (SPLADE) add semantics to inverted-index efficiency.
  3. Fine-tuning embeddings on in-domain pairs with hard negatives is a high-return investment.
  4. ColBERT's late interaction (sum of MaxSim) offers near cross-encoder quality with precomputable document vectors.
  5. Sentence window and parent-document retrieval decouple the unit of matching from the unit of reading.