Skip to content

QuerySearchNamespace

Source: src/Cloudflare/AI/QuerySearchNamespace.ts

Bind a {@link SearchNamespace} to a Worker and obtain the Effect-native namespace client whose .get(name) selects an instance at runtime. The ai_search_namespace binding resolves to a runtime SearchNamespace whose .get(name) selects an instance within the namespace at runtime.

QuerySearchNamespace is a single identifier that is simultaneously the binding’s Context tag, its type, and the callable — yield* Cloudflare.AI.QuerySearchNamespace(namespace).

Provide {@link QuerySearchNamespaceBinding} in the Worker’s runtime layer.

const ns = yield* Cloudflare.AI.QuerySearchNamespace(namespace);
return {
fetch: Effect.gen(function* () {
const answer = yield* ns.get("docs-search").chatCompletions({
messages: [{ role: "user", content: query }],
});
return yield* HttpServerResponse.json(answer);
}),
};