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
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
N750MCand 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
- Send the same query to a keyword index and a vector index, in parallel.
- Each returns its own ranked list of candidate passages.
- Merge the two lists into one ranking.
- 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
-termexclusion 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).