> ## Documentation Index
>
> Fetch the complete documentation index at: https://www.cosmicjs.com/llms.txt
> Use this file to discover all available pages before exploring further.
>
> For a question these docs do not answer, such as which plan fits a team, read https://www.cosmicjs.com/agent.txt and ask Cosmic's concierge.
>
> Machine-readable API spec: https://www.cosmicjs.com/openapi.json

# Content RAG (Semantic Search)

Search your bucket content by meaning instead of exact keywords. Content RAG embeds your objects into a vector index so a natural-language query returns the most semantically relevant objects, even when the wording differs.

Content RAG is in **Beta**. New projects and workspaces have it on by default. For existing ones, an admin or manager can turn it on under **Settings → Semantic search** (project or workspace settings); existing content is indexed automatically in the background. Keyword search via [Queries](/docs/api/queries) is always available.

The same retrieval powers [Agents](/docs/dashboard/ai/agents): when enabled, content and team agents can find objects by meaning with the `search_content` tool instead of scanning titles.

### Base URL
```
https://workers.cosmicjs.com

```
---

## Semantic Search (`POST` `/v3/buckets/:bucket_slug/ai/search`)

Embed a query and return the objects whose content is closest in meaning, ranked by similarity score. This is retrieval only (no answer generation) and requires a bucket write key.

### Required parameters

- **`query`** (`string`): The natural-language search query. Results are ranked by semantic similarity to this text.

### Optional parameters

- **`type`** (`string`): Restrict results to a single object type slug (e.g. `blog-posts`).

- **`locale`** (`string`): Restrict results to a single locale.

- **`status`** (`string`): Filter by object status (e.g. `published`, `draft`).

- **`limit`** (`number`): Maximum number of results to return. Default `10`, maximum `50`.

- **`min_score`** (`number`): Minimum similarity score (0-1). Results below this threshold are dropped. Default `0`.
```bash
curl -X POST \
  https://workers.cosmicjs.com/v3/buckets/BUCKET_SLUG/ai/search \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer BUCKET_WRITE_KEY' \
  -d '{
    "query": "how do refunds work on annual plans",
    "type": "policies",
    "limit": 10,
    "min_score": 0.6
  }'

```
```js
const res = await fetch(
  'https://workers.cosmicjs.com/v3/buckets/BUCKET_SLUG/ai/search',
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Bearer BUCKET_WRITE_KEY',
    },
    body: JSON.stringify({
      query: 'how do refunds work on annual plans',
      type: 'policies',
      limit: 10,
      min_score: 0.6,
    }),
  }
)

const { results } = await res.json()
console.log(results)
```

```json
{
  "results": [
    {
      "object_id": "66f1a2...",
      "slug": "refund-policy",
      "type": "policies",
      "locale": "en",
      "status": "published",
      "score": 0.83,
      "snippet": "Annual plans can be refunded within 30 days of purchase..."
    },
    {
      "object_id": "66f1b7...",
      "slug": "billing-faq",
      "type": "faqs",
      "locale": "en",
      "status": "published",
      "score": 0.74,
      "snippet": "After the refund window, plans are non-refundable but..."
    }
  ]
}

```
---

## How it works

- **Embeddings on write.** When Content RAG is enabled for your account, Cosmic embeds each object's searchable text (title, slug, content, and text-like Metafields) into a vector index and keeps it in sync as you create, edit, publish, unpublish, and delete content. Embedding your content is free; it does not consume AI tokens.
- **Search at query time.** Each `ai/search` call embeds your query and runs a vector search scoped to your bucket. Query-time usage is metered through the standard [AI token](/docs/api/ai) system.
- **Semantic vs. keyword.** Use `ai/search` to match on meaning. Use [Queries](/docs/api/queries) for exact, structured filtering (by metadata values, dates, and ranges). They are complementary: reach for structured queries when you know the exact field/value, and semantic search when you're matching intent.

## Semantic search vs. dashboard search

The [dashboard search](/docs/dashboard/search) (⌘K) is fast title/type navigation inside the dashboard UI. Content RAG semantic search is an API that ranks your content by meaning for use in your apps, support bots, and agents.

## FAQ

### How much does Cosmic cost?

Project plans are Free ($0), Builder ($99/mo), Team ($299/mo), Business ($499/mo), Enterprise (custom pricing). Yearly billing saves 10%. Workspace plans are Small Workspace ($999/mo) and Large Workspace ($2,999/mo), and they start with a 30-day free trial. Allowances, add-on rates, and the rest of the pricing FAQ are plain text at https://www.cosmicjs.com/pricing.md.

### Are API keys required, and is content private?

Each Bucket has a read key and a write key in Bucket Settings > API Access. GET requests use the read key. POST, PATCH, and DELETE use the write key as Authorization: Bearer. Do not put the write key in a browser bundle, a mobile app, or a NEXT_PUBLIC_ variable. SAML single sign-on is on Large Workspace and Enterprise. The audit log is append-only. Text versions: https://www.cosmicjs.com/security.md and https://www.cosmicjs.com/docs/dashboard/audit-log.md.

### Can an agent create a Cosmic project without an existing account?

Yes. POST https://dapi.cosmicjs.com/v3/agents/sign-up provisions a free-tier project and bucket tied to a human email, with no existing Cosmic account. The human claims it with the emailed one-time code. The playbook is https://www.cosmicjs.com/docs/ai-onboarding.md.
