# Search the knowledge base

`POST https://api.morevoice.ai/v1/kb/search`

The passages that best answer `query`, ranked like assistants and the copilot rank them (hybrid: words and meaning). Test keys search by words only, without an embedding call.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `kb_documents_search`.

## Parameters

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Required, `application/json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `query` | `string` | yes | What to look for, in any language the documents are in. |
| `copilot_profile_id` | `string` | no | Search as this copilot profile does: its documents only. |
| `document_ids` | `string[]` | no | Search only these documents. |
| `limit` | `integer` | no | Passages to return (1–20, default 5). |

Example:

```json
{
  "limit": 3,
  "query": "When are you open on Friday?"
}
```

## Responses

### 200 OK

OK Returns `KbSearchResult`.

| Field | Type | Description |
| --- | --- | --- |
| `object` | `"kb_search_result"` | — |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `query` | `string` | — |
| `data` | `object[]` | — |
| `semantic` | `boolean` | Meaning-based retrieval took part. Test keys search by words only (no embedding call). |

Example:

```json
{
  "data": [
    {
      "document_id": "kbd_6Nq0Sv3Xa5Cf8Hk1Mp4Rt7",
      "document_title": "Opening hours",
      "heading": "Opening hours",
      "match": "hybrid",
      "object": "kb_search_hit",
      "score": 0.82,
      "snippet": "… Friday 08:00–13:00.",
      "text": "Sunday–Thursday 08:00–18:00, Friday 08:00–13:00."
    }
  ],
  "livemode": true,
  "object": "kb_search_result",
  "query": "When are you open on Friday?",
  "semantic": true
}
```

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const kbSearchResult = await mv.kb.documentsSearch({
	limit: 3,
	query: "When are you open on Friday?",
});
console.log(kbSearchResult);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

kb_search_result = client.kb.documents_search({
    "limit": 3,
    "query": "When are you open on Friday?",
})
print(kb_search_result)
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/kb/search \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "limit": 3,
  "query": "When are you open on Friday?"
}'
```
