Skip to solution
mediumAI Engineering

What is hybrid search and why combine BM25 with vector search?

226 views
01

Understand the problem

Lexical + semantic retrieval fused with RRF: covering each method's blind spots.

hybrid-searchbm25rrfretrieval
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Hybrid search runs a lexical ranker (BM25 keyword matching) and semantic vector search in parallel and fuses the results, typically with Reciprocal Rank Fusion. Vector search understands paraphrase but misses exact identifiers (error codes, SKUs, function names); BM25 nails exact terms but not meaning. Fusing them rais

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Reciprocal Rank Fusion
function rrf(lists: string[][], k = 60): string[] {
  const score = new Map<string, number>();
  for (const list of lists)
    list.forEach((id, rank) =>
      score.set(id, (score.get(id) ?? 0) + 1 / (k + rank + 1)));
  return [...score.entries()].sort((a, b) => b[1] - a[1]).map(([id]) => id);
}

const fused = rrf([await bm25(q, 50), await vector(q, 50)]).slice(0, 20);
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 52 of 80 decoded in the AI Engineering track. One more won't hurt.

Back to track