> For the complete documentation index, see [llms.txt](https://docs.ojin.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ojin.ai/apps/overview/knowledge.md). Agents can also search and read this documentation through its [MCP server](https://docs.ojin.ai/~gitbook/mcp).

# Knowledge

Give your Human Agent your organization's documents to answer from, in its prompt or by searching them during a conversation.

Knowledge is the text and documents your agents answer from: product guides, policies, price lists, FAQs. It belongs to your organization, is grouped into **collections**, and each agent uses only the collections you tick for it.

{% hint style="warning" %}
**Knowledge works only for Ojin Agents.** A Third-Party Agent (ElevenLabs Agents, OpenAI Realtime) runs its own conversation and never receives your organization's knowledge.
{% endhint %}

## Adding knowledge

Open **Knowledge** in the [Ojin dashboard](https://ojin.ai/dashboard) sidebar and choose **Add knowledge**. You can:

* **Upload files**: `.txt`, `.md`, `.pdf`, `.docx` (Word) or `.pptx` (PowerPoint), several at once.
* **Paste text**: give it a title and paste the text.

Every item goes into a collection. Pick an existing one, or name a new one in the same dialog.

An item can't be edited. To change one, delete it and add the new version.

### Status

Each item shows its status on the Knowledge page:

* **Processing…**: Ojin is extracting the text of a document, or making an item searchable.
* **Ready**: agents can use the item the way its collection says.
* **Failed**: the item can't be used, with the reason. Some failures offer **Retry**. Others mean the file needs fixing, such as "This file can't be read" for a password-protected or damaged file.

**Try a search** on the Knowledge page shows what a search finds in your organization's knowledge.

## Collections

Every item belongs to exactly one collection, and each collection is one of two kinds:

* **Search only** (the default for a new collection): the agent searches the collection during a conversation and gets the passages that best match.
* **Always in the prompt**: the full text of the collection's items goes into the agent's prompt at the start of every session.

Use **Always in the prompt** for short material the agent needs in nearly every conversation, such as opening hours or key policies. Use **Search only** for everything else, especially long documents.

* Collection names are unique within your organization, ignoring case.
* Switching a collection between the two kinds applies from each agent's next session.
* Moving an item into a **Search only** collection makes it **Processing…** until it can be searched there. An item moved into an **Always in the prompt** collection keeps its status.
* Deleting a collection deletes every item in it, and removes it from every agent that uses it.

## Using knowledge in an agent

In an Ojin Agent's settings, on the **Basics** tab under **Conversation**, tick the collections the agent uses under **Knowledge**. An agent with nothing ticked uses no knowledge. An agent can use up to 45 collections. Changes apply from the agent's next session.

Under the checklist, the dashboard estimates how much the ticked **Always in the prompt** collections add to the agent's prompt ("Adds ≈N tokens…").

### How the agent uses it

* **Always in the prompt:** the ready items of the agent's ticked **Always in the prompt** collections are added after your system prompt, under a "Reference material" heading, and are sent to the LLM with every reply.
* **Search only:** when a ticked **Search only** collection has a ready item, the agent gets a built-in `search_knowledge` tool. It searches only the collections ticked for it, of both kinds, and gets 5 passages per search, each with its item's title and, for PDF and Word files, its page.
  * The agent may search up to 3 times per caller turn, and searches count toward the [3 tool calls per model response](https://docs.ojin.ai/apps/overview/tools.md).
  * `search_knowledge` is reserved: a custom tool of that name is replaced by the built-in search while the agent has searchable knowledge.
  * The agent is asked to say a short line before it searches, such as that it's looking it up. On the default model it doesn't, in our measurements, so callers hear a short pause before the answer.
  * When nothing matches, or a search fails, the agent hears that nothing in your knowledge matched.

Text you add to an **Always in the prompt** collection is ready for the agent's prompt at once, but searches find it only after Ojin has indexed it, usually within minutes. Nothing on the Knowledge page shows that step. Material you want found by search belongs in a **Search only** collection, where **Ready** means searchable.

Ojin tells the agent to answer from your reference material when it covers the question. It adds no instruction to cite sources, to say when your knowledge doesn't cover something, or to keep the material private. Put any such rules in the agent's system prompt.

{% hint style="danger" %}
**Anyone who can talk to the agent can hear its knowledge.** A caller can ask the agent to read out what is in its prompt or what it finds by search, and what the agent says appears in the transcript. Only add material every caller may hear.
{% endhint %}

## Limits

| What                                                 | Limit                                     |
| ---------------------------------------------------- | ----------------------------------------- |
| A text item (`.txt`, `.md` or pasted text)           | 4 MiB                                     |
| A document (`.pdf`, `.docx`, `.pptx`)                | 500 MB, and up to 4 MiB of extracted text |
| Item title                                           | 200 characters                            |
| Collection name                                      | 100 characters                            |
| Collections per agent                                | 45                                        |
| **Always in the prompt** knowledge one session loads | 4 MiB of text and 500 items               |

When an agent's ticked **Always in the prompt** collections hold more than the session limit, the agent's sessions don't start: connecting answers `422` (see the Session API's [error responses](https://docs.ojin.ai/apps/overview/api-reference.md#error-responses)). The Knowledge page and the agent's checklist warn when that happens. Untick a collection or switch it to **Search only**.

The agent's model sets a lower practical limit. The default model reads about 128,000 tokens in all: your system prompt, the knowledge in the prompt, and the conversation so far. Keep the "Adds ≈N tokens" figure well below that, and move larger material to **Search only** collections. Above the model's limit the agent stays silent: the call stays connected, but the agent can't reply. The estimate assumes about 4 bytes of text per token, so it undercounts text in scripts such as Japanese or Arabic.

## Managing knowledge with the API

Every knowledge endpoint accepts your API key in the `X-API-Key` header (see [Get your API key](https://docs.ojin.ai/getting-started/authentication.md)) and acts on that key's organization. The base URL is `https://api.ojin.ai`.

| Endpoint                                           | What it does                                                                            |
| -------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `GET /v1/knowledge/collections`                    | List the organization's collections, by name                                            |
| `POST /v1/knowledge/collections`                   | Create a collection: `name`, and `in_prompt` (`false` for **Search only**, the default) |
| `PATCH /v1/knowledge/collections/{collection_id}`  | Rename a collection (`name`) or switch its kind (`in_prompt`)                           |
| `DELETE /v1/knowledge/collections/{collection_id}` | Delete a collection and every item in it                                                |
| `POST /v1/knowledge/uploads`                       | Start an upload (see below)                                                             |
| `POST /v1/knowledge/items`                         | Finish an upload (see below)                                                            |
| `GET /v1/knowledge/items`                          | List every item, without its text, plus the organization's limits                       |
| `GET /v1/knowledge/items/{item_id}`                | One item, with the text agents load as `content`                                        |
| `PATCH /v1/knowledge/items/{item_id}`              | Move an item to another collection (`collection_id`)                                    |
| `DELETE /v1/knowledge/items/{item_id}`             | Delete an item                                                                          |
| `POST /v1/knowledge/items/{item_id}/retry`         | Retry an item whose `retryable` is `true`                                               |
| `POST /v1/knowledge/search`                        | Search the organization's knowledge (see [below](#searching-from-your-own-llm))         |

### Uploading a file

Create a collection first: every item needs one.

1. **Start the upload** with the file's exact size in bytes and its type:

   ```bash
   curl -X POST https://api.ojin.ai/v1/knowledge/uploads \
     -H "X-API-Key: $OJIN_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{ "content_length": 48213, "file_extension": "pdf" }'
   ```

   The answer holds an `item_id`, an `upload_url`, the `upload_headers` the upload must send, and `expires_at`. A file over the limit for its type answers `413`.
2. **Upload the file** to `upload_url` with a `PUT` that sends exactly the `upload_headers` and nothing else, within 15 minutes:

   ```bash
   curl -X PUT "$UPLOAD_URL" \
     -H "Content-Type: application/pdf" \
     -H "If-None-Match: *" \
     --data-binary @returns-policy.pdf
   ```

   Upload from your server. The upload URL accepts browser uploads only from the Ojin dashboard.
3. **Finish the upload** with the same `item_id` and `file_extension`, a `title`, and the `collection_id` it goes in:

   ```bash
   curl -X POST https://api.ojin.ai/v1/knowledge/items \
     -H "X-API-Key: $OJIN_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
       "item_id": "'"$ITEM_ID"'",
       "title": "Returns policy",
       "file_extension": "pdf",
       "collection_id": "'"$COLLECTION_ID"'"
     }'
   ```

   A new item answers `201`; finishing the same upload again returns the item with `200`. A collection that isn't your organization's answers `400`.

Each item carries a `status` (`processing`, `ready` or `failed`). A failed item also has a `failure_reason`:

| `failure_reason`    | Meaning                                                                                                  |
| ------------------- | -------------------------------------------------------------------------------------------------------- |
| `no_text`           | No text was found in the file                                                                            |
| `too_much_text`     | The file has more text than an agent can load                                                            |
| `unsupported`       | The file can't be read; check it isn't password-protected or damaged                                     |
| `source_missing`    | The uploaded file is missing; delete the item and upload it again                                        |
| `processing_failed` | The file couldn't be processed; retry it when `retryable` is `true`                                      |
| `not_searchable`    | An item in a **Search only** collection couldn't be made searchable; retry it when `retryable` is `true` |

### Choosing an agent's collections

Set the collections an agent uses with `knowledge_collection_ids` on `PATCH /v1/agents/{agent_id}`:

```bash
curl -X PATCH https://api.ojin.ai/v1/agents/$AGENT_ID \
  -H "X-API-Key: $OJIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "knowledge_collection_ids": ["'"$COLLECTION_ID"'"] }'
```

* The list holds ids of your organization's collections, at most 45, with no id twice. An id that isn't your organization's answers `400`.
* It replaces the agent's whole list. An empty list means the agent uses no knowledge.
* Leave the field out to keep the list as it is.
* Reading the agent returns its current `knowledge_collection_ids`.

## Searching from your own LLM

If you run your own LLM, for example when you drive a face model through the [Python SDK](https://docs.ojin.ai/models/build-with-python-sdk.md) or the [realtime API](https://docs.ojin.ai/models/introduction/api.md), you can search your organization's knowledge and put the passages into your LLM's prompt before it answers.

```bash
curl -X POST https://api.ojin.ai/v1/knowledge/search \
  -H "X-API-Key: $OJIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "query": "How long do customers have to return an item?", "max_results": 5 }'
```

```json
{
  "results": [
    {
      "item_id": "6f0c2a8e-0000-4000-8000-000000000001",
      "title": "Returns policy",
      "page": 2,
      "text": "Customers may return any item within 30 days of delivery…",
      "score": 0.71
    }
  ]
}
```

* `query` is 1 to 1,000 characters. `max_results` is 1 to 20, and 5 when left out.
* Results come most relevant first. `page` is set for PDF and Word files, and `null` otherwise. `score` is a relevance score: higher is more relevant.
* A search covers every collection of the organization, of both kinds. An item in a **Search only** collection is searchable once it shows **Ready**. Text in an **Always in the prompt** collection becomes searchable a little later, usually within minutes, with no status showing it. So keep the material your pipeline searches in **Search only** collections.
* No results is an empty `results` list, not an error.
* Searches are limited to about 60 a minute per organization, counting the dashboard's **Try a search** but not your agents' own searches. Past the limit, a search can answer `429`: wait and try again.
* A search usually takes about a second.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ojin.ai/apps/overview/knowledge.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
