Constructs an AiSearchBinding instance.
Optionalsettings: AiSearchSettings
Resolved settings. Defaults to resolve('aiSearch'), so callers
normally construct this with no arguments at all.
The binding name this instance resolves.
The binding name as declared in wrangler.json.
Answers a conversation, grounded in the indexed corpus.
The Worker environment.
The chat request.
The generated answer, plus the chunks it was grounded in.
Retrieval and generation in one call. The response carries the chunks the
answer was drawn from alongside the answer itself, which is what makes a
citation possible — return them, or a reader has no way to check the model.
MissingBindingError When the AI Search binding is absent.
Answers a conversation as a stream of server-sent events.
The Worker environment.
The chat request.
The event stream, ready to return as a response body.
Separate from chat rather than a stream: true flag on it, because
the two return different things — a parsed response and a ReadableStream
— and a boolean argument that changes a return type is a discriminated
union pretending to be an option.
MissingBindingError When the AI Search binding is absent.
Reads the instance's metadata.
The Worker environment.
What this instance is and how it is configured.
MissingBindingError When the AI Search binding is absent.
Checks whether the binding is available on the given environment.
Use this to degrade gracefully when a binding is optional.
The Worker environment.
true when the binding is present.
Resolves the binding, failing fast when it is not configured.
The Worker environment.
The resolved binding.
MissingBindingError When the binding is absent from the environment.
Retrieves the chunks matching a query.
The Worker environment.
The search request, as a query or a conversation.
The matching chunks, each with its score and source item.
Retrieval only — this returns passages and their scores, and generates no prose. Use it when the Worker does its own reasoning over the results, and chat when it wants an answer written.
The request takes either a query string or a messages conversation,
never both; the platform's own types enforce that.
MissingBindingError When the AI Search binding is absent.
Reads the instance's indexing statistics.
The Worker environment.
Counts per status, last activity, and engine details.
Item counts by status and the last activity time — the answer to "is the corpus behind?", which is the question a search over stale content raises and a search response cannot answer.
MissingBindingError When the AI Search binding is absent.
Resolves the binding without throwing.
The Worker environment.
The resolved binding, or null when it is not configured.
PrivatewithApplies the configured retrieval options to a request that names none.
The request shape, either a search or a chat request.
The caller-supplied request.
The request with configured options filled in.
All or nothing, for the reason AiSearchSettings.options gives: a
request naming ai_search_options owns the whole object, because merging
four nested sub-objects field by field would give a call site an effective
configuration it could not predict from reading itself.
Accessor for a single-instance AI Search binding.
Remarks
AI Search is managed retrieval: Cloudflare indexes a source, and a request asks it a question in words rather than in vectors. That is the difference from VectorizeBinding, which this package has had since 1.0.0 — with Vectorize a Worker owns the embedding model, the chunking, and the index lifecycle; here it owns none of them. Both are worth having, and which one is right turns on whether the embedding pipeline is something you want to run.
Not
env.AI.autorag()The older path to the same product hung off the Workers AI binding, as
env.AI.autorag(id)andenv.AI.aiSearch(). Both are deprecated in the@cloudflare/workers-typesversion this package pins, in favour of the standalone bindings this class and AiSearchNamespaceBinding wrap. So although AIBinding already exists, routing AI Search through it would have adopted a deprecated surface on the day it was written.Why there is no
AiSearchServiceThe kernel names no retrieval capability, and the same reasoning applies as for WorkflowBinding: an interface with one implementation and no consumers is ceremony. Managed retrieval is a plausible candidate later — "ask a corpus a question" is not Cloudflare vocabulary — but the seam should be drawn by a second implementation, not guessed at ahead of one.
Example
Author
Bayu Dwiyan Satria
Version
1.0.0
Since
1.3.0