Documents
When the library gets a new book, it finds a place for it on the shelves. It's all neatly organized so you can find each book easily when you need it. In a chatbot, it's like adding these books (or documents) to its system.
Now, imagine someone comes to the library and asks the librarian for a book about dinosaurs. The librarian knows just where to look and finds the best book about dinosaurs for them. In the same way, when someone asks the chatbot a question, the chatbot looks through all its books (or documents) to find the one that matches the question best.
So in this scenario, your chatbot is like the librarian, the documents are like the books, and the act of finding the right document is like the librarian finding the right book for a reader. This is how the chatbot manages to find the right answer to any question it gets asked.
Upload a document
URL: https://api.gigachat.ai/chatbots/{chatbot_id}/documents
Method: POST
Authorization: Authorization: Bearer <API_KEY>
Request Body: JSON
Property | Description | Required |
---|---|---|
name | Client defined name of the document, e.g. File name, URL.. | Yes |
content | The content of the document, i.e., the textual information from the web page or document | Yes |
{
"name": "https://developers.cloudflare.com/workers/learning/how-kv-works/",
"content": "How KV works Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies. Write data to KV and read data from KV When you write to KV, your data is written to central data stores. It is not sent automatically to every location’s cache."
}
Response 201
[
{
"id": "7c4e187d-27e4-4922-a54c-750d6a92d5a2",
"chatbot_id": "8fb205e5-ff46-4bf6-9d7b-4d770935a486",
"user_id": "4c4087f4-805f-4cf4-9957-0571faf82a4d",
"name": "https://developers.cloudflare.com/workers/learning/how-kv-works/-0",
"content": "DOCUMENT NAME: https://developers.cloudflare.com/workers/learning/how-kv/\n\n---\n\nHow KV works Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies. Write data to KV and read data from KV When you write to KV, your data is written to central data stores. It is not sent automatically to every location’s cache.",
"metadata": {
"loc": {
"lines": {
"to": 1,
"from": 1
}
}
},
"embedding": "[0.005706016,0.014266768,0.011446592,-0.05322389,-0.008515823,0.028229399,-0.029860675..]",
"created_at": "2023-06-16T18:18:38.88344+00:00",
"updated_at": "2023-06-16T18:18:38.88344+00:00"
}
]
Update a document
URL: https://api.gigachat.ai/chatbots/{chatbot_id}/documents/{document_id}
Method: PUT
Authorization: Authorization: Bearer <API_KEY>
Request Body:
The request accepts a JSON object with the name
property being required. To see all available properties, see the chatbot schema.
{
"content": "Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies."
}
Response 201
{
"id": "7c4e187d-27e4-4922-a54c-750d6a92d5a2",
"chatbot_id": "8fb205e5-ff46-4bf6-9d7b-4d770935a486",
"user_id": "4c4087f4-805f-4cf4-9957-0571faf82a4d",
"name": "https://developers.cloudflare.com/workers/learning/how-kv/-0",
"content": "Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies.",
"metadata": {
"loc": {
"lines": {
"to": 1,
"from": 1
}
}
},
"embedding": "[0.005706016,0.014266768,0.011446592,-0.05322389,-0.008515823,0.028229399,-0.029860675..]",
"created_at": "2023-06-16T18:18:38.88344+00:00",
"updated_at": "2023-06-16T18:18:38.88344+00:00"
}
Get all documents
URL: https://api.gigachat.ai/chatbots/{chatbot_id}/documents
Method: GET
Authorization: Authorization: Bearer <API_KEY>
Response 200
[
{
"id": "770a990a-b175-4928-8187-b68f5da6cd51",
"chatbot_id": "8fb205e5-ff46-4bf6-9d7b-4d770935a486",
"user_id": "4c4087f4-805f-4cf4-9957-0571faf82a4d",
"name": "https://developers.cloudflare.com/workers/learning/how-kv-works/-0",
"content": "DOCUMENT NAME: https://developers.cloudflare.com/workers/learning/how-kv-works/\n\n---\n\nHow KV works Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies. Write data to KV and read data from KV When you write to KV, your data is written to central data stores. It is not sent automatically to every location’s cache.",
"metadata": {
"loc": {
"lines": {
"to": 1,
"from": 1
}
}
},
"embedding": "[0.005448192,0.013777347,0.013372527,-0.05087228,-0.011975901,0.031494934,-0.028202405..]",
"created_at": "2023-06-12T19:51:49.208127+00:00",
"updated_at": "2023-06-12T19:51:49.208127+00:00"
},
{
"id": "7c4e187d-27e4-4922-a54c-750d6a92d5a2",
"chatbot_id": "8fb205e5-ff46-4bf6-9d7b-4d770935a486",
"user_id": "4c4087f4-805f-4cf4-9957-0571faf82a4d",
"name": "https://developers.cloudflare.com/workers/learning/how-kv/-0",
"content": "Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies.",
"metadata": {
"loc": {
"lines": {
"to": 1,
"from": 1
}
}
},
"embedding": "[0.005706016,0.014266768,0.011446592,-0.05322389,-0.008515823,0.028229399,-0.029860675..]",
"created_at": "2023-06-16T18:18:38.88344+00:00",
"updated_at": "2023-06-16T18:18:38.88344+00:00"
}
]
Get document by ID
URL: https://api.gigachat.ai/chatbots/{chatbot_id}/documents/{document_id}
Method: GET
Authorization: Authorization: Bearer <API_KEY>
Response 200
{
"id": "7c4e187d-27e4-4922-a54c-750d6a92d5a2",
"chatbot_id": "8fb205e5-ff46-4bf6-9d7b-4d770935a486",
"user_id": "4c4087f4-805f-4cf4-9957-0571faf82a4d",
"name": "https://developers.cloudflare.com/workers/learning/how-kv/-0",
"content": "Workers KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s data centers after access. KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs and websites that respond as quickly as a cached static file would. While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can see high latencies.",
"metadata": {
"loc": {
"lines": {
"to": 1,
"from": 1
}
}
},
"embedding": "[0.005706016,0.014266768,0.011446592,-0.05322389,-0.008515823,0.028229399,-0.029860675]",
"created_at": "2023-06-16T18:18:38.88344+00:00",
"updated_at": "2023-06-16T18:18:38.88344+00:00"
}
Delete document by ID
URL: https://api.gigachat.ai/chatbots/{chatbot_id}/documents/{document_id}
Method: DELETE
Authorization: Authorization: Bearer <API_KEY>
Response 204
No content