# mv.kb

> The kb methods of @morevoice/sdk: Knowledge-base documents assistants answer from.

Knowledge-base documents assistants answer from. These methods are on `mv.kb`, where `mv` is your client (see [the Node.js SDK](https://docs.morevoice.ai/sdk/node/#connect)). Each one returns the response object and throws when the API answers with an error.

## `documentsSearch()`

**Search the knowledge base.** 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.

```ts
mv.kb.documentsSearch(body: KbDocumentsSearchData["body"], options?: RequestOptions): Promise<KbDocumentsSearchResponse>
```

`POST /kb/search` · [API reference](https://docs.morevoice.ai/api/operations/kb_documents_search/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `body.query` | `string` | yes | What to look for, in any language the documents are in. |
| `body.copilot_profile_id` | `string` | no | Search as this copilot profile does: its documents only. |
| `body.document_ids` | `string[]` | no | Search only these documents. |
| `body.limit` | `integer` | no | Passages to return (1–20, default 5). |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options.headers["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. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`KbSearchResult`:

| Field | Type | Description |
| --- | --- | --- |
| `object` | `"kb_search_result"` | Always `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

```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);
```
