Hybrid search: combining keyword and semantic retrieval
Hybrid search runs keyword (BM25) and vector search on the same query, then merges the two ranked lists, usually with reciprocal rank fusion or a weighted sum.
Hybrid search runs the same query through two retrievers, a keyword index (usually BM25) and a vector index of embeddings, and merges the two ranked lists into one. Keyword search finds exact strings such as part numbers, error codes and names; vector search finds passages that mean the same thing in different words. The merge is usually done with reciprocal rank fusion, which needs no tuning, or with a weighted sum of normalised scores, which does better once you have labelled queries to tune it.
That is the whole idea. The details that decide whether it works are how each side is configured, how deep each list goes before the merge, and how you check that the merged list is better than what you had.
Two questions, two failures
As an illustration, picture a maintenance assistant over a plant's manuals, service notes and spares lists. Two engineers ask it something on the same morning.
The first types "P-4471 seal leak". The answer lives in a service note that mentions P-4471 twice. A pure vector search turns that query into an embedding, and the embedding of a short code carries very little meaning, so the top results are general pages about seal leaks on any pump. The one note about this pump might sit at position 14.
The second types "why is the cooling water pump dripping underneath". The relevant note says "mechanical seal failure on the coolant circulation pump, visible weep at the gland". A keyword index has almost nothing to match: no "dripping", no "underneath", and "cooling water" against "coolant". Vector search finds it easily.
Neither retriever is broken. They are good at different things, and real users send both kinds of query, often in the same session. Hybrid search exists because picking one retriever means accepting one of these failures.
What each side is actually doing
BM25 is a scoring formula from classical information retrieval. It rewards a document for containing the query terms, gives more weight to rare terms than common ones, and stops rewarding repetition after a point. Two parameters shape it. In Elasticsearch, where BM25 is the default similarity, k1 (default 1.2) "controls non-linear term frequency normalization (saturation)", which is how fast extra mentions of a term stop adding score, and b (default 0.75) "controls to what degree document length normalizes tf values", which stops long documents winning simply because they contain more words. Most teams never change these, and that is usually fine.
Vector search embeds the query and returns the stored chunks whose embeddings sit closest to it. It knows nothing about exact strings. It knows that "dripping" and "weep" are related because the embedding model learned that from training text. Our explainer on vector databases covers how the index behind it works and where it loses recall.
There is good evidence that the old method holds up. The BEIR benchmark (Thakur et al., 2021) tested 10 retrieval systems across 18 public datasets in a zero-shot setting, meaning the models had not been trained on those domains. Its authors concluded that BM25 holds up as a strong baseline, and that dense and sparse retrieval models, while cheaper to run, "often underperform other approaches" when moved to new domains. The best average results came from re-ranking and late-interaction models, which are more expensive to run. Your company's documents are a new domain for any off-the-shelf embedding model, so that finding applies directly: do not throw away keyword search just because you added vectors.
Merging two lists that do not speak the same language
The hard part of hybrid search is the merge. A BM25 score of 14.2 and a cosine similarity of 0.81 are not on the same scale, and neither has a fixed maximum you can rely on across queries. Adding them together directly lets whichever retriever produces bigger numbers dominate. There are two sane ways out.
Reciprocal rank fusion ignores the scores and uses only positions. Cormack, Clarke and Büttcher introduced it at SIGIR 2009: each document gets 1 / (k + r) for every list it appears in, where r is its rank in that list, and the documents are sorted by the sum. They fixed k = 60 during a pilot study, and their table of k values from 0 to 90 shows the results barely moved across that range; in their words, 60 "was near-optimal, but that the choice was not critical". The constant keeps one system's first-place result from overwhelming everything else. In their experiments RRF beat Condorcet Fuse, CombMNZ and the best individual system by 4% to 5% on average. Elasticsearch implements the same formula, with rank_constant defaulting to 60, and its documentation says plainly that "RRF requires no tuning."
Convex combination normalises each retriever's scores onto a common range, then takes a weighted sum: α times one score plus (1 − α) times the other. Elasticsearch's linear retriever does this, offering minmax and l2_norm normalisers with each weight defaulting to 1.0. The catch is that you have to choose the weight, and the right weight depends on your documents and your users' queries.
Which one wins? Bruch, Gai and Ingber studied exactly this in 2022 and reached two findings that cut against common advice. First, "contrary to existing studies", they found RRF sensitive to its parameters. Second, a convex combination beat RRF both in-domain and out-of-domain, and it was sample efficient: a small set of labelled examples was enough to tune its single weight. They also found the choice of normalisation method mattered little once the weight was learned.
| Reciprocal rank fusion | Weighted score combination | |
|---|---|---|
| Uses | Rank positions only | Normalised scores |
| Needs labelled queries | No | A small set to choose the weight |
| Main setting | k (60 in the original paper and in Elasticsearch) | The weight α, plus a normaliser |
| Strength | Works on day one; immune to score scale | Better results in the Bruch et al. study once tuned |
| Weakness | Throws away how confident each retriever was | A badly chosen weight can be worse than either retriever alone |
My recommendation is to start with RRF because you can ship it before you have a single labelled query, and to move to a weighted combination once you have collected a hundred or two real queries with known good answers. At that point the tuning is cheap and the study says it pays.
A fusion example you can check by hand
Here is the arithmetic behind the diagram, with invented documents. The keyword list has the P-4471 service note first, a spares list second and a seal specification third. The vector list has a generic leak checklist first, the same seal specification second and a pump FAQ third.
The service note appears only in the keyword list, at rank 1, so it scores 1/61, about 0.0164. The leak checklist gets the same 0.0164 from the vector list. The seal specification appears in both: 1/63 + 1/62, about 0.0159 + 0.0161 = 0.0320. It comes out on top, nearly twice the score of either first-place result.
That is RRF's character in one example. It rewards agreement. Most of the time that is what you want, because a passage both retrievers like is rarely a fluke. But look at what happened to the service note, which was the exact document the engineer needed: it tied for second with a generic checklist. If your users often search by code, that is a real cost, and it is one reason the weighted approach can win once tuned, since a strong BM25 score on a rare term can be given the weight it deserves. A reranker after fusion, which reads each candidate against the question, is the other fix; the RAG explainer covers where it fits in the pipeline.
Building it on Postgres
Many teams already have their documents in Postgres, and the pgvector README has a short section for exactly this case: "Use together with Postgres full-text search for hybrid search", then combine with "Reciprocal Rank Fusion or a cross-encoder". The work comes down to a few steps.
- Add a
tsvectorcolumn built from each chunk's text with a text search configuration that matches its language, and put a GIN index on it. - Keep the embedding in a
vectorcolumn on the same row, with an HNSW or IVFFlat index once the table is large enough to need one. - At query time, run the full-text query and the vector query separately, each returning its top 50 or so chunk IDs with their rank, using
row_number()over each ordering. - Join the two lists on chunk ID, compute the sum of 1 / (60 + rank) for each, and sort.
- Send the top 10 or 20 to a reranker or straight to the model.
One detail surprises people. Postgres's ts_rank and ts_rank_cd are not BM25. The documentation states that "the ranking functions do not use any global information", so they score each document against the query without knowing how rare a term is across the whole collection. For RRF that matters less than you might expect, because RRF only uses the order. The rare-term problem does show up in which documents make the top 50, so if your corpus has a few very common words that match everything, check the keyword list on its own before trusting the fused one.
Putting both indexes on the same row has a benefit that is easy to miss: every filter you apply (tenant, document version, who may read it) is written once and applied to both queries the same way.
Where hybrid search goes wrong
Most hybrid search failures I would expect to find in a review are not about the fusion formula. They are about one leg being quietly weaker than the team thinks.
The tokenizer is the first suspect. Codes like "P-4471", "INV/2026/0193" or "SKU 88-A" may be split into pieces, have punctuation dropped, or be stemmed into something odd, and then the keyword leg cannot find the one thing it exists to find. Run your ten most common code formats through the analyser (in Postgres, ts_debug shows how text is parsed) and look at the tokens before you go any further. The language configuration matters too: an English stemmer applied to Hindi or Tamil text in a mixed document set will do strange things, and a simple, non-stemming configuration is often safer for those fields.
Shallow candidate lists are the second. If each retriever returns only its top 10 and you fuse those, a document ranked 12th by one side and 3rd by the other never gets the chance to rise. Pull deeper on each side than you will finally keep. Elasticsearch exposes this as rank_window_size, which defaults to the query's size, so if you want a deeper window you have to set it.
Filters applied unevenly are the third, and the dangerous one. If the vector query respects document permissions and the keyword query does not, the fused list can contain chunks the user should never see, and they will arrive with a high score because of an exact keyword hit. Access rules belong inside both retrievals, using the same source of truth. In CloudOEngine, data sources and the AI runtime with RAG share one permission model, so the rule on a source document is the rule both retrieval paths see, rather than a copy someone maintains by hand.
Duplicate chunks are the last. Overlapping chunks from the same section can take several of the top 10 slots between them. Collapse by source document or section after fusion so the model sees a spread of evidence. Our guide to chunking strategies covers how overlap creates this in the first place.
Prove it helped before you keep it
Hybrid search adds a second index to build, store and keep in sync. It should earn that.
The test is the same one you would use for any retrieval change. Collect a few hundred real queries from logs, and label the chunk or document that should come back for each. Then split them by type: queries with codes or names in them, natural-language questions, and short keyword queries. Measure recall at 10 for keyword alone, vector alone and fused, per type. The per-type split is the point, because a fused system that wins overall can still lose badly on code lookups, which is exactly what the RRF example above predicts.
Once that set exists, you have what the Bruch et al. study says a weighted combination needs. Sweep the weight from 0 to 1 in steps of 0.1, pick the best value on half the queries, and check it on the other half.
Offline numbers are not the end of it. When a user reports a wrong answer, you need to see what retrieval returned for that exact query: which chunks came from which leg, and where they landed after fusion. In CloudOEngine every agent step and tool call is traced and inspectable, so you can open the run behind a bad answer and see the passages the model was given. Our article on evaluating LLM applications covers how to turn those failures into regression tests.
How CloudOEngine helps
CloudOEngine is one platform and one console for connecting data (databases, files and camera streams), running pipelines and running AI. Its AI runtime includes an LLM gateway, agents with tool access and RAG, so the documents you index and the assistant that searches them sit on the same platform as the sources they came from.
The riskiest part of hybrid search is applying access rules evenly across two retrieval paths. Data, pipelines and AI in CloudOEngine share one permission model and one audit trail, so you define who may read a document once. Governance is included, not upsold: tenant isolation, role-based access, audit logs and per-tenant encrypted secrets.
Debugging retrieval needs evidence. Agents in CloudOEngine run real tools, such as filing a ticket, and every step and tool call is traced and inspectable, so when an answer is wrong you can open that run and see what was retrieved before you start changing fusion weights. Where an agent's next step is an action rather than an answer, Autopilot can require a person to approve it, in the app or through an email approve link, before it runs.
CloudOEngine is built in Bengaluru, India.
Book a demo or see the AI runtime.
Frequently asked questions
What is hybrid search?
Hybrid search sends one query to two retrievers, a keyword index such as BM25 and a vector index of embeddings, and merges their ranked results into one list. Keyword search catches exact terms like part numbers and error codes, and vector search catches paraphrases, so together they miss less than either alone.
What is reciprocal rank fusion (RRF)?
RRF scores each document by adding 1 / (k + rank) for every result list it appears in, then sorts by that sum. It uses only positions, not raw scores, so it can merge lists whose scores are on completely different scales. The constant k was set to 60 in the original 2009 paper, and Elasticsearch uses 60 as its default.
Is RRF or a weighted score combination better?
A 2022 study by Bruch, Gai and Ingber found that a convex (weighted) combination of normalised scores beat RRF both in-domain and out-of-domain, and needed only a small set of labelled queries to tune its one weight. RRF is still the easier starting point because it works without any labelled data.
Can I do hybrid search in PostgreSQL?
Yes. The pgvector README suggests using it together with Postgres full-text search and combining the two result lists with reciprocal rank fusion or a cross-encoder. Postgres's built-in ts_rank functions do not use corpus-wide statistics, so they are not BM25, but RRF only needs the order of results.
How many results should each retriever return before fusion?
Each retriever should return more candidates than you will finally use, because a document ranked 30th by one retriever and 5th by the other can end up near the top after fusion. Pulling 50 to 100 per side for a final top 10 is a reasonable illustration to start testing from, then measure recall on your own queries.
Sources
- Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods (Cormack, Clarke and Büttcher, SIGIR 2009)
- An Analysis of Fusion Functions for Hybrid Retrieval (Bruch, Gai and Ingber, 2022)
- BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models (Thakur et al., 2021)
- pgvector: open-source vector similarity search for Postgres (README, Hybrid Search)
- PostgreSQL documentation: Controlling Text Search (ranking search results)
- Elasticsearch: Similarity settings (BM25 k1 and b)
- Elasticsearch: Reciprocal rank fusion
- Elasticsearch: Linear retriever
