<!-- generated by build_articles.py — edit content/science/hybrid-search.md instead -->
---
title: "Hybrid search 2026: BM25 plus vectors for RAG and AI agents"
canonical: "https://xerj.org/science/hybrid-search"
updated: "2026-11-20"
source: "content/science/hybrid-search.md"
---

# What is hybrid search?

**Short answer** (updated 2026-11-20): 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.

## Agent prompt

```text
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.
```

## Commands

### Command 1

Note: Install the single XERJ binary.

```sh
curl -fsSL https://xerj.org/get | sh
```

### Command 2

Note: Start a local node with a vector arm. The all-MiniLM-L6-v2 model downloads once, about 90 MB.

```sh
xerj --embed-mode neural
```

### Command 3

Note: Index a folder. Full-text and vector fields go into the same index.

```sh
xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain
```

### Command 4

Note: One hybrid request. Fill query_vector with your embedding; the empty array marks where the floats go.

```sh
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}'
```

## BM25, vector or hybrid: pick for your queries

*Figure: Runs in your browser and sends nothing. Each answer adds a point to the method it matches. The nDCG@10 scores are the XERJ BEIR runs published below.*

## How hybrid search works

*Figure: Runs in your browser and sends nothing. A walk-through of the request shape, not a benchmark; measured numbers are in the dataset table on this page.*

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](/science/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 |

*Figure: The fusion method is reciprocal rank fusion, as described by Cormack, Clarke and Buettcher (SIGIR 2009). How XERJ turns this on is on the hybrid-search answer. This figure does not report a new score.*

## 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.

*Figure: Runs in your browser and sends nothing. Measured by XERJ with --embed-mode neural and the built-in all-MiniLM-L6-v2 model; the default lexical embedder is not covered. Raw output is in benchmarks/beir-hybrid/results in the XERJ repository.*

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](/answers/hybrid-search-quality-measured-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](/answers/rag-without-vector-database).

## Run hybrid search on your own folder

1. Install: `curl -fsSL https://xerj.org/get | sh`
2. Start a local node with neural embeddings: `xerj --embed-mode neural`
3. Index a folder: `xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain`
4. Send one `hybrid` request with a `match` query, a `knn` query 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](/answers/what-is-hybrid-search), and [how XERJ combines search](/answers/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](https://doi.org/10.1561/1500000019) (2009). Dense vector retrieval for question answering is described by Karpukhin and colleagues in [Dense Passage Retrieval for Open-Domain Question Answering](https://arxiv.org/abs/2004.04906) (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](https://cormack.uwaterloo.ca/cormacksigir09-rrf.pdf) (SIGIR 2009). Those papers are research sources; the BEIR numbers above are XERJ measurements.

## Related terms

[Hybrid vs vector vs semantic search](/science/hybrid-vs-vector-vs-semantic-search), [BM25](/science/bm25), [semantic search](/science/semantic-search), [reciprocal rank fusion](/science/reciprocal-rank-fusion) and [reranking](/science/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](https://cormack.uwaterloo.ca/cormacksigir09-rrf.pdf)

## Related

- [Hybrid search vs vector search vs semantic search](/science/hybrid-vs-vector-vs-semantic-search)
- [Reciprocal rank fusion formula](/science/reciprocal-rank-fusion)
- [BM25 vs vector search](/science/bm25)
- [What is semantic search?](/science/semantic-search)
- [What is reranking?](/science/reranking)
- [How to run hybrid search in XERJ](/answers/what-is-hybrid-search)
- [How does XERJ combine BM25 and kNN?](/answers/how-xerj-combines-search)
- [How much better is hybrid search than BM25? Measured nDCG numbers](/answers/hybrid-search-quality-measured-ndcg)
- [RAG without a vector database: 3 vectorless RAG setups that work](/answers/rag-without-vector-database)
- [What is syntax-aware search?](/science/syntax-aware-search) (same intent: Science)
- [Neurosymbolic AI frameworks in 2026: open source tools for LLM reasoning and agent memory](/compare/neurosymbolic-ai-frameworks-2026) (same intent: Science)
- [What is agentic memory?](/science/agentic-memory) (same intent: Science)
