AiSearch
Cloudflare AI Search provides RAG (Retrieval-Augmented Generation) capabilities for building AI-powered search and chat applications.
Props
Name of the AI Search instance.
${app}-${stage}-${id} (max 32 characters)
source
R2Bucket | AiSearchR2Source | AiSearchWebCrawlerSource
required
Data source for indexing.Show AiSearchR2Source properties
bucket
string | R2Bucket
required
R2 bucket - can be bucket name string or R2Bucket resource.
jurisdiction
default | eu | fedramp
default:"default"
Jurisdiction for the R2 bucket.
Prefix for included items from the R2 bucket.
Path patterns to include (up to 10 patterns). Supports wildcards: * matches any characters except /, ** matches any characters including /.
Path patterns to exclude (up to 10 patterns). Supports wildcards: * matches any characters except /, ** matches any characters including /.
Show AiSearchWebCrawlerSource properties
Domain to crawl. Must be onboarded to your Cloudflare account.Example: "docs.example.com" or "https://docs.example.com" (protocol will be stripped)
Path patterns to include (up to 10 patterns).
Path patterns to exclude (up to 10 patterns).
aiSearchModel
AiSearch.Model
default:"@cf/meta/llama-3.3-70b-instruct-fp8-fast"
Text generation model for AI responses.
embeddingModel
AiSearch.EmbeddingModel
default:"@cf/baai/bge-m3"
Embedding model for vectorization.
Enable chunking of source documents.
Size of each chunk (minimum 64).
Overlap between chunks (0-30).
Maximum search results (1-50).
Minimum match score (0-1).
rerankingModel
AiSearch.RerankingModel
default:"@cf/baai/bge-reranker-base"
Reranking model.
Enable query rewriting for better retrieval.
Enable similarity caching.
Whether to index the source documents when the AI Search instance is created.
Whether to delete the AI Search instance when removed from Alchemy.
Whether to adopt the AI Search instance if it already exists.
Output
The unique ID of the AI Search instance.
The name of the AI Search instance.
Source bucket or domain name.
The name of the underlying Vectorize index.
Examples
Basic AI Search with R2
const bucket = await R2Bucket("docs", { dev: { remote: true } });
const aiSearch = await AiSearch("rag", {
source: bucket
});
const worker = await Worker("search", {
entrypoint: "./src/search.ts",
bindings: {
AI_SEARCH: aiSearch
}
});
AI Search with R2 Source Config
const aiSearch = await AiSearch("docs-search", {
source: {
type: "r2",
bucket: "my-docs-bucket",
includePaths: ["docs/**"],
excludePaths: ["**/*.png", "**/*.jpg"]
}
});
AI Search with Web Crawler
const aiSearch = await AiSearch("site-search", {
source: {
type: "web-crawler",
domain: "docs.example.com",
includePaths: ["/guides/**", "/api/**"],
excludePaths: ["/blog/**"]
}
});
Advanced AI Search Configuration
const aiSearch = await AiSearch("advanced-search", {
source: bucket,
aiSearchModel: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
embeddingModel: "@cf/baai/bge-m3",
chunk: true,
chunkSize: 512,
chunkOverlap: 20,
maxNumResults: 20,
scoreThreshold: 0.5,
reranking: true,
rewriteQuery: true,
cache: true
});