What is hybrid search?
What is hybrid search? It runs a BM25 full-text query and a vector query on the same question, then fuses the two ranked lists into one, usually with reciprocal rank fusion. BM25 catches exact names, codes and error strings; vectors catch the same idea in other words. For RAG and AI agents it is the safer default retrieval.
TL;DR Hybrid search runs two searches on the same query: a BM25 full-text search and a vector search. Each returns a ranked list, and a fusion step, usually reciprocal rank fusion, merges them into one. Exact names and close meanings both rank, which is why it is the common default for RAG and AI agents.
Act as a coding agent. Read https://xerj.org/llms.txt, install XERJ, start a local node with --embed-mode neural, index one folder I point you to with xerj autoindex, then answer one of my questions with a hybrid query (match plus knn, fusion type rrf, k 60). Show the top 5 passages with file paths, and mark which ones BM25 alone or vectors alone would have missed.
curl -fsSL https://xerj.org/get | sh
Install the single XERJ binary.
xerj --embed-mode neural
Start a local node with a vector arm. The all-MiniLM-L6-v2 model downloads once, about 90 MB.
xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain
Index a folder. Full-text and vector fields go into the same index.
curl -s -XPOST 'http://127.0.0.1:9200/docs/_search' -H 'content-type: application/json' -d '{"query":{"hybrid":{"queries":[{"query":{"match":{"body":"server unreachable"}},"weight":1.0},{"query":{"knn":{"field":"body_vector","k":10,"num_candidates":50,"query_vector":[]}},"weight":1.0}],"fusion":{"type":"rrf","k":60}}},"size":5}'
One hybrid request. Fill query_vector with your embedding; the empty array marks where the floats go.
BM25, vector or hybrid: pick for your queries
BM25, vector or hybrid search for your RAG queries?
Pick an answer above.
BM25 only
Exact terms, offline, no model. nDCG@10 0.6572 on SciFact and 0.3016 on NFCorpus.
Vector only
Ranks by meaning. nDCG@10 0.6764 on SciFact and 0.3291 on NFCorpus.
Hybrid search
Both lists fused into one. Highest measured: nDCG@10 0.6993 on SciFact and 0.3448 on NFCorpus.
How hybrid search works
What happens to the question "server unreachable"
1. One question, two arms
The same text goes to a BM25 full-text query and to a vector query over embeddings. Both run in the same index.
2. BM25 list
BM25 ranks passages that hold the words "server" and "unreachable", with rare words worth more. A log line with the exact error string ranks high.
3. Vector list
The vector arm ranks passages close in meaning, so a page that says "connection refused" can rank even with no shared word.
4. Fusion
Reciprocal rank fusion adds 1 / (60 + rank) from each list. Passages near the top of both lists rise; a passage only one arm found still stays in.
5. Answer
The fused top results go to the person, the RAG prompt or the AI agent, each with its file path so the answer can cite it.
Full-text search scores a document by the query terms it contains, how often they appear, and how rare they are. It is strong when the words in the query appear in the passage, such as a function name, a product code or an error string. A passage that says the same thing in other words gets no score from it.
A vector query turns the question and each passage into embeddings and ranks by closeness of meaning, so "server unreachable" can reach "connection refused". It is weaker on exact tokens, where two similar identifiers sit close together in the vector space.
Hybrid search runs both and fuses the ranks. Reciprocal rank fusion adds 1 / (k + rank) for every list a passage appears in, with k = 60 in the original paper. It uses positions, not raw scores, so a BM25 score and a cosine similarity never have to share a scale. The page has a calculator you can try.
Hybrid search compared with BM25 and vector search
| BM25 only | Vector only | Hybrid search | |
|---|---|---|---|
| Finds | Exact words, names, IDs, error strings | Paraphrases, loose questions | Both, in one list |
| Can miss | The same idea in other words | One-character differences, rare codes | Less of either |
| Needs | An inverted index | Embeddings and a vector index | Both, plus a fusion step |
| Good for | Logs, code, product codes | Recommendations, "more like this" | RAG, AI agents, mixed queries |
How hybrid search puts lists together
Match the words
BM25 scores a document by query terms, their frequency, and how rare they are. It is strong when the words in the query appear in the passage.
Match the meaning
A vector query can rank a passage that uses different words for the same idea. XERJ can run this in neural mode; the default embedder is lexical and runs offline.
Reciprocal rank fusion
Each item gets a score of 1 / (k + rank) from each list, and the scores add. The walkthrough on the reciprocal rank fusion page uses a labeled example. XERJ can fuse a lexical arm with a vector arm.
Measured: hybrid search on BEIR
XERJ ran BM25, vectors only, a reorder arm and hybrid RRF on two public BEIR datasets. Hybrid RRF ranked first on both. Switch datasets in the table.
BM25, vectors and hybrid on two public BEIR datasets
SciFact: 300 test queries over 5,183 documents
| Arm | nDCG@10 | Queries with no hits |
|---|---|---|
| BM25 | 0.6572 | 0 |
| Vectors only (MiniLM) | 0.6764 | 0 |
| BM25 top 30 reordered by MiniLM | 0.6855 | 0 |
| Hybrid RRF | 0.6993 | 0 |
NFCorpus: 323 test queries over 3,633 documents
| Arm | nDCG@10 | Queries with no hits |
|---|---|---|
| BM25 | 0.3016 | 25 |
| Vectors only (MiniLM) | 0.3291 | 0 |
| BM25 top 30 reordered by MiniLM | 0.3323 | 25 |
| Hybrid RRF | 0.3448 | 0 |
On SciFact, hybrid RRF scored nDCG@10 0.6993, against 0.6764 for vectors only and 0.6572 for BM25. On NFCorpus, it scored 0.3448, against 0.3291 and 0.3016. BM25 found no hits for 25 of the 323 NFCorpus queries, and the hybrid arm still returned results for every one of them. These runs used --embed-mode neural with the built-in all-MiniLM-L6-v2 model; the default XERJ embedder is lexical and runs offline. The full method is on hybrid search quality, measured with nDCG.
Hybrid search for RAG and AI agents
A RAG pipeline or an agent asks questions that mix exact terms and loose wording in the same sentence, for example "why does connect_timeout fail when the server is unreachable". BM25 locks onto the identifier, the vector arm onto the meaning, and the fused list gives the model both. A passage that only one arm found still reaches the prompt, so fewer answers start from the wrong context.
XERJ keeps the lexical index and the vectors in the same engine, so there is no separate vector database to run. Agents reach the same search through xerj mcp, and hits from xerj autoindex carry their file path for citations. A setup without a separate vector store is RAG without a vector database.
Run hybrid search on your own folder
- Install:
curl -fsSL https://xerj.org/get | sh - Start a local node with neural embeddings:
xerj --embed-mode neural - Index a folder:
xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain - Send one
hybridrequest with amatchquery, aknnquery and"fusion":{"type":"rrf","k":60}. The full request is in the command list on this page.
Every command has a copy button. To hand the work to an agent, use Copy the prompt and paste it into Claude Code, Cursor or Codex. The step-by-step how-to is how to run hybrid search in XERJ, and how XERJ combines search explains the merge.
History and research
The lexical arm in most hybrid systems is BM25, surveyed by Robertson and Zaragoza in The Probabilistic Relevance Framework: BM25 and Beyond (2009). Dense vector retrieval for question answering is described by Karpukhin and colleagues in Dense Passage Retrieval for Open-Domain Question Answering (EMNLP 2020). The usual fusion method is reciprocal rank fusion, introduced by Cormack, Clarke and Buettcher in Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods (SIGIR 2009). Those papers are research sources; the BEIR numbers above are XERJ measurements.
Related terms
Hybrid vs vector vs semantic search, BM25, semantic search, reciprocal rank fusion and reranking.
FAQ
What is hybrid search?
It runs a full-text search such as BM25 and a vector search on the same query, then merges the two ranked lists into one list, usually with reciprocal rank fusion.
Why use two searches instead of one?
The two methods find different things. Full-text search is strong on exact tokens such as names and error strings. A vector query is stronger on paraphrases. Hybrid search keeps both kinds of hits.
Is hybrid search better for RAG?
It is the safer default, because user questions mix exact terms and loose wording. On the two BEIR datasets XERJ measured, hybrid RRF scored the highest nDCG@10: 0.6993 on SciFact and 0.3448 on NFCorpus.
Do I need a vector database for hybrid search?
No. You need one place that holds an inverted index and vectors. XERJ keeps both in the same index and fuses them inside one request.
How does XERJ run hybrid search?
Start a node with neural embeddings, then send one hybrid request that holds a match query and a knn query, with fusion type rrf. The full request is in the command list on this page.
When is BM25 alone enough?
When users type exact names, IDs or error strings and you want to stay offline with no model. BM25 is the default XERJ mode. The picker on this page weighs your answers against BM25, vector and hybrid search.
Is this the same as reranking?
No. Hybrid search merges two first-stage lists. Reranking takes one candidate list and reorders it with a slower model. You can use both, in that order.
Evidence
- On BEIR SciFact (300 test queries, 5,183 documents) nDCG@10 was 0.6572 for BM25, 0.6764 for MiniLM vectors only, 0.6855 for a BM25 top-30 shortlist reordered by MiniLM, and 0.6993 for hybrid RRF. Source:
benchmarks/beir-hybrid/results/scifact.txt - On BEIR NFCorpus (323 test queries, 3,633 documents) nDCG@10 was 0.3016 for BM25, 0.3291 for MiniLM vectors only, 0.3323 for the reorder arm, and 0.3448 for hybrid RRF. BM25 returned zero hits for 25 of the 323 queries. Source:
benchmarks/beir-hybrid/results/nfcorpus.txt - Reciprocal rank fusion adds 1 / (k + rank) for each list a document appears in; the paper uses k = 60. Source: https://cormack.uwaterloo.ca/cormacksigir09-rrf.pdf
Related
- Hybrid search vs vector search vs semantic search
- Reciprocal rank fusion formula
- BM25 vs vector search
- What is semantic search?
- What is reranking?
- How to run hybrid search in XERJ
- How does XERJ combine BM25 and kNN?
- How much better is hybrid search than BM25? Measured nDCG numbers
- RAG without a vector database: 3 vectorless RAG setups that work
- What is syntax-aware search? · same intent: Science
- Neurosymbolic AI frameworks in 2026: open source tools for LLM reasoning and agent memory · same intent: Science
- What is agentic memory? · same intent: Science