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
GET /search
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 emptyq(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(...).aiSearchAPI; newer projects may prefer dedicatedai_searchbindings - Remote/account access is typically needed for real searches
- No auth on the public
/searchendpoint
Deployment
Configure AI Search
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 devcurl "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
- Workers - Edge compute runtime
- Workers AI - Binding used to call AI Search
- AI Search - Managed RAG over your indexed data