# Search the documents of this site

`/.well-known/search` finds passages in the documents this site serves to agents and answers them as Markdown. It retrieves text: no model is called and nothing is generated, so every line of an answer is a line of a document you can fetch. It needs no account and reads none.

Each site searches its own documents: the buyer site its index, guides and content pages, the supply site the device owners' index and guides. The documents of a site are the ones its `/docs-manifest.json` lists.

## Ask

With GET, the text goes in `q`:

```sh
BASE=${BASE:-https://coronium.ai}
curl -sS --get "$BASE/.well-known/search" --data-urlencode "q=how is a payout requested"
```

With the HTTP QUERY method, the text is the body: plain text, JSON with the one key `q`, or a form with the one field `q` (plain words under the form type, as curl sends `--data` with no header, are taken as the text). QUERY is safe and can be repeated, like GET, and it keeps the text out of the address.

```sh
BASE=${BASE:-https://coronium.ai}
curl -sS -X QUERY -H 'Content-Type: text/plain' --data 'device withheld class_not_sold' "$BASE/.well-known/search"
curl -sS -X QUERY -H 'Content-Type: application/json' --data '{"q":"device withheld class_not_sold"}' "$BASE/.well-known/search"
```

On the supply site set `BASE=https://supply.coronium.ai`. Send `Accept: text/markdown`, or no `Accept` header.

## The answer

The answer is `text/markdown`. Its first line names the query, with a backslash before each character Markdown would read as markup, and each hit is a second-level heading with the address of its document on this site and its score, then the passage:

```text
# Search results for: "<the query>"

## <the address of the document> (score: 1.000)

**<the title> > <a heading> > <a step>**

<the passage>
```

- The address is the document's own: fetch it for the whole text.
- The bold line is the passage's place in its document: the title, the headings above it and, in a guide, its step.
- A long passage is cut at the end of a line, and its last line then reads `The passage goes on in <address>.`
- A query that matches nothing answers the first line and the sentence `No passage of this site matches.`, with status 200.
- The answer carries `Accept-Query`, the media types a QUERY body may have, and an `ETag`; the same query is the same answer until the site is released again.

## How a passage is ranked

Each document is cut at its headings, and under a heading at each numbered step, so a passage is one heading or one step with the text under it. A word is a run of letters, digits and underscores, in lower case; a word with underscores, such as a refusal code, also counts as each of its parts. Passages are ranked by BM25 over those words, with the words of a passage's headings weighted above its text. The score shown is the passage's rank score divided by the best one, so the first hit reads `1.000`. There is no stemming and no list of synonyms: search for the words a document would use, and for a code or a log line, the exact words.

## Bounds

<!-- facts:begin search.limits -->
- A search query is at most 400 bytes.
- A search answers at most 5 passages.
- One address may send 60 search requests a minute.
<!-- facts:end search.limits -->

## Refusals

A refusal is JSON with `code`, `cause` and `fix`.

| Status | Code | When |
|---|---|---|
| 400 | `invalid` | no `q`, another parameter, a body that is not what its `Content-Type` says, JSON with another key, or a form with another field |
| 400 | `content_type_required` | a QUERY with no `Content-Type` |
| 406 | `not_acceptable` | an `Accept` header that takes neither Markdown nor any text |
| 413 | `body_too_large` | a body over the size the address takes |
| 403 | `wrong_origin` | a request that names another site as its `Origin`: a page of another site cannot search this one from a browser |
| 405 | `method_not_allowed` | a method other than GET and QUERY, `OPTIONS` among them |
| 415 | `unsupported_media_type` | a QUERY body that is not `text/plain`, `application/json` or `application/x-www-form-urlencoded` |
| 422 | `unprocessable_query` | a query that is empty, too long, or holds no letter or digit |
| 429 | `rate_limited` | too many searches from one address; `retryAt` and `Retry-After` say when to send again |

## How a page names it

Every HTML page of this site but its not-found page names the search in four `meta` tags of its head, `agent:instructions`, `agent:endpoint`, `agent:method` and `agent:documentation`, and the Markdown form of a page carries the same four values in an `agent` block of its front matter. The address they give is the GET form, with `{query}` where the text goes.

Whether an outside search engine may index this site is the content signal of `/robots.txt`, which names no rule for this address. This search is the site's own and does not depend on it.
