This site is not affiliated with or endorsed by Cloudflare, Inc. It simply showcases experiments built using Cloudflare services.
Cloudflare Experiments

AI Search Demo

Query Cloudflare AI Search (managed RAG) from a Worker

Query Cloudflare AI Search (managed RAG, formerly AutoRAG) from a Worker via the Workers AI binding using env.AI.autorag(name).aiSearch({ query }).

API Reference

Run a natural-language search against your AI Search instance.

q string (required)

Natural language query.

Example Request

curl "https://your-worker.workers.dev/search?q=What%20is%20Workers%20AI"

Success Response

{
  "answer": "Generated answer from AI Search",
  "results": [],
  "query": "What is Workers AI",
  "instance": "demo-index"
}

Error Codes

  • 400 - Missing or empty q (INVALID_QUERY)
  • 502 - AI Search / AutoRAG failure (SEARCH_ERROR)

Use Cases

  • Learn managed RAG via AI Search from a Worker
  • Prototype Q&A over indexed docs without building Vectorize yourself
  • Compare AutoRAG-style search with a custom RAG Mini Search experiment
  • Demo grounded answers with retrieval metadata

Limitations

  • Requires a configured AI Search instance and indexed data source
  • Uses the legacy AI.autorag(...).aiSearch API; newer projects may prefer dedicated ai_search bindings
  • Remote/account access is typically needed for real searches
  • No auth on the public /search endpoint

Deployment

Click the deploy button

Deploy to Cloudflare Workers

Create an AI Search instance in the dashboard, index your data, and set INSTANCE_NAME in wrangler.json vars (default: demo-index).

Test your deployment

curl "https://your-worker.workers.dev/search?q=hello"

Local Development

cd apps/experiments/ai-search-demo
npm install
npm run dev
curl "http://localhost:8787/search?q=hello"

AI Search typically requires a remote instance (wrangler may need remote AI / account access).

Configuration

wrangler.json declares:

  • Workers AI binding AI
  • Var INSTANCE_NAME (AI Search / AutoRAG instance name)

See AI Search Workers binding docs for the newer dedicated binding shape.

Cloudflare Features Used

On this page