# Docs search

If your site already has a search for its help articles, the agent can use it live: one public endpoint that searches, and articles it can read. Add it under **Knowledge → Docs and files → Add knowledge → Docs search**, as an admin. The agent searches it alongside your [docs and files](https://staging.preview.answerable.co/docs/knowledge/docs-and-files.md).

The endpoint must be `https` on a public address. answerable doesn't follow redirects: answer at the configured address.

## Request

```http
GET <search endpoint>?q=<words>&limit=8
Accept: application/json
User-Agent: answerable/1.0
```

- `q` is a few keywords the agent chose, such as `reset password`. Match it the way the site's own search does; keyword matching is fine.
- `limit` is the most results answerable will use (8). Returning fewer is fine.
- answerable adds `q` and `limit` to the configured address, keeping any query parameters already in it.
- The endpoint is public: it returns the same public articles the site's search does, so it needs no authentication.

## Response

`200` with JSON:

```json
{
  "results": [
    {
      "title": "Reset your password",
      "url": "https://example.com/help/reset-password",
      "excerpt": "Open Settings, choose Security, then Reset password…",
      "content_url": "https://example.com/help/reset-password.md"
    }
  ]
}
```

| Field | Required | Notes |
| --- | --- | --- |
| `title` | Yes | Plain text. HTML tags such as `<mark>` are stripped. |
| `url` | Yes | The article's public page, absolute or relative to the search endpoint. The agent cites it in replies. |
| `excerpt` | No | A sentence or two around the match. Up to 500 characters are kept. |
| `content_url` | No, but recommended | The article as **Markdown or plain text**. When present, the agent reads this instead of the HTML page. |

- Return `{ "results": [] }` when nothing matches, not an error.
- Results must be on the same site as the search endpoint: the same host, a host under it or above it, or a sibling under the same domain (`docs.example.com` for `api.example.com`). Others are dropped, so the agent can't be pointed elsewhere.
- Order results best first. answerable keeps the first 8.

## Reading an article

The agent reads an article by fetching its `content_url` (or its `url` if there's no `content_url`) with:

```http
GET <content_url or url>
Accept: text/markdown, text/plain;q=0.9, text/html;q=0.8
```

- **Markdown or plain text is best.** Start with the title as `# Title`. Keep the information the agent should weigh, such as which plans a feature is available on.
- **HTML works too.** answerable reads the `<main>` (or `<article>`) element, dropping navigation, headers, footers, and scripts.
- answerable keeps the first 12,000 characters of an article. Reply `404` for an article that doesn't exist.

## Checklist

- [ ] `GET <search endpoint>?q=…&limit=…` returns a list of results:\
  `{ results: [{ title, url, excerpt, content_url }] }`
- [ ] Results are only public articles, best match first
- [ ] Each article's `content_url` returns its Markdown
- [ ] No redirects, and an answer within a few seconds (answerable waits 8)
