Constructs an AiSearchNamespaceBinding instance.
Optionalsettings: AiSearchNamespaceSettings
Resolved settings. Defaults to resolve('aiSearchNamespace'), so
callers normally construct this with no arguments at all.
The binding name this instance resolves.
The binding name as declared in wrangler.json.
Creates an instance in the namespace.
The Worker environment.
The instance configuration. Only id is required.
A handle to the new instance.
Provisioning from the request path is unusual, and it is here because the
namespace binding's reason to exist is the case where it is not: a corpus
created when a customer signs up cannot be declared in wrangler.json.
Passing only id creates one with built-in storage, to upload items into.
MissingBindingError When the namespace binding is absent.
Opens one instance within the namespace.
The Worker environment.
The instance name within the bound namespace.
The instance handle.
Synchronous and local — this names an instance rather than fetching it, so
an instance that does not exist fails on the first operation rather than
here. The returned handle is the platform's own AiSearchInstance, so
search, chatCompletions, items and jobs are all reachable on it
without this package standing in the way.
MissingBindingError When the namespace 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.
Lists the instances in the namespace.
The Worker environment.
Optionalparams: AiSearchListInstancesParams
Optional pagination, search, and ordering.
The instances and their pagination cursor.
MissingBindingError When the namespace binding is absent.
Deletes an instance from the namespace.
The Worker environment.
The instance name to delete.
MissingBindingError When the namespace binding is absent.
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.
Searches across several instances at once.
The Worker environment.
The multi-instance search request.
Merged chunks, tagged by instance, plus any partial failures.
A fan-out, and it reports partial failure rather than hiding it: chunks
come back tagged with the instance they came from, and an errors array
names the instances that did not answer. A caller that ignores errors is
reading a result set that silently lost a corpus.
ai_search_options.instance_ids is required, which is why nothing is
defaulted into this request — which instances to search is the question
being asked.
MissingBindingError When the namespace binding is absent.
Resolves the binding without throwing.
The Worker environment.
The resolved binding, or null when it is not configured.
Accessor for a namespace-scoped AI Search binding.
Remarks
The other half of AI Search, and a genuinely different binding rather than a convenience over AiSearchBinding:
ai_searchnames one instance at deploy time, whileai_search_namespacesopens a namespace and lets a request name the instance. That is what a per-tenant corpus needs, since the set of instances is not known when the Worker is deployed.Which one to bind follows from that. One corpus, fixed at deploy — the single-instance binding, and a Worker that cannot ask for the wrong one. A corpus per customer, created as customers arrive — this one.
Nothing stops a Worker binding both, and the default names here differ (
AI_SEARCHandAI_SEARCH_NAMESPACE) so that it can. Two bindings cannot share a name on oneenvregardless of what this package defaults to.Example
Author
Bayu Dwiyan Satria
Version
1.0.0
Since
1.3.0