Skip to content

Hybrid search

Hybrid search runs vector and keyword search in parallel and merges the results. It requires keyword search to be enabled. For an overview of search modes, refer to Search modes.

Set both index_method.vector and index_method.keyword to true:

TypeScript
const instance = await env.AI_SEARCH.create({
id: "my-instance",
index_method: {
vector: true,
keyword: true,
},
fusion_method: "rrf",
});

To disable hybrid search, set index_method.keyword to false. The keyword index is deleted.

For each search method, you can configure the following to adjust retrieval behavior:

Fusion method

The fusion_method field controls how vector and keyword results are merged.

ValueDefaultDescription
rrfYesReciprocal Rank Fusion. Scores results based on rank position across both search methods. Recommended for most use cases.
maxNoTakes the higher of the normalized vector and keyword scores. Use when one search method is consistently more relevant.

Reranking

After fusion, you can optionally apply reranking to further reorder results by semantic relevance. Reranking uses a cross-encoder model that evaluates the query and each chunk together, which can improve precision beyond what fusion alone provides.

Reranking is disabled by default. Refer to Reranking to enable and configure it.

Per-request overrides

Override search settings on individual requests using ai_search_options.retrieval.

FieldTypeDescription
retrieval_type"vector", "keyword", or "hybrid"Force a specific search mode. Must be compatible with index_method.
fusion_method"rrf" or "max"Override the fusion method.
TypeScript
const instance = env.AI_SEARCH.get("my-instance");
const results = await instance.search({
messages: [{ role: "user", content: "What is Cloudflare?" }],
ai_search_options: {
retrieval: {
retrieval_type: "hybrid",
fusion_method: "rrf",
},
},
});

Scoring details

When hybrid search is active, each chunk includes a scoring_details object:

FieldTypeDescription
vector_scorenumberVector similarity score (0 to 1).
keyword_scorenumberRaw BM25 keyword score.
vector_ranknumberRank position in the vector result set.
keyword_ranknumberRank position in the keyword result set.
fusion_methodstringFusion method used (rrf or max).
reranking_scorenumberScore from the reranking model, if enabled.

Limits

Instances with keyword search enabled support up to 500,000 files per instance on the Workers Paid tier, compared to 1,000,000 for vector-only instances. Refer to Limits and pricing for the full list of limits.