AI Search instances now include built-in storage and namespace Workers Bindings
New AI Search instances created after today will work differently. New instances come with built-in storage and a vector index, so you can upload a file, have it indexed immediately, and search it right away.
Additionally new Workers Bindings are now available to use with AI Search. The new namespace binding lets you create and manage instances at runtime, and cross-instance search API lets you query across multiple instances in one call.
All new instances now comes with built-in storage which allows you to upload files directly to it using the Items API or the dashboard. No R2 buckets to set up, no external data sources to connect first.
const instance = env.AI_SEARCH.get("my-instance");
// upload and wait for indexing to completeconst item = await instance.items.uploadAndPoll("faq.md", content);
// search immediately after indexingconst results = await instance.search({ messages: [{ role: "user", content: "onboarding guide" }],});The new ai_search_namespaces binding replaces the previous env.AI.autorag() API provided through the AI binding. It gives your Worker access to all instances within a namespace and lets you create, update, and delete instances at runtime without redeploying.
// wrangler.jsonc{ "ai_search_namespaces": [ { "binding": "AI_SEARCH", "namespace": "default", }, ],}// create an instance at runtimeconst instance = await env.AI_SEARCH.create({ id: "my-instance",});For migration details, refer to Workers binding migration. For more on namespaces, refer to Namespaces.
Within the new AI Search binding, you now have access to a Search and Chat API on the namespace level. Pass an array of instance IDs and get one ranked list of results back.
const results = await env.AI_SEARCH.search({ messages: [{ role: "user", content: "What is Cloudflare?" }], ai_search_options: { instance_ids: ["product-docs", "customer-abc123"], },});Refer to Namespace-level search for details.