AI Applications
Retrieval Strategies: Vector Search, Keyword Search, and Hybrid Search
The same chunks, the same token budget, five ways to rank them: vector search, two flavours of BM25, and two hybrids. What each one finds that the others miss, and what combining them costs.
On this page · 16 sections
“Chunking Strategies for RAG: What Actually Matters? (opens in a new tab)” ended with a suspicion. Every strategy there ranked chunks by one signal, cosine similarity between embeddings, and that signal is built for meaning. Customers don’t always ask in meaning. They paste an error code, SSO-104, or a field name, include_completed=false, or a status line from a log: 503 maintenance.
The standard advice is to add keyword search and combine the two: hybrid search. This article tests that advice on the same documents, the same chunks, and the same token budget as Article #15, so that the only thing that changes is how the chunks are ranked.
The short version: keyword search did find things vector search missed, and the reverse, and combining them helped most when the budget was tight. But on these chunks vector search was already strong, the tokenizer choice I expected to matter didn’t, and one of the two standard ways of combining rankings lost a question that vector search had ranked first. The details are more useful than the summary.
Try to Understand It This Way
You ask two colleagues to find the page that answers a customer’s question in a thick manual.
The first one has read the whole manual and knows what each section is about. Ask “How do I stop people signing in from outside our office network?” and they go straight to the IP allowlist, although the question doesn’t contain the word “allowlist”. But read them SSO-104, and they look at you blankly: it doesn’t mean anything, so they guess at sections about single sign-on in general.
The second one only uses the index at the back of the book. SSO-104 is in the index, on one page, and they find it in seconds. But the office-network question has no word in it that the index lists for the allowlist page, so they come back with pages that happen to contain “can” and “how”.
The first colleague is vector search. The second is keyword search. Hybrid search asks both and merges their answers, and the interesting part is how you merge them.
Two Ways to Rank
Vector search turns the question and every chunk into embeddings and ranks chunks by cosine similarity, as in “Vector Databases Explained: What Problem Are They Solving? (opens in a new tab)” and every RAG demo since. It ranks every chunk, however weakly related.
Keyword search here is BM25, a ranking function used by Lucene and Elasticsearch and widely used in information retrieval. A chunk scores for each query word it contains. Rare words count more than common ones (that’s the idf part), repeated words count with diminishing returns (k1), and long chunks are penalized a little for containing many words (b):
score(chunk) = sum over query tokens t of
idf(t) * tf * (k1 + 1) / (tf + k1 * (1 - b + b * length / average length))
idf(t) = ln(1 + (N - df + 0.5) / (df + 0.5)) N chunks, df of them contain t
k1 = 1.2, b = 0.75 Elasticsearch's defaults
A chunk that contains none of the query’s words isn’t returned at all. That’s how a search engine behaves, and it matters later.
Before BM25 can count words, an analyzer decides what a word is, and identifiers are where that decision bites. The demo compares two:
words identifiers
SSO-104 sso, 104 sso, 104, sso-104
cursor_expired cursor, expired cursor, expired, cursor_expired
X-RateLimit-Remaining x, ratelimit, remaining ... + x-ratelimit-remaining
Neither analyzer stems words or drops stop words, so “signing” doesn’t match “sign”, and “can” and “how” count as words like any other.
Two Ways to Combine
The two methods produce scores on different scales: a cosine similarity, which is bounded, and a BM25 score, which has no upper limit. You can’t add them directly. There are two common answers.
Reciprocal rank fusion (RRF) ignores the scores and uses only the ranks. Each chunk present in a ranking gets 1 / (k + rank) from it, and nothing from a ranking it’s absent from; the sums decide the final order. Vector search ranks all 98 chunks, while BM25 returns only the ones that match, so a chunk can get a contribution from one ranking and not the other. Its authors, Cormack, Clarke, and Büttcher (2009), set k to 60, a value that “was fixed during a pilot investigation and not altered during subsequent validation”, and Elasticsearch uses the same default. This demo uses 60 too. You don’t calibrate scores or choose a weight, although the rank constant itself can be changed.
Weighted fusion keeps the scores, rescales each method’s scores for one query to the range 0 to 1 (min-max normalization), and mixes them: alpha * vector + (1 - alpha) * keyword. Here alpha was chosen on development questions only, from 0.0 to 1.0 in steps of 0.1. Min-max normalization makes the two scores comparable within one query. It doesn’t make a normalized 0.9 mean the same thing for two different queries.
The Experiment
The demo, 05-hybrid-search, keeps everything from Article #15 except the ranking: the same five documents, the same structure-headings chunks (98 chunks, Article #15’s best strategy), the same 1,000-token retrieved-context budget, and the same scoring rule. A question’s evidence is found if every passage that answers it is whole inside a retrieved chunk.
There are two sets of questions:
- The 60 from Article #15, unchanged. On these, vector search with this chunking already found everything. They’re reported separately, so that a set designed to find differences doesn’t hide how much vector search already handles.
- 40 new questions, written for where the methods should differ, and committed to the repository before any keyword-search code existed: 15 built around an exact string (an error code, a header, a field, a URL, a version), 15 paraphrases that share at most one content word with the passage that answers them, and 10 that mix the two.
Both sets are split into development and test questions. Two choices were made on development questions only, by rules written down before the first run: which analyzer the hybrids use, and the weighted fusion’s alpha.
Implementation note: the exact setup
Machine: Apple M4 Pro (24 GB), macOS 26.6.2
Runtime: Ollama 0.40.16, /api/embed
Embeddings: nomic-embed-text, ID 0a109f422b47, prefixes "search_query: " / "search_document: "
Chunks: structure-headings from Article #15: 98 chunks, 10,913 tokens
Budget: 1,000 tokens of retrieved chunks (Llama 3.2 tokens); chunks in rank order, a chunk
that doesn't fit what's left is skipped; also measured at 500 and 2,000
BM25: as in Lucene, k1 1.2, b 0.75, written out in about 40 lines per language;
only chunks containing a query token are returned
RRF: k = 60, over the full vector ranking and the keyword ranking
Weighted: BM25 scores every chunk, so one it doesn't match scores 0; each method's scores
are min-max normalized over all 98 chunks, per query; chunks whose combined
score is 0 are dropped; alpha from 0.0 to 1.0 in steps of 0.1, chosen on
development questions (ties: closest to 0.5)
Questions: 40 new (21 development, 19 test) and 60 from Article #15 (31 and 29)
Languages: Python 3.12.13 and Node.js 24.16.0, identical output and identical rankings
Runs: twice in each language, 2026-11-15, identical apart from timings
No chat model was used: this article is about what retrieval finds, and Article #15 already showed that what a small model does with it is a separate question.
Vector Search Was Already Strong
Here is how often each method found the evidence within 1,000 tokens:
new questions Article #15's questions
method dev (21) test (19) dev (31) test (29)
vector 18 17 31 29
keyword (words) 13 17 29 28
keyword (identifiers) 13 17 29 29
RRF 19 18 30 29
weighted (alpha 0.8) 20 18 31 28
Vector search found the evidence for all 60 of Article #15’s questions and for 35 of the 40 new ones. That was not what the questions were written to show. By kind, on the 19 new test questions:
method identifier (7) paraphrase (7) mixed (5)
vector 6 6 5
keyword (words) 7 5 5
keyword (identifiers) 7 5 5
RRF 7 6 5
weighted (alpha 0.8) 7 6 5
Keyword search found every identifier question and vector search all but one. On paraphrases, vector search was ahead by one. The hybrids matched the better method in each column.
Two things probably help it here. The chunks carry their section headings, so the chunk with the single sign-on error codes starts with “Single sign-on” and “Troubleshooting”, and is embedded with them. And the corpus is small: 98 chunks, so a 1,000-token budget holds about a tenth of everything. Being roughly right is often enough. With thousands of chunks, the same ranking quality would leave more questions outside the budget.
What Each One Finds That the Other Misses
Comparing vector search with keyword search using the words analyzer (the one the hybrids use), over all 100 questions at 1,000 tokens, ten questions were found only by vector search and two only by keyword search. With the identifiers analyzer it’s nine and two.
Keyword search’s two were the kind it exists for:
'What does a 503 with the code maintenance mean?'
'What does include_completed=false do?'
Vector search filled the budget with other chunks, many of them short release-note entries, and missed the API reference’s error table and its task-listing section. BM25 ranked both of those chunks first: maintenance, 503, and false each appear in only one chunk.
Six of vector search’s ten were paraphrases. “How do I stop people signing in from outside our office network?” shares no useful word with “Admins can limit sign-ins and API requests to a list of IP address ranges”. “Signing” isn’t “sign”, so BM25 matched that chunk only on “from”, “in”, and “our”, and ranked it eleventh. “Our accountant needs copies of the bills automatically” means “billing contact” and “invoices”, and BM25 can’t know that.
Keyword search also found five of the seven paraphrase test questions, and that needs an honest explanation. The words it matched in the right chunk were mostly ones like “can”, “a”, “after”, “how”, and “long”, with a few real ones (“tax”, “immediately”, “address”), and the right chunk only had to be among the ten or so that fit into the budget. On these questions, BM25 without stop words is mostly being lucky in a small corpus.
The Tokenizer Choice That Didn’t Matter
I expected the identifiers analyzer to matter: keep cursor_expired whole, and BM25 should find the error table instead of every chunk about cursors. On the development questions, it made no difference at all: 42 questions found with either analyzer, so by the rule fixed in advance, the hybrids use the simpler one.
The reason is in these documents. The parts of their identifiers are already rare: of the 98 chunks, 104 is in one, cursor and idempotency in four, scim in seven. A question that contains two such parts mostly matches the chunk that has both, whole identifier or not. The one test question where the two analyzers differed doesn’t contain an identifier at all: adding whole identifiers as extra tokens changed the chunks’ lengths and the rarity of words, and that changed the ranking enough to move a chunk across the budget line.
That’s a result about this corpus, not about analyzers. In documents where the parts of identifiers are common words, such as error codes like E500 next to “500 MB”, or product names made of dictionary words, the analyzer is exactly where keyword search succeeds or fails. Test it on your own identifiers.
Combining Them
Hybrid search helped most when the budget was tight. All 48 test questions, by budget:
method 500 tokens 1,000 tokens 2,000 tokens
vector 41 46 48
keyword (words) 41 45 46
RRF 45 47 47
weighted (alpha 0.8) 43 46 48
At 500 tokens, about five chunks, RRF found 45 where either method alone found 41. That’s the case for hybrid search: when only the top few chunks fit, a chunk that both methods rank fairly high beats one that only one method ranks high, and on these questions that was more often the right one. At 2,000 tokens, vector search alone found all 48, and RRF found 47.
RRF rewards agreement, and that has a cost. “Our accountant needs copies of the bills automatically” is ranked first by vector search. BM25 matches the chunk with the answer only on “the”, and ranks it 90th of the 91 chunks it returns. In RRF:
billing contact chunk: vector rank 1, keyword rank 90 1/61 + 1/150 = 0.0230
a chunk both rank 5th: vector rank 5, keyword rank 5 1/65 + 1/65 = 0.0308
Any chunk that both lists rank in their top 25 beats the one vector search was sure about. Because BM25 without stop words matched 91 of the 98 chunks for this question, almost every chunk was in both lists, and the billing contact chunk fell out of RRF’s top ten.
Weighted fusion needed tuning, and the tuning said “mostly vector”. On the development questions:
alpha (vector weight) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
questions found 42 43 46 48 49 49 49 50 51 50 49
Alpha 0.8, 80% vector, found 51 of 52, against 49 for vector search alone. On the test questions it matched vector search’s totals at 1,000 and 2,000 tokens and beat it at 500 (43 against 41); at 1,000 tokens it found one test question that vector search missed and lost another. With 52 development questions and differences of one or two, this is a rough choice, not a tuned optimum. A weight chosen on one set of documents and questions won’t transfer to another without measuring again.
The Two Questions Nothing Found
Two questions weren’t found by any method within 1,000 tokens:
- “Who else handles our information on your behalf?” The answer is the data processing policy’s table of subprocessors. Vector search didn’t place that chunk in its top ten, and BM25 matched it only on “on”. No method found it even at 2,000 tokens.
- “Do I pay extra for every person I add?” The answer is one sentence, “Prices are per organization, not per member”, above the plans table. Vector search ranked that chunk eighth, but at 199 tokens it no longer fit: the seven chunks above it already used 990 of the 1,000 tokens. At 2,000 tokens, vector search and weighted fusion found it.
Neither retrieval method reads the question and the chunk together. Both compare two things computed separately: two embeddings, or two bags of words. Comparing them together is what a reranker does, and it’s the next article.
What It Costs
Keyword search is the cheap part. In these runs, building a BM25 index over 98 chunks took 2 to 9 milliseconds, and scoring one question took about a tenth of a millisecond. Embedding one question took about 8 to 9 milliseconds, on a local model with nothing else to do, before the cosine comparison even started.
The cost of hybrid search isn’t compute. It’s another index to keep in sync with the documents, an analyzer to design, and, for weighted fusion, a weight to choose and re-choose whenever the documents or the embedding model change.
What Breaks
- Identifiers in vector search. An error code or a field name has little meaning to embed; vector search ranks whatever is about the same topic.
- Paraphrases in keyword search. No shared word, no match. And without stop words, BM25 “finds” chunks through words like “can” and “how”.
- An analyzer you didn’t test. Whether
SSO-104is one token or two decides what keyword search can find. Here it didn’t matter; on your identifiers it might. - RRF against a lone strong signal. A chunk only one method returns can lose to chunks both methods rank mediocre.
- Weights that don’t transfer. A fusion weight is fitted to one corpus, one embedding model, and one set of questions.
- Scores treated as comparable. Min-max normalization rescales one query’s scores; it doesn’t make scores mean the same thing across queries.
- Two separate representations. Neither method reads the question and the chunk together.
Engineering Decisions
1. Measure on questions that separate the methods
A set of questions written for one method’s strengths will make it look perfect. Write questions with identifiers, paraphrases, and both, and report them separately from your existing set.
2. Decide what a token is, deliberately
The analyzer is part of the retrieval design. Write down how identifiers, codes, and versions are split, and test that on the identifiers your users actually paste.
3. Keep the chunk’s context in what you embed
Headings in the chunk made vector search strong on identifier questions here. Fix chunking before adding a second retrieval method.
4. Choose RRF when you can’t tune, and know what it does
RRF avoids score calibration and weight selection. It still has a rank constant (60 in this demo), and it helped most at small budgets. It also favours chunks that both methods return, which can bury a chunk that only one method ranks first.
5. Tune weighted fusion on development data, and expect to re-tune
The weight is a fitted parameter. Choose it on development questions, report it on test questions, and choose it again when the documents or the embedding model change.
6. Look at the questions, not just the totals
The two that nothing found, and the one RRF lost, explain more about each method than the totals do.
What to Take Away
- Vector search and keyword search fail on different questions. Vector search misses identifiers; keyword search misses paraphrases.
- Hybrid search helped most when the budget was tight: 45 of 48 test questions within 500 tokens, against 41 for either method alone.
- On a small, well-chunked corpus, vector search alone came close. Good chunking narrowed the gap that hybrid search usually fills.
- How you merge matters. RRF rewards agreement; weighted fusion needs a weight that has to be measured.
- Both methods compare question and chunk separately. Some questions need a model that reads them together.
Think About These Use Cases
-
An internal IT help desk: Users paste error messages, ticket numbers, and hostnames. Which analyzer rules would you need, and how would you test them?
-
A legal document search: Lawyers search for exact clause numbers and defined terms, and also ask questions in plain language. Would you weight one method over the other?
-
A product catalogue: Product codes like
XR-2000-Band descriptions like “lightweight waterproof jacket”. How would you split the codes? -
A multilingual help center: Questions arrive in German against English documents. Which method still works, and why?
-
A support bot with a 300-token budget: Only two or three chunks fit. Which fusion method would you start with, and what would you measure?
If you want to work through one of these, take it to GPT along with this article. Ask GPT ↗️
Related Sources
- 05-hybrid-search: The companion demo: BM25 with two analyzers, RRF, weighted fusion, the 40 new questions, and the comparison at equal budgets (Python and JavaScript).
- The Probabilistic Relevance Framework: BM25 and Beyond (Robertson and Zaragoza, Foundations and Trends in Information Retrieval, 2009): Where BM25 comes from; reports that “values such as 0.5 < b < 0.8 and 1.2 < k1 < 2 are reasonably good in many circumstances”.
- Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods (Cormack, Clarke, and Büttcher, SIGIR 2009): The RRF formula and the choice of k = 60.
- Similarity settings (Elasticsearch documentation): BM25 as the default similarity, with k1 1.2 and b 0.75.
- Reciprocal rank fusion (Elasticsearch documentation): RRF in a production search engine, with a default rank constant of 60.
- Hybrid search scoring (RRF) (Azure AI Search documentation): How a managed search service merges keyword and vector results.
What’s Next?
Both methods here compare a question and a chunk that were turned into numbers separately. The two questions nothing found needed something that reads them together, and so did the chunk RRF buried.
In the next article, we’ll look at Reranking: Improving Retrieval Quality: a second pass that reads the question and each candidate chunk together, what it fixes, and what it costs.