Hybrid Search: Vector and Keyword Fusion, Indexing and Similarity Cache
How managed hybrid search combines vector and keyword retrieval, fusion, indexing, keyword tokenizers, and similarity caching—and what to avoid with AI Gateway.
This page summarizes Cloudflare AI Search documentation on how instances find and rank content: vector, keyword, and hybrid search; how results are fused; how indexing, chunking, and sync keep the index fresh; and how similarity cache differs from AI Gateway caching.
Search modes: vector, keyword, and hybrid
Section titled “Search modes: vector, keyword, and hybrid”AI Search supports three search modes. New instances use hybrid search by default.
AI Search supports three search modes: vector, keyword, and hybrid. New instances use hybrid search by default.
— Cloudflare, Search modes
Vector search embeds the query and returns chunks with similar meaning, even when wording differs. Keyword search matches chunks that contain query terms exactly via full-text search. Hybrid search runs both in parallel and merges them with a fusion method.
Keyword search matches chunks that contain your query terms exactly using full-text search. When you search “ERR_CONNECTION_REFUSED timeout,” keyword search finds documents that actually contain “ERR_CONNECTION_REFUSED” as a term. However, it may miss a page about “troubleshooting network connections” that describes the same problem.
— Cloudflare, Search modes
Hybrid search runs vector and keyword search in parallel and merges the results using a fusion method. Vector search understands intent, keyword search matches specific terms. Together, a query like “ERR_CONNECTION_REFUSED timeout” finds the exact error page and related troubleshooting content.
— Cloudflare, Search modes
| Mode | Best when | Trade-off |
|---|---|---|
| Vector | Paraphrases, concepts, “same idea, different words” | May miss rare exact tokens (error codes, SKUs) |
| Keyword | Exact terms, codes, identifiers | May miss synonym or intent matches |
| Hybrid (default) | Production Q&A over mixed content | More index work; tuning fusion and tokenizers matters |
To use vector-only or keyword-only retrieval, set index_method at create or update time, or override per request with ai_search_options.retrieval.retrieval_type (must match what the instance indexes). See Vector search and Keyword search.
Hybrid search: enable fusion and per-request retrieval
Section titled “Hybrid search: enable fusion and per-request retrieval”Hybrid search requires keyword indexing to be enabled. It is on by default for new instances.
New AI Search instances use hybrid search by default. Hybrid search combines semantic vector retrieval with full-text matching. You can choose a different index method when you create an instance.
— Cloudflare, AI Search is generally available
Hybrid search runs vector and keyword search in parallel and merges the results. It requires keyword search to be enabled.
— Cloudflare, Hybrid search
How do I enable hybrid search on a new instance?
Section titled “How do I enable hybrid search on a new instance?”Set both index_method.vector and index_method.keyword to true, and choose a fusion_method:
const instance = await env.AI_SEARCH.create({ id: "my-instance", index_method: { vector: true, keyword: true, }, fusion_method: "rrf",});Changing index_method triggers a full reindex. To drop hybrid behavior, set index_method.keyword to false; the keyword index is deleted. Details are in Hybrid search.
Fusion method: rrf vs max
Section titled “Fusion method: rrf vs max”The fusion_method field controls how vector and keyword result lists become one ranking.
| Value | Default | Behavior |
|---|---|---|
rrf |
Yes | Reciprocal Rank Fusion by rank position across both methods; recommended for most cases |
max |
No | Higher of normalized vector and keyword scores; use when one method is consistently better |
The fusion_method field controls how vector and keyword results are merged.
— Cloudflare, Hybrid search
Agent SDKs (Agents SDK, AI SDK, LangChain) expose the same idea: combine vector and keyword search with configurable fusion.
Per-request overrides for retrieval_type and fusion_method
Section titled “Per-request overrides for retrieval_type and fusion_method”Override retrieval on a single search call:
const results = await instance.search({ messages: [{ role: "user", content: "What is Cloudflare?" }], ai_search_options: { retrieval: { retrieval_type: "hybrid", fusion_method: "rrf", }, },});Requesting a retrieval_type incompatible with index_method returns an error. With hybrid search active, each chunk can expose scoring_details (vector_score, keyword_score, ranks, fusion_method, optional reranking_score). See Hybrid search — Scoring details.
Keyword search: tokenizer and match mode
Section titled “Keyword search: tokenizer and match mode”Keyword search is controlled at indexing time (index_method, keyword_tokenizer) and at retrieval time (keyword_match_mode).
Enable keyword search to match chunks that contain your query terms exactly.
— Cloudflare, Keyword search
At least one of vector or keyword must be true. The keyword field defaults to true. Changing index_method or keyword_tokenizer triggers a full reindex.
Keyword tokenizer: porter vs trigram
Section titled “Keyword tokenizer: porter vs trigram”| Tokenizer | Default | Use case |
|---|---|---|
porter |
Yes | Natural language; stemming (e.g. “running” ↔ “run”) |
trigram |
No | Code and overlapping substrings (“config” ↔ “configuration”) |
For Japanese, Chinese, or Korean content or queries, do not rely on porter.
The porter tokenizer does not work well for these languages. If your content is in Japanese, Chinese, or Korean, set keyword_tokenizer to trigram. Changing the tokenizer triggers a full reindex.
— Cloudflare, AI Search keyword search supports Japanese, Chinese, and Korean queries
With trigram, queries without spaces (e.g. full questions in CJK) can match via overlapping three-character windows. Words shorter than three characters cannot be matched alone. See Keyword search — Keyword tokenizer.
Keyword match mode: and vs or
Section titled “Keyword match mode: and vs or”| Mode | Default | Effect |
|---|---|---|
and |
Yes | All query terms must appear; higher precision |
or |
No | Any term can match; higher recall |
Override per request via ai_search_options.retrieval.keyword_match_mode as shown in Keyword search.
Retrieval: match_threshold and generation context
Section titled “Retrieval: match_threshold and generation context”match_threshold filters on vector similarity (0–1), not the fused score shown in the response.
The match_threshold sets the minimum vector similarity score that a chunk must meet to be included in the results.
— Cloudflare, Result controls
Flow for a typical query: embed the query → query the index (hybrid fuses lists if enabled) → drop chunks below match_threshold → cap at max_num_results → pass context to generation. If nothing passes the threshold, AI Search does not generate a response. With reranking enabled, a separate reranking.match_threshold may apply.
Higher threshold: stricter, fewer chunks. Lower threshold: more recall, possibly weaker precision. Balance max_num_results and chunk size so retrieved tokens fit the generation model context window.
Chunking and index size
Section titled “Chunking and index size”AI Search uses recursive chunking at natural boundaries, then splits further if chunks are too large.
Chunking is the process of splitting large data into embeddings for search. AI Search uses recursive chunking, which breaks your content at natural boundaries (like paragraphs or sentences), and then further splits it if the chunks are too large.
— Cloudflare, Chunking
You can set chunk size (tokens per chunk) and chunk overlap (0–30%). Smaller chunks mean more vectors and a larger index; overlap increases ingestion cost because shared text is counted in each chunk. Chunk settings apply at indexing time and are editable after creation per the configuration overview.
Indexing and sync: schedules, single-file reindex, inactivity
Section titled “Indexing and sync: schedules, single-file reindex, inactivity”External data sources sync on a schedule; built-in storage indexes uploads immediately without sync jobs.
By default, AI Search runs a sync job every 6 hours.
— Cloudflare, Syncing
Allowed sync_interval values include 15 minutes through 24 hours (API values in seconds; default 21600). You can trigger sync manually (as often as every 30 seconds), cancel jobs, pause or resume indexing, or reindex one file from Overview > Indexed Items (sync icon). See Syncing — Controls and the indexing improvements note.
If an instance has no search traffic for 31 days, scheduled syncs for external sources pause automatically; the index remains searchable but source changes are not picked up until traffic resumes or you resume indexing manually.
Similarity cache vs AI Gateway caching
Section titled “Similarity cache vs AI Gateway caching”Two different caches apply to different layers. Confusing them is a common source of stale or wrong search behavior.
AI Search similarity cache (for answers)
Section titled “AI Search similarity cache (for answers)”Similarity cache reuses generated responses for prompts that are close in wording, using MinHash and LSH—not only identical strings.
Similarity-based caching in AI Search lets you serve responses from Cloudflare’s cache for queries that are similar to previous requests, rather than creating new, unique responses for every request.
— Cloudflare, Similarity cache
Default cache duration is now 48 hours via instance cache_ttl (10 minutes to 6 days); previously a fixed 30-day behavior applied. Shorter TTL when content changes often; longer when stable. Example six-day TTL: "cache_ttl": 518400. Purge all cached responses without deleting indexed content via the purge cache API or the instance settings page.
Threshold presets (instance or per-request cache_threshold) range from super_strict_match to anything_goes; default is close_enough. Check cf-aig-cache-status: HIT or MISS. Cached answers clear when underlying document chunks change.
AI Gateway caching (do not use on the AI Search gateway)
Section titled “AI Gateway caching (do not use on the AI Search gateway)”Do not turn on AI Gateway caching for the gateway connected to your AI Search instance. This matters most for embedding requests. AI Search relies on fresh embeddings to build its vector index and to match each query against it, so serving cached embeddings can store or return incorrect vectors and quietly degrade the accuracy of your search results. To cache search results, use AI Search’s own Similarity cache instead.
— Cloudflare, AI Gateway
Similarly, avoid rate limiting on that gateway: limits apply to AI Search’s own model calls, including bulk embedding during indexing, and can interrupt indexing and querying. AI Gateway caching is aimed at identical provider requests (text/image), not semantic answer reuse for search.
Common mistakes
Section titled “Common mistakes”- Enabling AI Gateway cache or aggressive rate limits on the gateway tied to AI Search (stale embeddings, interrupted sync).
- Using
porterfor CJK content or queries (empty or poor keyword hits). - Expecting
match_thresholdto filter on fused or keyword scores (it filters vector similarity only). - Changing
keyword_tokenizerorindex_methodin production without planning for a full reindex. - Ignoring chunk size ×
max_num_resultsagainst the generation model context limit. - Relying on scheduled sync after 31 days of no search traffic while assuming the index still mirrors the source (sync may be paused).
Optional retrieval tuning (reranking, query rewriting, boost) is described under Configuration and agent SDK pages such as LangChain — Retrieval configuration.
How to check this on your site
Section titled “How to check this on your site”-
In the Cloudflare dashboard, open your AI Search instance and confirm Search modes match intent: hybrid default, or explicit vector/keyword flags under Configuration. For CJK corpora, verify
keyword_tokenizeristrigramper Keyword search. -
Run test queries that need exact terms and paraphrases; in hybrid mode, inspect
scoring_detailsper Hybrid search to see vector vs keyword contribution. -
On the AI Gateway used by the instance, confirm caching is off and rate limiting is not throttling embeddings, per AI Gateway.
-
After content updates, confirm indexing via Overview > Indexed Items or Syncing; use single-file reindex when only one document changed; purge similarity cache if answers may be stale per Similarity cache.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.