Skip to content

Search by meaning (RAG)

plugins: [semantic({ collections: ["posts", "pages"] })] + the Workers AI binding. Published content is split into chunks (per language), turned into vectors with @cf/google/embeddinggemma-2 and indexed on publish, unpublish or delete.

  • Site: Astro.locals.cms.semanticSearch("fabrics for a wedding dress", { collections, locale, limit }) or GET /api/cms/semantic?q=…. Returns title, chunk and URL, read with the searcher's access.
  • Panel: a "By meaning" button next to the list search.
  • MCP: the search_content tool.
  • Ask the content: POST /api/cms/semantic/ask { question } → { answer, sources } with [n] citations (needs ai()). Staff use their AI cap; visitors only with ask: { public: true }, with dailyLimitPerVisitor (20) per IP per day.
  • Where the vectors live: by default in D1 (compares up to 5000 chunks in memory: small sites). For more, a Vectorize index: wrangler vectorize create <site>-vectors --dimensions=768 --metric=cosine and in wrangler.jsonc "vectorize": [{ "binding": "CMS_VECTORS", "index_name": "<site>-vectors" }]. Vectorize does not run locally.
  • Reindex (when turning the plugin on for a site with content, or after changing fields): POST /api/cms/semantic/reindex as an admin.
  • Migration 0008.