---
name: relevan-setup
description: "Set up Relevan search from the start: authenticate, create an index, load documents, run the first search, and send the first feedback. Use when a user asks you to add Relevan search to a product."
---

# Relevan setup

Do these steps to set up Relevan search from the start: authenticate, create an index, load documents, search, and send the first feedback.

## 1. Authenticate

First check whether the `relevan` MCP server is connected, for example through the Relevan agent plugin. If it is, you need no API key for steps 2 to 7. Use its tools in place of the REST calls: `create_index`, `create_mapping`, `upsert_documents`, `describe_index`, `search`, and `send_search_feedback`. The create tools need the `write` scope, which only an organization owner can grant. Keep each `upsert_documents` call under 8 KB. For a larger load, use the REST bulk call in step 5 with an API key.

If the server is not connected, the user can connect it. In Claude Code, the user runs `claude plugin marketplace add relevan-dev/agent-plugins`, then `claude plugin install relevan@relevan`, then runs `/mcp` in a new session to sign in. Codex and GitHub Copilot CLI install the same plugin: https://github.com/relevan-dev/agent-plugins. Another MCP client adds `https://capy-learning-loop-demo.api.dev.relevan.dev/v1/mcp`. The steps for each client: https://capy-learning-loop-demo.docs.dev.relevan.dev/guides/mcp-server

The app code that you write still needs its own API key on its server. To get one, do these steps:

1. Ask the user for a write API key. The user creates the key in the console: https://capy-learning-loop-demo.console.dev.relevan.dev. A read key gets 403 on the calls that create an index or upload documents.
2. Keep the key in a server environment variable, such as `RELEVAN_API_KEY`. Do not put the key in browser code.
3. Send the key in the `x-api-key` header on each request.
4. Call `GET https://capy-learning-loop-demo.api.dev.relevan.dev/v1/organizations`. An org-scoped API key resolves to one organization. Use its `id` or `slug` as `{orgId}` in each route below.

## 2. Create an index

Call `POST https://capy-learning-loop-demo.api.dev.relevan.dev/v1/{orgId}/indexes` with a body such as `{ "name": "products" }`.

Right after you create the index, give the user the link to the index list page in the console: `https://capy-learning-loop-demo.console.dev.relevan.dev/{orgId}/indexes`. Give the link in your next message, before you deploy a mapping or upload documents. Do not wait and give the link only in a final summary. Tell the user to open the link to monitor the progress. The `consoleUrl` field of the response gives the full link.

## 3. Find the ranking signals

Follow this skill before you design the mapping: https://capy-learning-loop-demo.api.dev.relevan.dev/skills/relevan-ranking-signals/SKILL.md

## 4. Deploy the mapping

Follow this skill to draft and deploy the mapping: https://capy-learning-loop-demo.api.dev.relevan.dev/skills/relevan-mapping/SKILL.md

Relevan applies the mapping to the index after the `POST` returns. Wait until it is applied before you upload documents. A document that arrives first can give a new field the wrong type for the life of the index.

1. Keep the `id` of the `POST` response. Call `GET https://capy-learning-loop-demo.api.dev.relevan.dev/v1/{orgId}/indexes/{indexName}/mappings/{id}` every 10 seconds.
2. In the first 30 seconds, a `404` or a `null` `deployment` means that the revision is not visible yet. Keep polling. A `404` after 30 seconds means that the `id` is wrong. Stop, and check the `id`.
3. Read `deployment.status`. Upload documents only when it is `succeeded`.
4. If it is `failed`, do not upload. Give the user `deployment.failureReason`. To retry one time, `POST` the same mapping again. Keep `deployment.createdAt` of that response. A poll with an older `createdAt` shows the failed deployment, not the retry. Keep polling.
5. If it is `canceled`, a newer deployment replaced it. Do not upload, and tell the user.
6. If the status is not `succeeded` after 10 minutes, stop and tell the user. Do not upload.

## 5. Upload the documents

Before the first upload, follow the storage cap rule in `https://capy-learning-loop-demo.api.dev.relevan.dev/llms.txt`. It says how to read the storage that remains, estimate the size of the corpus, and warn the user. A 402 response with `code: "storage_limit_exceeded"` means that the request does not fit in the storage that remains. Do not retry it.

Call `POST https://capy-learning-loop-demo.api.dev.relevan.dev/v1/{orgId}/indexes/{indexName}/documents/_bulk` with a maximum of 1000 documents in each request:

```json
{ "documents": [{ "id": "sku-1", "content": { "title": "Trail Runner 2" } }] }
```

If one document does not agree with the mapping, Relevan rejects the full request and writes no documents. The response names each document with a problem.

## 6. Search

Call `GET https://capy-learning-loop-demo.api.dev.relevan.dev/v1/{orgId}/indexes/{indexName}/skill` once. It tells you how to search this index. Then call `POST https://capy-learning-loop-demo.api.dev.relevan.dev/v1/{orgId}/indexes/{indexName}/search` with a body such as `{ "query": "waterproof trail shoe" }`.

Keep `searchContext.queryId` from the response. The feedback call needs it. Read the `X-Search-Quota-Remaining` header, and plan your work so that you do not use all the searches.

## 7. Send the first feedback

Follow this skill to send feedback for each result that you act on: https://capy-learning-loop-demo.api.dev.relevan.dev/skills/relevan-feedback/SKILL.md

## Before you finish: the integration checklist

Before you tell the user that the integration is complete, show the user this checklist. Mark each item as done or not done. If an item is not done, tell the user why. Do not mark an item as done if the user chose to skip it.

- [ ] The mapping is deployed, and the documents are uploaded.
- [ ] You asked the user which facts make a result good, and the answers are in the mapping.
- [ ] Each ranking signal is a field on every document.
- [ ] A job or a write path keeps the ranking signals current.
- [ ] The UI receives the `queryId` from each search response.
- [ ] A click on a result sends a `click` event through a server route.
- [ ] Each closing event sends a `conversion` event, if the product has one.
- [ ] The UI shows filters for the filterable fields that users need.

## Other Relevan documents

- [Relevan overview](https://capy-learning-loop-demo.dev.relevan.dev/llms.txt): What Relevan is, who it suits, and what it costs.
- [Documentation index](https://capy-learning-loop-demo.docs.dev.relevan.dev/llms.txt): Each page of the Relevan documentation: guides, releases, and resources.
- [API index](https://capy-learning-loop-demo.api.dev.relevan.dev/llms.txt): The API capabilities, the rate limits, and the search quota.
- [OpenAPI spec](https://capy-learning-loop-demo.api.dev.relevan.dev/openapi): Each endpoint, with its request and response schemas.
- [relevan-ranking-signals](https://capy-learning-loop-demo.api.dev.relevan.dev/skills/relevan-ranking-signals/SKILL.md): Find the data that tells Relevan which result is the best one, such as prices, sales, or activity, and add it to each document. Use before you design a Relevan mapping.
- [relevan-mapping](https://capy-learning-loop-demo.api.dev.relevan.dev/skills/relevan-mapping/SKILL.md): Draft and deploy a RelevanMapping from a sample of documents. Use when a Relevan index has no mapping, or when the documents get new fields.
- [relevan-feedback](https://capy-learning-loop-demo.api.dev.relevan.dev/skills/relevan-feedback/SKILL.md): Send search_judgment, click, conversion, and llm_judgment feedback to Relevan after a search. Relevan trains the ranking of the index from it. Use when you build search into an app, or when an agent acts on a search result.
