Skip to content

Keyword search

Enable keyword search to match chunks that contain your query terms exactly. For an overview of search modes, refer to Search modes.

Set index_method.keyword to true when creating or updating an instance. You can use keyword search on its own or alongside vector search for hybrid search.

FieldTypeDefaultDescription
vectorbooleantrueEnable vector (semantic) search.
keywordbooleanfalseEnable keyword (BM25) search.

At least one of vector or keyword must be true. Changing index_method triggers a full reindex of your content.

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

Keyword tokenizer

The keyword_tokenizer field (inside indexing_options) controls how text is split into tokens. Changing this triggers a full reindex.

ValueDefaultDescription
porterYesApplies Porter stemming. "running" matches "run." Best for natural language.
trigramNoOverlapping 3-character windows. "config" matches "configuration." Best for code.

Keyword match mode

The keyword_match_mode field (inside retrieval_options) controls how multiple query terms are combined.

ValueDefaultDescription
andYesAll query terms must appear. Higher precision, fewer results.
orNoAny query term can match. Higher recall, more results.

You can override keyword_match_mode per request:

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: {
keyword_match_mode: "or",
},
},
});

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.