For AI agents: this page is also available as Markdown at /docs/hybrid-search.md. Every docs page is: add .md to its URL. llms.txt lists them all.
Hybrid search
Hybrid search runs a keyword query and a vector search together and merges the results. The two fail in opposite ways: keywords miss paraphrases and synonyms, and vectors miss exact identifiers, rare names and part numbers. With both, "waterproof jacket for hiking" matches on meaning and "XJ-4421" still finds the exact product.
There are two ways to combine them, both on POST /v1/search/{collection} with language: "es":
- rank fusion, which ranks each source on its own and merges the lists with reciprocal rank fusion (RRF) or weighted linear fusion, written as Elasticsearch
rrfandlinearretrievers, and - summed scores, where a
knnsection sits beside a textqueryand the two scores are added.
The same requests work on the Elasticsearch- and OpenSearch-compatible APIs, and the turbopuffer-compatible API has its own RRF multi-query.
#Fusion
A fusion takes several retrievers, each producing a ranked list from its own query, and merges the lists. On /v1, the retriever goes inside query, and the request's filters apply to every retriever:
curl -s https://api.warpsearch.io/v1/search/books \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"language": "es",
"query": {
"retriever": {
"rrf": {
"retrievers": [
{ "standard": { "query": { "match": { "title_t": "dune" } } } },
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100, "num_candidates": 200 } }
],
"rank_constant": 60,
"rank_window_size": 100
}
}
},
"filters": [{ "term": { "kind_s": "fiction" } }],
"limit": 10,
"fields": ["id", "title_t"]
}'
curl -s https://api.warpsearch.io/compat/es/books/_search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"retriever": {
"rrf": {
"retrievers": [
{ "standard": { "query": { "match": { "title_t": "dune" } } } },
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100, "num_candidates": 200 } }
],
"filter": { "term": { "kind_s": "fiction" } },
"rank_constant": 60,
"rank_window_size": 100
}
},
"size": 10,
"_source": ["title_t"]
}'
A hybrid query with the search pipeline in the body (stored pipelines are not supported). Only the score-ranker-processor (RRF) is accepted:
curl -s https://api.warpsearch.io/compat/opensearch/books/_search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": {
"hybrid": {
"queries": [
{ "match": { "title_t": "dune" } },
{ "knn": { "embedding_v": { "vector": [0.75, 0.15, 0.10], "k": 100 } } }
],
"filter": { "term": { "kind_s": "fiction" } },
"pagination_depth": 100
}
},
"search_pipeline": {
"phase_results_processors": [
{ "score-ranker-processor": { "combination": { "technique": "rrf", "rank_constant": 60 } } }
]
},
"size": 10
}'
A multi-query with rerank_by RRF:
curl -s https://api.warpsearch.io/compat/turbopuffer/v2/namespaces/books/query \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"queries": [
{ "rank_by": ["title_t", "BM25", "dune"], "filters": ["kind_s", "Eq", "fiction"], "top_k": 100 },
{ "rank_by": ["embedding_v", "ANN", [0.75, 0.15, 0.10]], "filters": ["kind_s", "Eq", "fiction"], "top_k": 100 }
],
"rerank_by": ["RRF", { "rank_constant": 60 }],
"limit": 10
}'
| Field | Meaning |
|---|---|
retrievers | The ranked inputs: standard (a query, with its own filter and, under rrf, sort) or knn. Wrap one as {"retriever": ..., "weight": w} to weight it. |
filter | Shared by every retriever and ANDed with each one's own filter. The request's filters on /v1 do the same. |
rank_constant | RRF smoothing constant, at least 1. Defaults to 60. |
rank_window_size | How many results each retriever contributes. Defaults to 10, and must be at least limit. |
The fusion is rrf or linear. Retrievers do not nest: a fusion's retrievers are standard or knn. The OpenSearch and turbopuffer forms are described in OpenSearch and turbopuffer compatibility.
#Reciprocal rank fusion
With RRF, a document scores weight / (k + rank) for every source that returned it, summed over sources, with ranks starting at 1. Only ranks count, so BM25 scores and cosine similarities never need to share a scale, and RRF works well as a default without tuning.
A document ranked first by both retrievers above scores 1/61 + 1/61. A document found by only one source still appears, with a smaller score.
#Weights
Weights scale a source's contribution without changing which candidates it brings:
{
"language": "es",
"query": {
"retriever": {
"rrf": {
"retrievers": [
{ "retriever": { "standard": { "query": { "match": { "title_t": "dune" } } } }, "weight": 1 },
{ "retriever": { "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100 } }, "weight": 2 }
],
"rank_window_size": 100
}
}
}
}
Weights must be finite and at least 0, and at least one must be above 0. A weight of 0 switches the retriever off: it is not run, and its documents do not reach the result. You can use this to toggle a source from configuration without rewriting the request. The OpenSearch score ranker takes parameters.weights (summing to 1), and turbopuffer RRF takes weights.
#Linear fusion
Linear fusion combines scores instead of ranks. Each source's scores are rescaled to the range 0 to 1 over its own result list, then summed with the weights:
normalized(d) = (score(d) - min) / (max - min)
fused(d) = sum over sources of weight * normalized(d)
{
"language": "es",
"query": {
"retriever": {
"linear": {
"retrievers": [
{ "retriever": { "standard": { "query": { "match": { "title_t": "dune" } } } }, "weight": 0.3, "normalizer": "minmax" },
{ "retriever": { "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100 } }, "weight": 0.7, "normalizer": "minmax" }
],
"rank_window_size": 100
}
}
}
}
min and max are the lowest and highest scores in that source's list, so its best document gets 1 and its worst gets 0. A source that did not return a document contributes 0 to it. If all scores in a list are equal, every document in it gets 1.
minmax is the only normalizer, and it must be set, on each retriever or once on linear. Linear fusion is available in the WarpSearch and Elasticsearch forms; the OpenSearch normalization-processor is not supported.
Prefer RRF when score distributions are unknown or unstable, or when a source is sorted by a field. Prefer linear when score magnitudes carry information you want to keep, such as a clear winner in one source beating a near tie in another, and you can tune weights against relevance judgments. Min-max is sensitive to outliers and to the list size, so retune weights after changing a source's rank_window_size. Every retriever under linear fusion must rank by relevance score.
With two sources, weights α and 1 - α make linear fusion a convex combination, and α is the only setting to tune. A few dozen judged queries are usually enough to choose it: run the judgment list at α = 0.1, 0.2, up to 0.9, and keep the best. Search does not learn the weights for you. For when to pick RRF or linear, see Choosing a ranking strategy.
#Sources
A fusion's sources do not have to be one keyword query and one vector search. Any number of standard and knn retrievers can be fused, each with its own query, filter and window.
#A source sorted by a field
A standard retriever with a sort ranks its documents by that field instead of by score. Under RRF, only ranks count, so a recency or popularity ordering can be fused with relevance orderings. This blends "matches well" with "is new" without putting dates and scores on one scale:
{
"language": "es",
"query": {
"retriever": {
"rrf": {
"retrievers": [
{ "standard": { "query": { "match": { "title_t": "dune" } } } },
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100 } },
{ "retriever": { "standard": {
"query": { "match": { "title_t": "dune" } },
"sort": [{ "published_dt": "desc" }]
} }, "weight": 0.5 }
],
"rank_window_size": 100
}
}
},
"limit": 10
}
The third source holds the newest documents that match dune. Its lower weight keeps freshness a tie-breaker rather than the main order. Keep a query on a sorted source: sorted over the whole collection, it would push recent but unrelated documents into the fusion. Sorted sources work only with rrf; linear rejects them.
#A minimum score per source
min_score on a standard retriever drops that source's weak matches before fusion, so a document that barely matches the keywords gets no keyword contribution:
{ "standard": { "query": { "match": { "title_t": "dune" } }, "min_score": 2.0 } }
Text scores vary by query and collection, so pick the threshold from real queries. On a knn retriever the equivalent is similarity, whose scale does not depend on the query.
#Several vector fields
Each knn retriever searches one vector field, so a fusion can combine several embeddings, such as one of the title and one of the body, or a text and an image embedding:
{
"language": "es",
"query": {
"retriever": {
"rrf": {
"retrievers": [
{ "knn": { "field": "title_v", "query_vector": [0.75, 0.15, 0.10], "k": 100 } },
{ "knn": { "field": "body_v", "query_vector": [0.71, 0.20, 0.09], "k": 100 } },
{ "standard": { "query": { "match": { "body_t": "dune" } } } }
],
"rank_window_size": 100
}
}
}
}
Each vector must come from the model that produced its field. To store several vectors per document in one field instead, see Multi-vector fields.
#A boosted source
A source's query can be a function_score, so business signals shape that source before fusion. Here the keyword side favors recent books, and the vector side stays pure:
{
"language": "es",
"query": {
"retriever": {
"linear": {
"retrievers": [
{ "retriever": { "standard": { "query": { "function_score": {
"query": { "match": { "title_t": "dune" } },
"functions": [{ "gauss": { "published_dt": { "origin": "now", "scale": "365d" } } }],
"boost_mode": "multiply"
} } } }, "weight": 0.4, "normalizer": "minmax" },
{ "retriever": { "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100 } },
"weight": 0.6, "normalizer": "minmax" }
],
"rank_window_size": 100
}
}
}
}
The fused list itself cannot be rescored, so put a signal that should apply to every document into each source, or add it as a sorted source under RRF. See Ranking with business signals.
#Pools, filters and facets
| Topic | Behavior |
|---|---|
| Pool size | A document outside a retriever's window cannot contribute from that retriever. Size rank_window_size for the recall your page size needs; 50 to 200 is a common range. |
| Paging | offset (from) pages within the union of the windows and does not enlarge them. Deep paging needs a larger rank_window_size. |
| Filters | The fusion-level filter (or filters on /v1) applies to every retriever, and a retriever can add its own on top. Filters apply inside the vector search, not afterwards. post_filters (post_filter) is not supported with fusion. |
| Facets | Aggregations count every document a retriever matches (its query within its filters, or a kNN retriever's k nearest), as Elasticsearch does, not only the fused page. |
Sorting and min_score | A fused search cannot also be sorted or cut by min_score. Sort or cut a source instead (Sources). |
| One hit per entity | collapse works on the fused list and inside a standard source. See One result per entity. |
#One result per entity
When documents are chunks of a parent, or variants of a product, one entity can fill the fused page. Put collapse beside the retriever, and the fused list keeps the best document of each value:
{
"language": "es",
"query": {
"retriever": {
"rrf": {
"retrievers": [
{ "standard": { "query": { "match": { "chunk_t": "reset the router" } } } },
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 50, "unit": "groups" } }
],
"rank_window_size": 100
}
},
"collapse": { "field": "parent_id_s", "inner_hits": { "name": "more", "size": 2 } }
},
"limit": 10
}
{
"retriever": {
"rrf": {
"retrievers": [
{ "standard": { "query": { "match": { "chunk_t": "reset the router" } } } },
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 50, "unit": "groups" } }
],
"rank_window_size": 100
}
},
"collapse": { "field": "parent_id_s", "inner_hits": { "name": "more", "size": 2 } },
"size": 10
}
- Collapsing happens after fusion and before paging, so
limit(size) andoffset(from) count groups. Each group is headed by its best fused document, andinner_hitslists more of its members. - The total and the facets still count documents, as without
collapse. "unit": "groups"on aknnretriever makes itskcount groups, so it brings 50 different parents rather than 50 chunks that may share a few. See Nearest groups.- A
standardsource can also collapse its own list before fusion, with"collapse": {"field": ...}inside the retriever (noinner_hitsthere). Itsrank_window_sizethen counts groups. Use this when one source, such as a keyword search over chunks, would otherwise spend its window on one parent.
The collapse field must be a single-valued string, id, integer or date field. Collapse is not available over several collections or on partitioned collections.
#Summed scores
Instead of a fusion, you can put a knn section beside the text query. A document matches if either part matches, and its score is the sum of the two scores, each times its boost. This is how Elasticsearch scores a knn section next to a query:
curl -s https://api.warpsearch.io/v1/search/books \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"language": "es",
"query": {
"query": { "match": { "title_t": { "query": "dune", "boost": 0.4 } } },
"knn": {
"field": "embedding_v",
"query_vector": [0.75, 0.15, 0.10],
"k": 50,
"num_candidates": 200,
"boost": 0.6,
"filter": { "term": { "kind_s": "fiction" } }
}
},
"limit": 10
}'
curl -s https://api.warpsearch.io/compat/es/books/_search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": { "match": { "title_t": { "query": "dune", "boost": 0.4 } } },
"knn": {
"field": "embedding_v",
"query_vector": [0.75, 0.15, 0.10],
"k": 50,
"num_candidates": 200,
"boost": 0.6,
"filter": { "term": { "kind_s": "fiction" } }
},
"size": 10
}'
The knn query clause works inside a bool query, beside must and should clauses:
curl -s https://api.warpsearch.io/compat/opensearch/books/_search \
-H "Authorization: Bearer $WARPSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"should": [
{ "match": { "title_t": { "query": "dune", "boost": 0.4 } } },
{ "knn": { "embedding_v": { "vector": [0.75, 0.15, 0.10], "k": 50, "boost": 0.6,
"filter": { "term": { "kind_s": "fiction" } } } } }
]
}
},
"size": 10
}'
Vector scores are WarpSearch similarity scores (raw cosine or dot product), not Elasticsearch's rescaled values, so boosts tuned on Elasticsearch may need retuning. A knn section's own filter restricts only its candidates. To filter the keyword side too, put the filter in filters on /v1, or inside the query as well.
On Solr, q={!knn f=embedding_v topK=50}[0.75, 0.15, 0.10] runs a vector search with fq filters applied before the neighbors are chosen, but there is no Solr form that combines it with a keyword query. See Elasticsearch, OpenSearch and Solr.
Summed scores are not rank fusion. For RRF or normalized linear combination, use an rrf or linear retriever (Fusion).
Because the two scores are added as they are, their scales matter: a BM25 score is often 5 to 20, and a cosine similarity is at most 1, so unboosted, the keyword side usually decides the order. Set the boosts from measurements, not by assumption. A knn clause also scores only its own k nearest documents. Others that match only the keywords get no vector score at all.
#The better of the two: dis_max
dis_max scores a document by its best clause instead of the sum, plus tie_breaker times the other matching clauses. Use it when either signal alone is good enough evidence, so a document does not win just because it matched both weakly:
{
"language": "es",
"query": {
"dis_max": {
"queries": [
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 50, "boost": 10 } },
{ "match": { "title_t": "dune" } }
],
"tie_breaker": 0.3
}
},
"limit": 10
}
tie_breaker 0 keeps only the best clause, and 1 adds them all, which is the same as summed scores. The clauses still compete on raw scores, so the boost on the knn clause above lifts cosine similarities toward the BM25 range. Tune it the same way.
#Both must match
With both clauses under must, a document has to be among the k nearest neighbors and also match the keywords, and its score is the sum:
{
"language": "es",
"query": {
"bool": {
"must": [
{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 100 } },
{ "match": { "title_t": "dune" } }
]
}
}
}
The vector search picks its k first, and the keyword clause then removes those that do not match, so the result can hold fewer than k documents, and the response may carry a warning saying so. Raise k if too few remain. To choose the neighbors only among keyword matches instead, see the next section.
#Vector search within keyword matches
Sometimes the keywords should decide what is eligible, and meaning should decide the order: a search that must mention a part number, a product line or a legal term, ranked by how well each match answers the question. Put the keyword query in the knn section's filter:
{
"language": "es",
"query": {
"knn": {
"field": "embedding_v",
"query_vector": [0.75, 0.15, 0.10],
"k": 10,
"filter": { "match": { "body_t": "warranty" } },
"exact": true
}
},
"limit": 10
}
{
"knn": {
"field": "embedding_v",
"query_vector": [0.75, 0.15, 0.10],
"k": 10,
"filter": { "match": { "body_t": "warranty" } },
"exact": true
},
"size": 10
}
The filter selects documents but does not score them, so the order is by vector similarity alone. The neighbors are chosen among every keyword match, not only the top few. exact: true (a WarpSearch extension) compares the query vector with every match, which is the right choice when the keyword query is selective. When it matches a large share of the collection, leave exact off and let the approximate index search within the filter (see Filter inside the search).
The opposite order, where vectors decide what is eligible and keywords refine the order, is a bool with the knn under must and the keyword query under should. Every result is one of the k nearest, and keyword matches among them score higher:
{
"language": "es",
"query": {
"bool": {
"must": [{ "knn": { "field": "embedding_v", "query_vector": [0.75, 0.15, 0.10], "k": 50 } }],
"should": [{ "match": { "title_t": "dune" } }]
}
}
}
#Recipes
| Goal | Setup |
|---|---|
| Sensible default | RRF with rank_constant 60, equal weights, rank_window_size 100. |
| Semantic-heavy (natural-language questions) | RRF with weights such as keyword 1, vector 2, or linear with 0.3 / 0.7. |
| Keyword-heavy (product search, codes, names) | RRF with weights such as keyword 2, vector 1, or linear with 0.7 / 0.3. |
| Restrict to a segment of data | Put the condition in filters (or the fusion filter) so every retriever obeys it. |
| Turn off vectors for exact-match lookups | Set the kNN retriever's weight to 0 from your own configuration. |
| Boost a field only on the keyword side | Keep boosts in the keyword retriever's query, not in weights. |
| Favor recent documents a little | Add a date-sorted standard source under RRF with a weight below 1 (Sources). |
| Keywords decide eligibility, meaning decides order | knn with the keyword query as its filter (Vector search within keyword matches). |
| Either signal alone is enough | dis_max over a knn and a match (The better of the two). |
Start with the defaults, collect a handful of queries with known good answers, and change one thing at a time.
#Measure recall
Approximate vector search can miss true neighbors. To see whether that affects your hybrid results, run the same request twice, with "exact": true on the knn in one of them. If the fused lists barely differ, approximate search is costing you nothing and the defaults are fine. If they differ a lot, raise ivf.nprobe or num_candidates (see Tune recall and latency), or rank_window_size if relevant documents fall just outside the fused window.
#Reranking
WarpSearch does not host models, so cross-encoder and other reranker models, including Elasticsearch's text_similarity_reranker retriever, are not available. Rerank in your application: retrieve the top 50 to 100 fused results, send them to your reranker, and keep the best few. Because fusion already blends keywords and meaning, the reranker only has to reorder a short list.
#Not supported
Not supported: the Elasticsearch
text_similarity_reranker,rescorer,pinned,ruleanddiversifyretrievers, nestedrrforlinearretrievers, the OpenSearchnormalization-processorand stored search pipelines, and OpenSearchneuralandneural_sparsequeries. They return400 unsupported_feature(see Query languages).
Coming soon: sparse vectors for learned sparse retrieval (for example SPLADE) and
rank_featuresfields, which suit learned token weights and static signals such as popularity. They are in development, with no release date. Once available, a sparse source can join the same fusion as the keyword and dense sources.
For the vector side, see Vector search and Multi-vector fields.