Skip to content

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.

Install the package from npm:

Terminal window
pnpm add @emdash-cms/plugin-ai-search

Add aiSearch() to plugins in astro.config.mjs:

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:

wrangler.jsonc
{
"ai_search_namespaces": [{ "binding": "AI_SEARCH", "namespace": "default" }],
}
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 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:

src/layouts/Base.astro
---
import { AiSearch } from "@emdash-cms/plugin-ai-search/astro";
---
<AiSearch placeholder="Search content" />

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.