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

# Add a knowledge base with the API

> Create a knowledge base with its files in one call, wait until it is ready, attach it to an assistant, and keep it up to date — from your own code.

This guide gives an assistant a knowledge base entirely through the API: one call to create it with its files, a loop that waits until Verbeo has read them, and one call to attach it. It then shows how to keep it current. Every call takes your private API key as a Bearer token ([Authentication](https://docs.verbeo.ai/api-reference/authentication.md)).

## 1. Create the knowledge base with its files

Send its name and its files as a multipart form, each file under the field name `files`. One request takes up to 25 files, together up to 25 MB.

```javascript Node.js theme={null}
import { readFile } from "node:fs/promises";

const API = "https://api.verbeo.ai/v1";
const auth = { Authorization: `Bearer ${process.env.VERBEO_API_KEY}` };

const form = new FormData();
form.append("display_name", "Clinic FAQ");
for (const name of ["prices.pdf", "opening-hours.docx"]) {
  form.append("files", new Blob([await readFile(name)]), name);
}
const created = await fetch(`${API}/knowledge-base`, { method: "POST", headers: auth, body: form });
const { data: kb } = await created.json();
if (!created.ok) throw new Error(kb?.error?.message);
```

```python Python theme={null}
import os, requests

API = "https://api.verbeo.ai/v1"
auth = {"Authorization": f"Bearer {os.environ['VERBEO_API_KEY']}"}

created = requests.post(
    f"{API}/knowledge-base",
    headers=auth,
    data={"display_name": "Clinic FAQ"},
    files=[("files", open("prices.pdf", "rb")), ("files", open("opening-hours.docx", "rb"))],
)
created.raise_for_status()
kb = created.json()["data"]
```

The answer comes once the files are stored: `kb.files` lists them, each `processing`. If one is refused — a duplicate, a file over your plan's size — nothing is created, and `error.message` starts with that file's name ([errors](https://docs.verbeo.ai/api-reference/knowledge-bases/overview.md#errors)).

## 2. Wait until it is ready

Verbeo reads each file in the background. Read the knowledge base until `processing_count` is `0`; then `ready_count` files are searchable and `error_count` failed.

```javascript Node.js theme={null}
let status;
do {
  await new Promise((resolve) => setTimeout(resolve, 5000));
  status = (await (await fetch(`${API}/knowledge-base/${kb.id}`, { headers: auth })).json()).data;
} while (status.processing_count > 0);
```

```python Python theme={null}
import time

while True:
    time.sleep(5)
    status = requests.get(f"{API}/knowledge-base/{kb['id']}", headers=auth).json()["data"]
    if status["processing_count"] == 0:
        break
```

A failed file says why in its `error_code` and `error_message`: [list the files](https://docs.verbeo.ai/api-reference/knowledge-bases/list-files.md) to see them.

## 3. Check what a caller's question finds

Before a real call, [test a search](https://docs.verbeo.ai/api-reference/knowledge-bases/search.md) with a question your callers ask:

```bash theme={null}
curl -X POST "https://api.verbeo.ai/v1/knowledge-base/search" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "store_ids": ["KNOWLEDGE_BASE_ID"], "query": "How much is a deep cleaning?" }'
```

A passage with `"verdict": "sent"` is what the assistant would get.

## 4. Attach it to an assistant

Add the knowledge base's id to the assistant's `kbStoreIds`. A `PATCH` replaces the list, so send every knowledge base the assistant should search:

```bash theme={null}
curl -X PATCH "https://api.verbeo.ai/v1/assistant/ASSISTANT_ID" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "config": { "kbStoreIds": ["KNOWLEDGE_BASE_ID"], "kbTopK": 3 } }'
```

From its next call, the assistant searches it whenever a caller asks something your files may answer.

## Keep it up to date

| To | Call |
| - | - |
| Add files | [`POST /knowledge-base/{id}/files`](https://docs.verbeo.ai/api-reference/knowledge-bases/upload-files) with the files |
| Add a short text or an FAQ list | [`POST /knowledge-base/{id}/texts`](https://docs.verbeo.ai/api-reference/knowledge-bases/add-text) with JSON |
| Swap in a new version of a file | [`POST /knowledge-base/files/{fileId}/replace`](https://docs.verbeo.ai/api-reference/knowledge-bases/replace-file): assistants keep the old one until the new one is ready |
| Change a text or an FAQ list | [`PUT /knowledge-base/files/{fileId}/text`](https://docs.verbeo.ai/api-reference/knowledge-bases/edit-text) |
| Remove files | [`DELETE /knowledge-base/files/{fileId}`](https://docs.verbeo.ai/api-reference/knowledge-bases/delete-file), or [several at once](https://docs.verbeo.ai/api-reference/knowledge-bases/delete-files.md) |
| Say better when to search it | [`PUT /knowledge-base/{id}`](https://docs.verbeo.ai/api-reference/knowledge-bases/update) with your own `tool_description` |

> [!TIP]
>
> Name your files for what they hold (`prices-2027.pdf`, not `doc1.pdf`): each passage starts with its file's name, which helps a search find it. [Write a knowledge base that answers well](https://docs.verbeo.ai/guides/knowledge-base-writing.md) has more.


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