AI Search
AI Search is a first-party native plugin that indexes published content into a Cloudflare AI Search instance and serves search results to the site. It keeps the index current as content changes.
Installation
Section titled “Installation”Install the package from npm:
pnpm add @emdash-cms/plugin-ai-searchAdd aiSearch() to plugins in astro.config.mjs:
import { defineConfig } from "astro/config";import emdash from "emdash/astro";import { aiSearch } from "@emdash-cms/plugin-ai-search";
export default defineConfig({ integrations: [ emdash({ plugins: [aiSearch()], }), ],});Add the AI Search namespace binding:
{ "ai_search_namespaces": [{ "binding": "AI_SEARCH", "namespace": "default" }],}Options
Section titled “Options”| Option | Default | Description |
|---|---|---|
binding |
AI_SEARCH |
Name of the ai_search_namespaces binding in wrangler.jsonc. |
instance |
emdash |
AI Search instance the plugin creates and owns inside that namespace. |
Add search to the site
Section titled “Add search to the site”Add the AiSearch component to a layout. It renders a search button and opens the search modal, also with Cmd/Ctrl+K, so render it once per page:
---import { AiSearch } from "@emdash-cms/plugin-ai-search/astro";---
<AiSearch placeholder="Search content" />Build the index
Section titled “Build the index”After deploying, open AI Search in the admin. The setup wizard chooses the content to index, shows an example result address for each source, and builds the index when you select Build index. Search is live once the build starts, with results appearing as documents are indexed. Later content changes update the index automatically.