Setting the file. One moment.
Chapter 04 · Cloudflare Deploy
Subchapter 4.15
references/ai-search/patterns.mdMarkdown2 KBView on GitHub
| Use | Method | Returns |
|---|---|---|
| Custom UI, analytics | search() | Raw chunks only (~100-300ms) |
| Chatbots, Q&A | aiSearch() | AI response + chunks (~500-2000ms) |
| Setting | Use When |
|---|---|
true | User input (typos, vague queries) |
false | LLM-generated queries (already optimized) |
const answer = await env.AI.autorag("saas-docs").aiSearch({
query: "refund policy",
model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
filters: {
column: "folder",
operator: "gte", // "starts with" pattern
value: `tenants/${tenantId}/`
}
});const stream = await env.AI.autorag("docs").aiSearch({
query, model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast", stream: true
});
return new Response(stream, { headers: { "Content-Type": "text/event-stream" } });| Threshold | Use |
|---|---|
| 0.3 (default) | Broad recall, exploratory |
| 0.5 | Balanced, production default |
| 0.7 | High precision, critical accuracy |
const systemPrompt = `You are a documentation assistant.
- Answer ONLY based on provided context
- If context doesn't contain answer, say "I don't have information"
- Include code examples from context`;// OR: Multiple folders
filters: {
operator: "or",
filters: [
{ column: "folder", operator: "gte", value: "docs/api/" },
{ column: "folder", operator: "gte", value: "docs/auth/" }
]
}
// AND: Folder + date
filters: {
operator: "and",
filters: [
{ column: "folder", operator: "gte", value: "docs/" },
{ column: "timestamp", operator: "gte", value: oneWeekAgoSeconds }
]
}Enable for high-stakes use cases (adds ~300ms latency):
reranking: { enabled: true, model: "@cf/baai/bge-reranker-base" }