> ## Documentation Index
> Fetch the complete documentation index at: https://docs.personal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Knowledge

> Teach an assistant a piece of text

## Overview

Saves a piece of text to a knowledge collection so the assistant can recall it. Pass `document_id` to add to an existing document instead of creating a new one.

> [!NOTE]
>
> Changes data, so it needs a key that isn't read-only.

Operation name: `knowledge.add`.

## Authorization

**x-api-key** `string` *required*

Your Composer API key

## Headers

**Content-Type** `string` *required*

Must be set to application/json

## Body

**content** `string` *required*

The text to save.

```json Example theme={null}
"content": "We close at 3pm on public holidays."
```

**agent** `string`

The assistant this knowledge is for.

```json Example theme={null}
"agent": "my-assistant"
```

**collection** `string`

The collection to add to. Default `semantic`.

**title** `string`

A title, when creating a new document.

```json Example theme={null}
"title": "Holiday hours"
```

**document\_id** `string`

Add to this existing document instead of creating one.

**metadata** `object`

Extra details returned with the text when it is recalled, such as its source.

```json Example Request theme={null}
{
  "content": "We close at 3pm on public holidays.",
  "agent": "my-assistant",
  "title": "Holiday hours"
}
```

***

## Response

**document\_id** `string`

The document the text was saved to.

**chunk\_id** `string`

The id of the saved piece.

```json Example Success Response theme={null}
{
  "document_id": "c41d2e7a-6b5f-4a3e-8d9c-0b1a2f3e4d5c",
  "chunk_id": "7e6d5c4b-3a2f-4e1d-9c8b-a7f6e5d4c3b2"
}
```

***

## Example cURL

```bash cURL theme={null}
curl --request POST 'https://composer.personal.ai/lab/api/v1/op/knowledge.add' \
--header 'Content-Type: application/json' \
--header 'x-api-key: <your-api-key>' \
--data '{"content": "We close at 3pm on public holidays.", "agent": "my-assistant", "title": "Holiday hours"}'
```

***

## Error Codes

| Code | Description |
| - | - |
| 400 | The body doesn't match the fields above, or the operation failed. The response body says why. |
| 401 | Missing or invalid API key |
| 403 | This key isn't allowed to call this operation (for example, a read-only key) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.