Skip to content

QuerySearch

Source: src/Cloudflare/AI/QuerySearch.ts

Bind a {@link SearchInstance} to a Worker and obtain the Effect-native AI Search client (search, chatCompletions, info, stats). The single-instance ai_search binding resolves directly to a runtime SearchInstance.

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

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

Bind the instance during the Worker’s init phase, then use search (retrieval only) or chatCompletions (retrieval + generation) from request handlers.

const search = yield* Cloudflare.AI.QuerySearch(instance);
return {
fetch: Effect.gen(function* () {
const answer = yield* search.chatCompletions({
messages: [{ role: "user", content: "How do I deploy?" }],
});
return yield* HttpServerResponse.json(answer);
}),
};