Before an AI assistant can answer from your documents, something has to find the right passage. There are two classic ways to search, and each is blind in its own way: one matches words, the other matches meaning. Hybrid search runs both and merges their results, so one method’s blind spot doesn’t cost you the answer. Here you’ll search a small help centre three ways, see where each one slips, and tune the blend yourself.
Two ways to search#
Keyword search looks for the question’s words in each passage. The standard recipe, called BM25, adds up the shared words, gives rare words more weight than common ones (“E-147” counts for far more than “thermostat”), and gently favours short passages. It’s fast, predictable and has been the backbone of search engines for decades. But it only sees spelling: ask for your “money back” and it won’t find a passage that says “refund”.
Vector search turns every passage and every question into an embedding, a list of numbers that captures meaning, and returns the passages whose numbers are closest. “Money back” lands near “refund”. But meaning is all it keeps: product codes, model numbers and names carry little meaning, so similar-looking ones blur together.
You’ll also hear them called sparse and dense retrieval: a keyword index records, for each passage, the handful of words it contains out of a vocabulary of thousands (mostly zeros, so sparse), while an embedding fills every one of its few hundred numbers (dense). Hybrid search runs both and merges the two ranked lists into one. The help centre below belongs to Hearth, a made-up maker of smart thermostats and doorbells, with 16 passages and 12 typical questions.
Predict first
Someone asks: “what happens if I break it”. The right passage is the warranty, which says accidental damage isn’t covered. What does keyword search put first?
Vector search gets the warranty question right with both models. Now try the error codes with BGE small selected. For “what does E-147 mean”, the right passage comes fourth: the model knows the question is about a thermostat error, but E-147, E-417, E-471 and E-714 look much alike to it, and the passages around them are all about Wi-Fi. Keyword search finds E-147 instantly, because only one passage contains it. Anthropic gives the same example in its write-up on retrieval: an embedding model “might find content about error codes in general, but could miss the exact ‘TS-999’ match.”
The two models even fail on different codes: MiniLM gets E-147 right but puts E-417 second. Keyword search has the opposite problem. It puts the eco mode passage first for “can I get my money back”, because that passage says the house warms up as someone “heads back”. Keyword search misses meaning; vector search misses exact codes and names. They fail on different questions, which is why combining them works.
Merging two lists#
You can’t just add the two scores together: a BM25 score might be 7 while a similarity is 0.6, and neither scale means anything to the other. The most common fix ignores the scores and uses only the positions. Reciprocal rank fusion (RRF), from a 2009 paper by Gordon Cormack, Charles Clarke and Stefan Büttcher, gives each passage 1 ÷ (60 + its place) from every list it appears in, and adds those up.
So a passage that’s first in one list and fourth in the other scores 1/61 + 1/64 ≈ 0.0320, while one that’s first in a single list scores 1/61 ≈ 0.0164. Agreement wins. The 60 keeps any one list from dominating: first place is worth only a little more than fifth.
That’s usually what you want, but not always. In the warranty question, the boiler passage is first in the keyword list and also appears in the vector list, so the hybrid puts it first and the warranty second. Look at the D3 question too: “charge” matches the D2 battery passage, which vector search also rates highly, so it edges out the D3 passage that says “charging”.
Predict first
You can tilt the merge, counting one list more than the other. Across all 12 questions, which blend puts the most right answers first?
Keyword only puts 7 of the 12 right answers first and misses the warranty altogether. Vector only does better: 11 with MiniLM and 10 with BGE small, which leaves E-147 fourth. An even split never loses an answer below second place, but it puts fewer first (9 and 10), for reasons like those above. Somewhere around 60 to 80% vector, both models put 11 of 12 first and every answer in the top two.
Don’t copy that number. The right blend depends on your documents, your users’ questions and your embedding model, so collect 30 or 50 real questions with known answers and measure, the way this figure does. For an AI assistant, the measure that matters most is usually whether the right passage makes the handful you pass to the model, not whether it comes first.
When hybrid search pays off#
- Documents full of identifiers: error codes, part numbers, product names, legal clause numbers, function names in code. These are where vector search is weakest.
- Users who type both ways: some paste an exact error message, others describe the problem in their own words.
- When vector recall disappoints: if the right passage often misses the top results, adding a keyword list is one of the cheapest fixes to try.
The cost is a second index to build and keep up to date, and a few milliseconds per search. Many search tools now offer both in one place, including Elasticsearch, OpenSearch, Weaviate and Qdrant.
In code#
Both searches and the merge, in a few lines of Python (pip install rank-bm25 sentence-transformers), on five passages from the help centre:
import re
from rank_bm25 import BM25Okapi
from sentence_transformers import SentenceTransformer
docs = [
"Error E-417: the thermostat can't find your Wi-Fi network.",
"Error E-471: your Wi-Fi password was rejected. Enter it again in the app.",
"Error E-147: the thermostat is on Wi-Fi but can't reach the internet.",
"Returns: send back any product within 30 days for a full refund.",
"Warranty: devices are covered for two years. Accidental damage isn't covered.",
]
words = lambda text: re.findall(r"[a-z0-9-]+", text.lower())
bm25 = BM25Okapi([words(d) for d in docs])
model = SentenceTransformer("BAAI/bge-small-en-v1.5")
doc_vecs = model.encode(docs, normalize_embeddings=True)
def rrf(*rankings, k=60):
scores = {}
for ranking in rankings:
for rank, doc in enumerate(ranking, start=1):
scores[doc] = scores.get(doc, 0) + 1 / (k + rank)
return sorted(scores, key=scores.get, reverse=True)
def search(query, top=10):
kw = bm25.get_scores(words(query))
keyword = [int(i) for i in kw.argsort()[::-1] if kw[i] > 0][:top]
sims = doc_vecs @ model.encode(query, normalize_embeddings=True)
vector = [int(i) for i in sims.argsort()[::-1]][:top]
return keyword, vector, rrf(keyword, vector)
for q in ["E-147", "can I get my money back"]:
keyword, vector, hybrid = search(q)
print(f"{q!r}: keyword {keyword}, vector {vector}, hybrid {hybrid}")
# 'E-147': keyword [2], vector [2, 0, 1, 4, 3], hybrid [2, 0, 1, 4, 3]
# 'can I get my money back': keyword [3, 0, 2], vector [3, 1, 4, 2, 0], hybrid [3, 0, 2, 1, 4]Both find the right passage first here; with five short passages, there’s little to confuse. Notice that keyword search also matched passages 0 and 2 for “money back”: both contain “can’t”, which this simple tokenizer splits into “can” and “t”. Real systems drop leftovers like these, as the figure does.
What to remember
- Keyword search (BM25) matches exact words and codes but misses paraphrases; vector search matches meaning but can blur look-alike codes and names.
- Hybrid search runs both and merges the ranked lists, usually with reciprocal rank fusion, which rewards passages that both lists agree on.
- Tune the blend, and judge it, on real questions with known answers from your own documents.