Skip to content

LearnRetrieve

Hybrid search

Hybrid retrieval · Keyword plus vector search

Runs keyword search and vector search on the same query and merges the two ranked lists, so a passage can be found by its exact words or by its meaning.

In DocSlurpIllustrated explainer

On this page
Hybrid search: keyword and vector search catch different passagesThe query "How do I book N750MC as our private jet to London?" goes to two retrievers. Keyword search matches the exact tail number N750MC and finds A, launch-review page 5, and D, travel-desk-guide page 14. Vector search matches the meaning of "private jet" and finds B, travel-desk-guide page 3, A, and C, charter-agreement page 2. Only A is found by both. Fused with reciprocal rank fusion at k equals 60, the order is A 0.0325, B 0.0164, D 0.0161, C 0.0159. Keyword search alone misses B and C; vector search alone misses D.Query“How do I book N750MC as our private jet to London?”KEYWORD · BM25matches the string N750MCVECTOR · EMBEDDINGS“private jet” ≈ “charter”bothDABCMisses B and C:no word in commonMisses D: a tail numberhas little meaning to embedFused with RRF (k = 60)1Alaunch-review.pdf p.5Launch team flew N750MC to Londonboth lists0.03252Btravel-desk-guide.pdf p.3Reserve charter aircraft via the deskvector only0.01643Dtravel-desk-guide.pdf p.14N750MC: cost code for hangar feeskeyword only0.01614Ccharter-agreement.pdf p.2Aircraft ready within three hoursvector only0.0159
Each lens catches what the other misses; hybrid search keeps the union. Keyword search finds the exact tail number N750MC (D) but not the travel desk’s booking page (B), which shares none of the query’s words. Vector search finds B and C by meaning but lets the rare code slip. Only A, found by both, scores twice under RRF. Switch lenses to see what each one alone would return.

The problem: one query, two kinds of words

An executive assistant types “How do I book N750MC as our private jet to London?” The query mixes two kinds of words. N750MC is an exact identifier: only a passage containing that string will do. “Private jet” is a description: the documents say “charter aircraft”, “business jet” or “the Learjet 75”, and any of those will do.

No single retriever handles both well.

  • Keyword search (lexical search, often ranked with BM25) matches the exact token N750MC and ranks the passages that contain it near the top. But it has no idea that “private jet” and “charter aircraft” mean the same thing, so the travel desk’s booking page, which shares none of the query’s words, scores nothing.
  • Vector search maps “private jet” close to “charter aircraft” and finds the booking page. But an embedding model has little meaning to encode for a code like N750MC. It lands near every other tail number, and the page that defines it may not make the cut.

Each retriever’s blind spot is the other’s strength. Hybrid search runs both and merges the results.

How it works

  1. Send the same query to a keyword index and a vector index, in parallel.
  2. Each returns its own ranked list of candidate passages.
  3. Merge the two lists into one ranking.
  4. Optionally rerank the merged shortlist with a model that reads each passage against the query.

Step 3 is the subtle one. The keyword list carries BM25 scores like 14.2 and the vector list carries similarities like 0.83. Those numbers are on different scales, so adding them lets whichever retriever uses bigger numbers win. Most systems either normalize the scores first (score normalization) or ignore scores and merge by rank with reciprocal rank fusion (RRF), which gives each passage 1 / (60 + rank) from every list that returned it.

A worked example

Four passages from a company corpus, as in the figure:

Passage Keyword rank Vector rank
A launch-review.pdf p.5: “The launch team flew N750MC to London” 1 2
D travel-desk-guide.pdf p.14: “N750MC: cost code for hangar fees” 2 —
B travel-desk-guide.pdf p.3: “Reserve charter aircraft through the travel desk” — 1
C charter-agreement.pdf p.2: “Aircraft are ready within three hours of a request” — 3

Fused with RRF at k = 60:

  • A: 1/61 + 1/62 = 0.03252
  • B: 1/61 = 0.01639
  • D: 1/62 = 0.01613
  • C: 1/63 = 0.01587

A wins because both retrievers found it. B and D each come from only one side, and each would have been missing entirely from the other retriever’s results. Keyword-only search loses B and C; vector-only search loses D. The hybrid list has all four.

Use the buttons in the figure to switch between keyword only, vector only and hybrid, and watch which passages each one misses.

Where it breaks

  • Fusion can’t recover what neither side found. If the answer uses different words and its meaning is far from the query, both lists miss it. Fix recall upstream with query rewriting, HyDE or better chunking.
  • Score blending needs care. A weighted sum of normalized scores (for example 0.7 × vector + 0.3 × keyword) can work, but the right weights depend on the corpus and the query mix, and they drift when either index changes. Rank fusion is the safer default.
  • It costs two queries. Latency is the slower of the two branches, plus fusion. Both indexes must be kept in sync with every document change.
  • Correlated lists add little. Two vector models trained on similar data tend to agree on the same mistakes. Fusion helps most when the inputs fail differently, which keyword and vector search do.
  • Operators only apply to one side. A quoted phrase or a -term exclusion is honored by keyword search, but the vector branch embeds the whole string as text. See phrase and negation search.

When to use it

Make hybrid the default for any corpus that mixes prose with identifiers: travel guides with tail numbers, contracts with clause numbers, manuals with part numbers, tickets with customer names. The BEIR benchmark found that BM25 remained a strong baseline that many dense retrievers failed to beat on unfamiliar domains, which is the practical argument for keeping keyword search in the mix rather than replacing it.

Pure vector search is reasonable only when queries are always natural-language descriptions and the corpus has no codes or names that matter. Pure keyword search is reasonable when users are experts who know the exact terms, as in log search.

In DocSlurp, every search runs a keyword branch and, whenever the query can be embedded, a vector branch, and fuses them with RRF. Graph and page-text branches join when they’re enabled.

In DocSlurp

In DocSlurp

Every search runs a keyword branch (Postgres full-text search, or LanceDB BM25 where the table has a full-text index) and, when the query embeds, a vector branch, then fuses them with RRF (core/server/src/search/retrieval-adapters.ts, core/server/src/search/session-execution.ts). Graph and page-text branches join when enabled. POST /v1/search/stream sends each branch’s hits as soon as that branch finishes, in whatever order they land and labelled by branch, then the fused and reranked list; the hits before that list are provisional, and per-phase timings arrive only when the request sets stats. POST /v1/search returns the same final list as one JSON body, and it is the fallback only when the stream never starts: a search is billed once it has produced hits, so a stream that drops after starting is reported, not re-run (core/packages/shared/src/search-stream.ts).

Sources

Jump to