Skip to content
GenAI Learn/Vector Search Fundamentals
Browsing as a guest. Sign in to save your progress and earn XP as you complete chapters.

Hybrid Search: Combining Keyword & Vector

4 min read

You'll learn to

  • -Explain why semantic search can miss an exact error code, and why keyword search misses paraphrases
  • -Combine two ranked lists with Reciprocal Rank Fusion, and compute a score by hand
  • -Recognize the query patterns that most need hybrid search

A developer searches an internal knowledge base for "CUDA_OUT_OF_MEMORY error code 0x3F" and gets back generic GPU troubleshooting articles, not the page documenting that exact error code. Semantic search found things conceptually related to GPU memory problems. It missed the one document that is a literal match, because an embedding model reasons about meaning, not about matching specific tokens exactly.

An Analogy: Two Librarians

Imagine two librarians. One reads every word and finds any book containing the exact phrase you typed. The other understands what you mean, and would find a book about "puppies" when you ask about "dogs", but would not notice a book just because it contains a rare code. Neither alone is enough. Ask both for their top picks and combine the lists, and you get the best of each.

Why Semantic Search Misses Exact Matches

An embedding model places "0x3F" and "error code" in meaning-space alongside thousands of other technical terms. A specific hexadecimal code is exactly the kind of token it has least reason to represent distinctively. Semantically, it looks like any other short alphanumeric string. Keyword search, classically BM25 (a refinement of simple term-frequency matching), has the opposite strength and weakness. It excels at exact and near-exact token matches but has no concept of meaning. It would never connect "puppy" and "dog".

Reciprocal Rank Fusion: Combining Two Rankings, Not Two Scores

Combining the two is harder than it sounds, because their raw scores are not comparable. A BM25 score and a cosine similarity live on completely different scales, and averaging them is meaningless. Reciprocal Rank Fusion (RRF) sidesteps this by ignoring raw scores and using rank position instead. Each method produces its own ranked list, and RRF rewards a document for appearing near the top of either.

Reciprocal Rank Fusion
RRF(d) = Σ 1 / (k + rank_i(d))
Summed across every ranking the document appears in. k (commonly 60) softens the impact of any single rank.

Work one example by hand with k = 60. The exact-match document D1 is rank 1 in the keyword list and rank 4 in the semantic list. It scores 1/(60 + 1) + 1/(60 + 4) = 0.01639 + 0.01563 = 0.03202. Document D2 is rank 4 in keywords and rank 1 in semantic, so it scores the same sum in the other order, 0.01563 + 0.01639 = 0.03202. The two tie at the top, even though semantic search alone had buried D1 at fourth. The demo does this for all five documents.

The exact fusion the interactive demo below performs, on the CUDA error example.

Neither signal alone was enough. Keyword search alone would miss a query phrased even slightly differently, and semantic search alone buried the one document that mattered. Combined, the right answer rises back to the top. Now try it yourself in the interactive version below: change which method ranks the exact-match document well, and watch the fused order move.

Query: "CUDA_OUT_OF_MEMORY error code 0x3F"

Watch the exact-match document's rank change as you switch retrieval modes.

1CUDA_OUT_OF_MEMORY error code 0x3F troubleshooting guide← exact match
2GPU memory management best practices
3Understanding CUDA error codes
40x3F error resolution steps
5Deep learning training optimization tips

Reciprocal Rank Fusion combines both rankings: a document that scores well on either signal gets pulled toward the top, restoring the exact match to a tie for first.

The tell for when a query needs hybrid search is any case where matching the precise token matters as much as matching the general meaning: exact identifiers, error codes, product SKUs (stock-keeping unit codes that identify a product), part numbers and proper nouns.

Interview Signal is part of Pro

See a real weak answer next to a real strong one for this exact topic.

Quiz is part of Pro

Test what you just read with a short quiz, and bank the XP.

Discussion0

Join the Discussion

Sign in to leave comments, reply to others, or like insights.

Sign In to ScaleDojo

No comments yet. Be the first to start the thread!