2024-11-04 13:21:29 +08:00
---
2024-11-05 15:21:37 +08:00
sidebar_position: 1
2024-10-30 19:40:39 +08:00
slug: /http_api_reference
---
2024-10-09 20:26:51 +08:00
2025-01-06 16:54:22 +08:00
# HTTP API
2024-10-14 20:48:23 +08:00
2024-11-25 14:31:01 +08:00
A complete reference for RAGFlow's RESTful API. Before proceeding, please ensure you [have your RAGFlow API key ready for authentication ](https://ragflow.io/docs/dev/acquire_ragflow_api_key ).
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
## DATASET MANAGEMENT
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Create dataset
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/datasets`
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
Creates a dataset.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
- Body:
2024-10-11 09:55:27 +08:00
- `"name"` : `string`
- `"avatar"` : `string`
- `"description"` : `string`
- `"language"` : `string`
2024-10-09 20:26:51 +08:00
- `"embedding_model"` : `string`
2024-10-11 09:55:27 +08:00
- `"permission"` : `string`
2024-10-24 20:10:47 +08:00
- `"chunk_method"` : `string`
2024-10-25 17:11:58 +08:00
- `"parser_config"` : `object`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 20:10:47 +08:00
--data '{
"name": "test_1"
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-21 19:50:45 +08:00
- `"name"` : (*Body parameter*), `string` , *Required*
The unique name of the dataset to create. It must adhere to the following requirements:
- Permitted characters include:
- English letters (a-z, A-Z)
- Digits (0-9)
- "_" (underscore)
- Must begin with an English letter or underscore.
- Maximum 65,535 characters.
- Case-insensitive.
- `"avatar"` : (*Body parameter*), `string`
2024-11-01 18:57:58 +08:00
Base64 encoding of the avatar.
2024-10-21 19:50:45 +08:00
- `"description"` : (*Body parameter*), `string`
2024-10-24 20:04:50 +08:00
A brief description of the dataset to create.
2024-10-21 19:50:45 +08:00
- `"language"` : (*Body parameter*), `string`
The language setting of the dataset to create. Available options:
2024-11-04 13:21:29 +08:00
- `"English"` (default)
2024-10-21 19:50:45 +08:00
- `"Chinese"`
- `"embedding_model"` : (*Body parameter*), `string`
The name of the embedding model to use. For example: `"BAAI/bge-zh-v1.5"`
- `"permission"` : (*Body parameter*), `string`
2024-11-14 18:44:37 +08:00
Specifies who can access the dataset to create. Available options:
- `"me"` : (Default) Only you can manage the dataset.
- `"team"` : All team members can manage the dataset.
2024-10-21 19:50:45 +08:00
- `"chunk_method"` : (*Body parameter*), `enum<string>`
The chunking method of the dataset to create. Available options:
- `"naive"` : General (default)
2024-10-30 15:33:36 +08:00
- `"manual"` : Manual
2024-10-21 19:50:45 +08:00
- `"qa"` : Q& A
- `"table"` : Table
- `"paper"` : Paper
- `"book"` : Book
- `"laws"` : Laws
- `"presentation"` : Presentation
- `"picture"` : Picture
2024-10-25 17:11:58 +08:00
- `"one"` : One
2024-11-01 18:00:15 +08:00
- `"knowledge_graph"` : Knowledge Graph
2024-11-05 15:21:37 +08:00
Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
2024-10-30 17:59:23 +08:00
- `"email"` : Email
2024-10-11 09:55:27 +08:00
2024-10-25 17:11:58 +08:00
- `"parser_config"` : (*Body parameter*), `object`
2024-10-30 15:33:36 +08:00
The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"` :
- If `"chunk_method"` is `"naive"` , the `"parser_config"` object contains the following attributes:
- `"chunk_token_count"` : Defaults to `128` .
- `"layout_recognize"` : Defaults to `true` .
- `"html4excel"` : Indicates whether to convert Excel documents into HTML format. Defaults to `false` .
- `"delimiter"` : Defaults to `"\n!?。;!?"` .
- `"task_page_size"` : Defaults to `12` . For PDF only.
- `"raptor"` : Raptor-specific settings. Defaults to: `{"use_raptor": false}` .
- If `"chunk_method"` is `"qa"` , `"manuel"` , `"paper"` , `"book"` , `"laws"` , or `"presentation"` , the `"parser_config"` object contains the following attribute:
- `"raptor"` : Raptor-specific settings. Defaults to: `{"use_raptor": false}` .
2024-10-30 17:59:23 +08:00
- If `"chunk_method"` is `"table"` , `"picture"` , `"one"` , or `"email"` , `"parser_config"` is an empty JSON object.
2024-10-30 15:33:36 +08:00
- If `"chunk_method"` is `"knowledge_graph"` , the `"parser_config"` object contains the following attributes:
- `"chunk_token_count"` : Defaults to `128` .
- `"delimiter"` : Defaults to `"\n!?。;!?"` .
- `"entity_types"` : Defaults to `["organization","person","location","event","time"]`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-11 09:55:27 +08:00
"code": 0,
"data": {
"avatar": null,
"chunk_count": 0,
2024-10-24 20:10:47 +08:00
"chunk_method": "naive",
"create_date": "Thu, 24 Oct 2024 09:14:07 GMT",
"create_time": 1729761247434,
2024-10-11 09:55:27 +08:00
"created_by": "69736c5e723611efb51b0242ac120007",
"description": null,
"document_count": 0,
"embedding_model": "BAAI/bge-large-zh-v1.5",
2024-10-24 20:10:47 +08:00
"id": "527fa74891e811ef9c650242ac120006",
2024-10-11 09:55:27 +08:00
"language": "English",
"name": "test_1",
"parser_config": {
2024-10-24 20:10:47 +08:00
"chunk_token_num": 128,
"delimiter": "\\n!?;。;!?",
"html4excel": false,
"layout_recognize": true,
"raptor": {
"user_raptor": false
}
2024-10-11 09:55:27 +08:00
},
"permission": "me",
"similarity_threshold": 0.2,
"status": "1",
"tenant_id": "69736c5e723611efb51b0242ac120007",
"token_num": 0,
2024-10-24 20:10:47 +08:00
"update_date": "Thu, 24 Oct 2024 09:14:07 GMT",
"update_time": 1729761247434,
2024-10-11 09:55:27 +08:00
"vector_similarity_weight": 0.3
}
2024-10-09 20:26:51 +08:00
}
```
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-11 09:55:27 +08:00
"code": 102,
"message": "Duplicated knowledgebase name in creating dataset."
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Delete datasets
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**DELETE** `/api/v1/datasets`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Deletes datasets by ID.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: DELETE
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-11 09:55:27 +08:00
- Body:
2024-10-21 19:50:45 +08:00
- `"ids"` : `list[string]`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request DELETE \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-11-12 17:14:33 +08:00
--data '{
"ids": ["test_1", "test_2"]
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-29 19:56:46 +08:00
- `"ids"` : (*Body parameter*), `list[string]`
2024-10-24 20:04:50 +08:00
The IDs of the datasets to delete. If it is not specified, all datasets will be deleted.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0
}
```
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-11 09:55:27 +08:00
"code": 102,
"message": "You don't own the dataset."
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Update dataset
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**PUT** `/api/v1/datasets/{dataset_id}`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Updates configurations for a specified dataset.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: PUT
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-24 16:14:07 +08:00
- Body:
- `"name"` : `string`
- `"embedding_model"` : `string`
- `"chunk_method"` : `enum<string>`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request PUT \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id} \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
2024-11-12 17:14:33 +08:00
"name": "updated_dataset"
2024-10-24 16:14:07 +08:00
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 16:14:07 +08:00
- `dataset_id` : (*Path parameter*)
The ID of the dataset to update.
2024-10-27 08:00:51 +08:00
- `"name"` : (*Body parameter*), `string`
2024-10-25 17:11:58 +08:00
The revised name of the dataset.
2024-10-27 08:00:51 +08:00
- `"embedding_model"` : (*Body parameter*), `string`
The updated embedding model name.
2024-10-21 19:50:45 +08:00
- Ensure that `"chunk_count"` is `0` before updating `"embedding_model"` .
2024-10-29 19:56:46 +08:00
- `"chunk_method"` : (*Body parameter*), `enum<string>`
2024-10-27 08:00:51 +08:00
The chunking method for the dataset. Available options:
2024-10-21 19:50:45 +08:00
- `"naive"` : General
- `"manual` : Manual
- `"qa"` : Q& A
- `"table"` : Table
- `"paper"` : Paper
- `"book"` : Book
- `"laws"` : Laws
- `"presentation"` : Presentation
- `"picture"` : Picture
- `"one"` :One
2024-11-05 15:21:37 +08:00
- `"email"` : Email
- `"knowledge_graph"` : Knowledge Graph
Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0
}
```
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-11 09:55:27 +08:00
"code": 102,
"message": "Can't change tenant_id."
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### List datasets
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**GET** `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
2024-10-09 20:26:51 +08:00
2024-10-22 17:10:23 +08:00
Lists datasets.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: GET
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request GET \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets?page={page}& page_size={page_size}& orderby={orderby}& desc={desc}& name={dataset_name}& id={dataset_id} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > '
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-27 08:00:51 +08:00
- `page` : (*Filter parameter*)
2024-10-21 19:50:45 +08:00
Specifies the page on which the datasets will be displayed. Defaults to `1` .
2024-10-27 08:00:51 +08:00
- `page_size` : (*Filter parameter*)
2024-11-05 15:21:37 +08:00
The number of datasets on each page. Defaults to `30` .
2024-10-27 08:00:51 +08:00
- `orderby` : (*Filter parameter*)
2024-10-21 19:50:45 +08:00
The field by which datasets should be sorted. Available options:
2024-10-24 16:14:07 +08:00
- `create_time` (default)
- `update_time`
2024-10-27 08:00:51 +08:00
- `desc` : (*Filter parameter*)
2024-10-24 16:14:07 +08:00
Indicates whether the retrieved datasets should be sorted in descending order. Defaults to `true` .
2024-10-27 08:00:51 +08:00
- `name` : (*Filter parameter*)
2024-10-23 22:58:37 +08:00
The name of the dataset to retrieve.
2024-10-27 08:00:51 +08:00
- `id` : (*Filter parameter*)
2024-10-24 16:14:07 +08:00
The ID of the dataset to retrieve.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0,
"data": [
{
2024-10-11 09:55:27 +08:00
"avatar": "",
"chunk_count": 59,
"create_date": "Sat, 14 Sep 2024 01:12:37 GMT",
"create_time": 1726276357324,
"created_by": "69736c5e723611efb51b0242ac120007",
"description": null,
"document_count": 1,
"embedding_model": "BAAI/bge-large-zh-v1.5",
"id": "6e211ee0723611efa10a0242ac120007",
"language": "English",
"name": "mysql",
2024-10-24 20:10:47 +08:00
"chunk_method": "knowledge_graph",
2024-10-11 09:55:27 +08:00
"parser_config": {
"chunk_token_num": 8192,
"delimiter": "\\n!?;。;!?",
"entity_types": [
"organization",
"person",
"location",
"event",
"time"
]
},
"permission": "me",
"similarity_threshold": 0.2,
"status": "1",
"tenant_id": "69736c5e723611efb51b0242ac120007",
"token_num": 12744,
"update_date": "Thu, 10 Oct 2024 04:07:23 GMT",
"update_time": 1728533243536,
"vector_similarity_weight": 0.3
2024-10-09 20:26:51 +08:00
}
2024-10-11 09:55:27 +08:00
]
2024-10-09 20:26:51 +08:00
}
```
2024-11-01 18:57:58 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-11 09:55:27 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-11 09:55:27 +08:00
"code": 102,
"message": "The dataset doesn't exist"
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
## FILE MANAGEMENT WITHIN DATASET
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Upload documents
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/datasets/{dataset_id}/documents`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Uploads documents to a specified dataset.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-22 17:10:23 +08:00
- `'Content-Type: multipart/form-data'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
- Form:
2024-10-22 17:10:23 +08:00
- `'file=@{FILE_PATH}'`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents \
2024-10-09 20:26:51 +08:00
--header 'Content-Type: multipart/form-data' \
2024-12-19 20:08:22 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-23 11:00:35 +08:00
--form 'file=@./test1.txt' \
--form 'file=@./test2.pdf'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
2024-10-22 17:10:23 +08:00
The ID of the dataset to which the documents will be uploaded.
2024-10-24 20:04:50 +08:00
- `'file'` : (*Body parameter*)
A document to upload.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-24 20:10:47 +08:00
"code": 0,
"data": [
{
"chunk_method": "naive",
"created_by": "69736c5e723611efb51b0242ac120007",
"dataset_id": "527fa74891e811ef9c650242ac120006",
"id": "b330ec2e91ec11efbc510242ac120004",
"location": "1.txt",
"name": "1.txt",
"parser_config": {
"chunk_token_num": 128,
"delimiter": "\\n!?;。;!?",
"html4excel": false,
"layout_recognize": true,
"raptor": {
"user_raptor": false
}
},
"run": "UNSTART",
"size": 17966,
"thumbnail": "",
"type": "doc"
}
]
2024-10-09 20:26:51 +08:00
}
```
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-14 20:03:33 +08:00
"code": 101,
"message": "No file part!"
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-10-16 18:41:24 +08:00
2024-12-18 19:01:05 +08:00
### Update document
2024-10-21 09:47:59 +08:00
2024-10-28 14:15:36 +08:00
**PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
2024-10-16 18:41:24 +08:00
2024-10-21 09:47:59 +08:00
Updates configurations for a specified document.
2024-10-16 18:41:24 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-16 18:41:24 +08:00
2024-10-21 09:47:59 +08:00
- Method: PUT
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
2024-10-16 18:41:24 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-22 17:10:23 +08:00
- `"name"` :`string`
- `"chunk_method"` :`string`
2024-10-23 20:07:47 +08:00
- `"parser_config"` :`object`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-16 18:41:24 +08:00
```bash
2024-10-21 09:47:59 +08:00
curl --request PUT \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/info/{document_id} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
--data '
{
"name": "manual.txt",
"chunk_method": "manual",
"parser_config": {"chunk_token_count": 128}
}'
2024-10-21 09:47:59 +08:00
2024-10-16 18:41:24 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-16 18:41:24 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The ID of the associated dataset.
- `document_id` : (*Path parameter*)
The ID of the document to update.
2024-10-22 17:10:23 +08:00
- `"name"` : (*Body parameter*), `string`
- `"chunk_method"` : (*Body parameter*), `string`
2024-10-23 11:00:35 +08:00
The parsing method to apply to the document:
2024-10-22 17:10:23 +08:00
- `"naive"` : General
- `"manual` : Manual
- `"qa"` : Q& A
- `"table"` : Table
- `"paper"` : Paper
- `"book"` : Book
- `"laws"` : Laws
- `"presentation"` : Presentation
- `"picture"` : Picture
- `"one"` : One
2024-11-01 18:57:58 +08:00
- `"knowledge_graph"` : Knowledge Graph
2024-11-05 15:21:37 +08:00
Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
2024-10-30 17:59:23 +08:00
- `"email"` : Email
2024-10-29 19:56:46 +08:00
- `"parser_config"` : (*Body parameter*), `object`
2024-10-30 15:33:36 +08:00
The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"` :
- If `"chunk_method"` is `"naive"` , the `"parser_config"` object contains the following attributes:
- `"chunk_token_count"` : Defaults to `128` .
- `"layout_recognize"` : Defaults to `true` .
- `"html4excel"` : Indicates whether to convert Excel documents into HTML format. Defaults to `false` .
- `"delimiter"` : Defaults to `"\n!?。;!?"` .
- `"task_page_size"` : Defaults to `12` . For PDF only.
- `"raptor"` : Raptor-specific settings. Defaults to: `{"use_raptor": false}` .
- If `"chunk_method"` is `"qa"` , `"manuel"` , `"paper"` , `"book"` , `"laws"` , or `"presentation"` , the `"parser_config"` object contains the following attribute:
- `"raptor"` : Raptor-specific settings. Defaults to: `{"use_raptor": false}` .
2024-10-30 17:59:23 +08:00
- If `"chunk_method"` is `"table"` , `"picture"` , `"one"` , or `"email"` , `"parser_config"` is an empty JSON object.
2024-10-30 15:33:36 +08:00
- If `"chunk_method"` is `"knowledge_graph"` , the `"parser_config"` object contains the following attributes:
- `"chunk_token_count"` : Defaults to `128` .
- `"delimiter"` : Defaults to `"\n!?。;!?"` .
- `"entity_types"` : Defaults to `["organization","person","location","event","time"]`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-16 18:41:24 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-16 18:41:24 +08:00
```json
{
"code": 0
2024-10-21 09:47:59 +08:00
}
2024-10-16 18:41:24 +08:00
```
2024-11-01 18:57:58 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-16 18:41:24 +08:00
```json
{
"code": 102,
2024-10-23 11:00:35 +08:00
"message": "The dataset does not have the document."
2024-10-16 18:41:24 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Download document
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Downloads a document from a specified dataset.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: GET
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
- Output:
2024-10-24 11:02:09 +08:00
- `'{PATH_TO_THE_FILE}'`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request GET \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--output ./ragflow.txt
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `documents_id` : (*Path parameter*)
2024-10-23 11:00:35 +08:00
The ID of the document to download.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-24 11:02:09 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-12-19 14:36:51 +08:00
```json
2024-10-25 17:11:58 +08:00
This is a test to verify the file download feature.
2024-10-24 11:02:09 +08:00
```
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-14 20:03:33 +08:00
"code": 102,
"message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
### List documents
2024-10-09 20:26:51 +08:00
2024-11-04 20:03:14 +08:00
**GET** `/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name}`
2024-10-09 20:26:51 +08:00
2024-10-22 17:10:23 +08:00
Lists documents in a specified dataset.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: GET
2024-11-04 20:03:14 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request GET \
2024-11-04 20:03:14 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents?page={page}& page_size={page_size}& orderby={orderby}& desc={desc}& keywords={keywords}& id={document_id}& name={document_name} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > '
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `keywords` : (*Filter parameter*), `string`
2024-10-23 22:58:37 +08:00
The keywords used to match document titles.
2024-11-04 20:03:14 +08:00
- `page` : (*Filter parameter*), `integer`
Specifies the page on which the documents will be displayed. Defaults to `1` .
- `page_size` : (*Filter parameter*), `integer`
2024-11-05 15:21:37 +08:00
The maximum number of documents on each page. Defaults to `30` .
2024-10-24 20:04:50 +08:00
- `orderby` : (*Filter parameter*), `string`
2024-10-23 11:00:35 +08:00
The field by which documents should be sorted. Available options:
2024-10-24 20:04:50 +08:00
- `create_time` (default)
- `update_time`
- `desc` : (*Filter parameter*), `boolean`
2024-10-24 16:14:07 +08:00
Indicates whether the retrieved documents should be sorted in descending order. Defaults to `true` .
2024-10-24 20:04:50 +08:00
- `id` : (*Filter parameter*), `string`
2024-10-23 22:58:37 +08:00
The ID of the document to retrieve.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0,
"data": {
"docs": [
{
"chunk_count": 0,
2024-10-14 20:03:33 +08:00
"create_date": "Mon, 14 Oct 2024 09:11:01 GMT",
"create_time": 1728897061948,
"created_by": "69736c5e723611efb51b0242ac120007",
"id": "3bcfbf8a8a0c11ef8aba0242ac120006",
"knowledgebase_id": "7898da028a0511efbf750242ac120005",
"location": "Test_2.txt",
"name": "Test_2.txt",
2024-10-09 20:26:51 +08:00
"parser_config": {
"chunk_token_count": 128,
"delimiter": "\n!?。;!?",
"layout_recognize": true,
"task_page_size": 12
},
2024-11-01 18:00:15 +08:00
"chunk_method": "naive",
2024-10-09 20:26:51 +08:00
"process_begin_at": null,
"process_duation": 0.0,
"progress": 0.0,
"progress_msg": "",
"run": "0",
2024-10-14 20:03:33 +08:00
"size": 7,
2024-10-09 20:26:51 +08:00
"source_type": "local",
"status": "1",
"thumbnail": null,
"token_count": 0,
"type": "doc",
2024-10-14 20:03:33 +08:00
"update_date": "Mon, 14 Oct 2024 09:11:01 GMT",
"update_time": 1728897061948
2024-10-09 20:26:51 +08:00
}
],
2024-10-14 20:03:33 +08:00
"total": 1
}
2024-10-09 20:26:51 +08:00
}
```
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-14 20:03:33 +08:00
"code": 102,
"message": "You don't own the dataset 7898da028a0511efbf750242ac1220005. "
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
### Delete documents
2024-10-21 09:47:59 +08:00
2024-10-28 14:15:36 +08:00
**DELETE** `/api/v1/datasets/{dataset_id}/documents`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Deletes documents by ID.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
- Method: DELETE
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'Content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"ids"` : `list[string]`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```bash
2024-10-21 09:47:59 +08:00
curl --request DELETE \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-11-07 19:26:03 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"ids": ["id_1","id_2"]
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
2024-10-29 19:56:46 +08:00
- `"ids"` : (*Body parameter*), `list[string]`
2024-10-24 20:04:50 +08:00
The IDs of the documents to delete. If it is not specified, all documents in the specified dataset will be deleted.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0
2024-10-21 09:47:59 +08:00
}.
2024-10-09 20:26:51 +08:00
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-14 20:03:33 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-14 20:03:33 +08:00
"code": 102,
2024-10-21 09:47:59 +08:00
"message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Parse documents
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/datasets/{dataset_id}/chunks`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Parses documents in a specified dataset.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/chunks`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"document_ids"` : `list[string]`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/chunks \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
2024-10-23 20:07:47 +08:00
The dataset ID.
2024-10-24 16:14:07 +08:00
- `"document_ids"` : (*Body parameter*), `list[string]` , *Required*
2024-10-23 20:07:47 +08:00
The IDs of the documents to parse.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0
}
```
2024-11-01 18:57:58 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-16 18:41:24 +08:00
"code": 102,
"message": "`document_ids` is required"
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Stop parsing documents
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**DELETE** `/api/v1/datasets/{dataset_id}/chunks`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Stops parsing specified documents.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
- Method: DELETE
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/chunks`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"document_ids"` : `list[string]`
2024-10-21 19:50:45 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request DELETE \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/chunks \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `"document_ids"` : (*Body parameter*), `list[string]` , *Required*
2024-10-23 20:07:47 +08:00
The IDs of the documents for which the parsing should be stopped.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```json
2024-10-09 20:26:51 +08:00
{
"code": 0
}
```
2024-11-01 18:57:58 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-16 18:41:24 +08:00
"code": 102,
"message": "`document_ids` is required"
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-25 20:21:38 +08:00
## CHUNK MANAGEMENT WITHIN DATASET
---
2024-12-18 19:01:05 +08:00
### Add chunk
2024-10-21 09:47:59 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
2024-10-21 09:47:59 +08:00
Adds a chunk to a specified document in a specified dataset.
2024-12-18 19:01:05 +08:00
#### Request
2024-10-21 09:47:59 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
2024-10-21 09:47:59 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-21 09:47:59 +08:00
- Body:
2024-10-23 20:07:47 +08:00
- `"content"` : `string`
2024-10-23 11:00:35 +08:00
- `"important_keywords"` : `list[string]`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 09:47:59 +08:00
```bash
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
2024-12-12 09:57:52 +08:00
"content": "< CHUNK_CONTENT_HERE > "
2024-10-24 16:14:07 +08:00
}'
2024-10-21 09:47:59 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-21 09:47:59 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `document_ids` : (*Path parameter*)
The associated document ID.
2024-10-23 20:07:47 +08:00
- `"content"` : (*Body parameter*), `string` , *Required*
The text content of the chunk.
2024-10-24 20:04:50 +08:00
- `"important_keywords` (*Body parameter*), `list[string]`
2024-10-23 20:07:47 +08:00
The key terms or phrases to tag with the chunk.
2024-12-30 19:01:44 +08:00
- `"questions"` (*Body parameter*), `list[string]`
If there is a given question, the embedded chunks will be based on them
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-21 09:47:59 +08:00
```json
{
"code": 0,
"data": {
"chunk": {
2024-12-30 19:01:44 +08:00
"content": "who are you",
"create_time": "2024-12-30 16:59:55",
"create_timestamp": 1735549195.969164,
"dataset_id": "72f36e1ebdf411efb7250242ac120006",
"document_id": "61d68474be0111ef98dd0242ac120006",
"id": "12ccdc56e59837e5",
"important_keywords": [],
"questions": []
2024-10-21 09:47:59 +08:00
}
}
}
```
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-21 09:47:59 +08:00
```json
{
"code": 102,
"message": "`content` is required"
}
```
---
2024-12-18 19:01:05 +08:00
### List chunks
2024-10-09 20:26:51 +08:00
2024-11-04 20:03:14 +08:00
**GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={id}`
2024-10-09 20:26:51 +08:00
2024-10-22 17:10:23 +08:00
Lists chunks in a specified document.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: GET
2024-11-04 20:03:14 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request GET \
2024-11-04 20:03:14 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}& page={page}& page_size={page_size}& id={chunk_id} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > '
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-09 20:26:51 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `document_ids` : (*Path parameter*)
The associated document ID.
2024-10-25 17:11:58 +08:00
- `keywords` (*Filter parameter*), `string`
2024-10-24 20:04:50 +08:00
The keywords used to match chunk content.
2024-11-04 20:03:14 +08:00
- `page` (*Filter parameter*), `integer`
Specifies the page on which the chunks will be displayed. Defaults to `1` .
- `page_size` (*Filter parameter*), `integer`
The maximum number of chunks on each page. Defaults to `1024` .
2024-10-25 17:11:58 +08:00
- `id` (*Filter parameter*), `string`
2024-10-24 20:04:50 +08:00
The ID of the chunk to retrieve.
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-16 18:41:24 +08:00
"code": 0,
2024-10-09 20:26:51 +08:00
"data": {
2024-10-24 20:10:47 +08:00
"chunks": [
{
"available_int": 1,
"content": "This is a test content.",
"docnm_kwd": "1.txt",
"document_id": "b330ec2e91ec11efbc510242ac120004",
"id": "b48c170e90f70af998485c1065490726",
"image_id": "",
"important_keywords": "",
"positions": [
""
]
}
],
2024-10-09 20:26:51 +08:00
"doc": {
2024-10-24 20:10:47 +08:00
"chunk_count": 1,
"chunk_method": "naive",
"create_date": "Thu, 24 Oct 2024 09:45:27 GMT",
"create_time": 1729763127646,
2024-10-16 18:41:24 +08:00
"created_by": "69736c5e723611efb51b0242ac120007",
2024-10-24 20:10:47 +08:00
"dataset_id": "527fa74891e811ef9c650242ac120006",
"id": "b330ec2e91ec11efbc510242ac120004",
"location": "1.txt",
"name": "1.txt",
2024-10-09 20:26:51 +08:00
"parser_config": {
2024-10-24 20:10:47 +08:00
"chunk_token_num": 128,
"delimiter": "\\n!?;。;!?",
"html4excel": false,
"layout_recognize": true,
"raptor": {
"user_raptor": false
}
2024-10-09 20:26:51 +08:00
},
2024-10-24 20:10:47 +08:00
"process_begin_at": "Thu, 24 Oct 2024 09:56:44 GMT",
"process_duation": 0.54213,
"progress": 0.0,
"progress_msg": "Task dispatched...",
"run": "2",
"size": 17966,
2024-10-09 20:26:51 +08:00
"source_type": "local",
"status": "1",
2024-10-24 20:10:47 +08:00
"thumbnail": "",
"token_count": 8,
2024-10-09 20:26:51 +08:00
"type": "doc",
2024-10-24 20:10:47 +08:00
"update_date": "Thu, 24 Oct 2024 11:03:15 GMT",
"update_time": 1729767795721
2024-10-09 20:26:51 +08:00
},
2024-10-24 20:10:47 +08:00
"total": 1
2024-10-16 18:41:24 +08:00
}
2024-10-09 20:26:51 +08:00
}
```
2024-11-01 18:57:58 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```json
2024-10-09 20:26:51 +08:00
{
2024-10-16 18:41:24 +08:00
"code": 102,
"message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
2024-10-09 20:26:51 +08:00
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Delete chunks
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**DELETE** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Deletes chunks by ID.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: DELETE
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"chunk_ids"` : `list[string]`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request DELETE \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"chunk_ids": ["test_1", "test_2"]
}'
2024-10-09 20:26:51 +08:00
```
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-16 18:41:24 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `document_ids` : (*Path parameter*)
The associated document ID.
- `"chunk_ids"` : (*Body parameter*), `list[string]`
The IDs of the chunks to delete. If it is not specified, all chunks of the specified document will be deleted.
2024-10-16 18:41:24 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-16 18:41:24 +08:00
```json
{
"code": 0
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-16 18:41:24 +08:00
```json
{
"code": 102,
"message": "`chunk_ids` is required"
}
```
2024-10-21 09:47:59 +08:00
---
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
### Update chunk
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Updates content or configurations for a specified chunk.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: PUT
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"content"` : `string`
2024-10-31 16:35:13 +08:00
- `"important_keywords"` : `list[string]`
- `"available"` : `boolean`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request PUT \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id} \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-11-07 19:26:03 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"content": "ragflow123",
2024-11-12 17:14:33 +08:00
"important_keywords": []
2024-10-24 16:14:07 +08:00
}'
2024-10-09 20:26:51 +08:00
```
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-21 09:47:59 +08:00
2024-10-24 20:04:50 +08:00
- `dataset_id` : (*Path parameter*)
The associated dataset ID.
- `document_ids` : (*Path parameter*)
The associated document ID.
- `chunk_id` : (*Path parameter*)
The ID of the chunk to update.
2024-10-23 20:07:47 +08:00
- `"content"` : (*Body parameter*), `string`
The text content of the chunk.
- `"important_keywords"` : (*Body parameter*), `list[string]`
A list of key terms or phrases to tag with the chunk.
- `"available"` : (*Body parameter*) `boolean`
The chunk's availability status in the dataset. Value options:
2024-10-24 20:04:50 +08:00
- `true` : Available (default)
2024-10-24 16:14:07 +08:00
- `false` : Unavailable
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 09:47:59 +08:00
2024-10-16 18:41:24 +08:00
```json
{
"code": 0
}
```
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 09:47:59 +08:00
2024-10-16 18:41:24 +08:00
```json
{
"code": 102,
"message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
}
```
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
---
2024-10-16 18:41:24 +08:00
2024-12-18 19:01:05 +08:00
### Retrieve chunks
2024-10-09 20:26:51 +08:00
2024-10-29 19:56:46 +08:00
**POST** `/api/v1/retrieval`
2024-10-09 20:26:51 +08:00
2024-10-22 17:10:23 +08:00
Retrieves chunks from specified datasets.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
- Method: POST
2024-10-28 15:06:18 +08:00
- URL: `/api/v1/retrieval`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-16 18:41:24 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"question"` : `string`
2024-10-24 16:14:07 +08:00
- `"dataset_ids"` : `list[string]`
- `"document_ids"` : `list[string]`
2024-11-04 20:03:14 +08:00
- `"page"` : `integer`
- `"page_size"` : `integer`
2024-10-23 20:07:47 +08:00
- `"similarity_threshold"` : `float`
- `"vector_similarity_weight"` : `float`
- `"top_k"` : `integer`
- `"rerank_id"` : `string`
- `"keyword"` : `boolean`
- `"highlight"` : `boolean`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-16 18:41:24 +08:00
```bash
curl --request POST \
2024-10-28 15:06:18 +08:00
--url http://{address}/api/v1/retrieval \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-11-07 19:26:03 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"question": "What is advantage of ragflow?",
"dataset_ids": ["b2a62730759d11ef987d0242ac120004"],
"document_ids": ["77df9ef4759a11ef8bdd0242ac120004"]
}'
2024-10-09 20:26:51 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameter
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
- `"question"` : (*Body parameter*), `string` , *Required*
2024-10-24 20:04:50 +08:00
The user query or query keywords.
2024-10-25 17:11:58 +08:00
- `"dataset_ids"` : (*Body parameter*) `list[string]`
The IDs of the datasets to search. If you do not set this argument, ensure that you set `"document_ids"` .
2024-10-24 16:14:07 +08:00
- `"document_ids"` : (*Body parameter*), `list[string]`
2024-10-25 17:11:58 +08:00
The IDs of the documents to search. Ensure that all selected documents use the same embedding model. Otherwise, an error will occur. If you do not set this argument, ensure that you set `"dataset_ids"` .
2024-11-04 20:03:14 +08:00
- `"page"` : (*Body parameter*), `integer`
Specifies the page on which the chunks will be displayed. Defaults to `1` .
- `"page_size"` : (*Body parameter*)
2024-11-05 15:21:37 +08:00
The maximum number of chunks on each page. Defaults to `30` .
2024-10-16 18:41:24 +08:00
- `"similarity_threshold"` : (*Body parameter*)
2024-10-23 20:07:47 +08:00
The minimum similarity score. Defaults to `0.2` .
2024-10-27 08:00:51 +08:00
- `"vector_similarity_weight"` : (*Body parameter*), `float`
2024-10-28 14:15:36 +08:00
The weight of vector cosine similarity. Defaults to `0.3` . If x represents the weight of vector cosine similarity, then (1 - x) is the term similarity weight.
2024-10-25 17:11:58 +08:00
- `"top_k"` : (*Body parameter*), `integer`
2025-01-27 15:45:16 +08:00
The number of chunks engaged in vector cosine computation. Defaults to `1024` .
2024-10-25 17:11:58 +08:00
- `"rerank_id"` : (*Body parameter*), `integer`
2024-10-23 22:58:37 +08:00
The ID of the rerank model.
2024-10-23 20:07:47 +08:00
- `"keyword"` : (*Body parameter*), `boolean`
Indicates whether to enable keyword-based matching:
2024-10-24 16:14:07 +08:00
- `true` : Enable keyword-based matching.
- `false` : Disable keyword-based matching (default).
2024-10-23 20:07:47 +08:00
- `"highlight"` : (*Body parameter*), `boolean`
Specifies whether to enable highlighting of matched terms in the results:
2024-10-24 16:14:07 +08:00
- `true` : Enable highlighting of matched terms.
- `false` : Disable highlighting of matched terms (default).
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-16 18:41:24 +08:00
```json
{
"code": 0,
"data": {
"chunks": [
{
"content": "ragflow content",
"content_ltks": "ragflow content",
"document_id": "5c5999ec7be811ef9cab0242ac120005",
"document_keyword": "1.txt",
"highlight": "< em > ragflow< / em > content",
"id": "d78435d142bd5cf6704da62c778795c5",
2024-11-12 14:59:41 +08:00
"image_id": "",
2024-10-16 18:41:24 +08:00
"important_keywords": [
""
],
"kb_id": "c7ee74067a2c11efb21c0242ac120006",
"positions": [
""
],
"similarity": 0.9669436601210759,
"term_similarity": 1.0,
"vector_similarity": 0.8898122004035864
}
],
"doc_aggs": [
{
"count": 1,
"doc_id": "5c5999ec7be811ef9cab0242ac120005",
"doc_name": "1.txt"
}
],
"total": 1
}
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-16 18:41:24 +08:00
```json
{
"code": 102,
"message": "`datasets` is required."
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
## CHAT ASSISTANT MANAGEMENT
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Create chat assistant
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/chats`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Creates a chat assistant.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-12 13:48:43 +08:00
- Body:
- `"name"` : `string`
- `"avatar"` : `string`
2024-10-24 16:14:07 +08:00
- `"dataset_ids"` : `list[string]`
2024-10-23 20:07:47 +08:00
- `"llm"` : `object`
- `"prompt"` : `object`
2024-10-12 13:48:43 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
```shell
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats \
2024-10-09 20:26:51 +08:00
--header 'Content-Type: application/json' \
2024-12-20 17:34:16 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '{
2024-10-24 20:10:47 +08:00
"dataset_ids": ["0b2cbc8c877f11ef89070242ac120005"],
2024-10-12 13:48:43 +08:00
"name":"new_chat_1"
2024-10-09 20:26:51 +08:00
}'
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-12 13:48:43 +08:00
2024-10-23 20:07:47 +08:00
- `"name"` : (*Body parameter*), `string` , *Required*
The name of the chat assistant.
2024-10-24 20:04:50 +08:00
- `"avatar"` : (*Body parameter*), `string`
Base64 encoding of the avatar.
- `"dataset_ids"` : (*Body parameter*), `list[string]`
The IDs of the associated datasets.
2024-10-23 20:07:47 +08:00
- `"llm"` : (*Body parameter*), `object`
2024-10-25 17:11:58 +08:00
The LLM settings for the chat assistant to create. If it is not explicitly set, a JSON object with the following values will be generated as the default. An `llm` JSON object contains the following attributes:
2024-10-23 20:07:47 +08:00
- `"model_name"` , `string`
2024-10-24 20:04:50 +08:00
The chat model name. If not set, the user's default chat model will be used.
2024-10-23 20:07:47 +08:00
- `"temperature"` : `float`
2024-12-18 15:46:31 +08:00
Controls the randomness of the model's predictions. A lower temperature results in more conservative responses, while a higher temperature yields more creative and diverse responses. Defaults to `0.1` .
2024-10-23 20:07:47 +08:00
- `"top_p"` : `float`
Also known as “nucleus sampling”, this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
- `"presence_penalty"` : `float`
This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2` .
- `"frequency penalty"` : `float`
Similar to the presence penalty, this reduces the model’ s tendency to repeat the same words frequently. Defaults to `0.7` .
- `"max_token"` : `integer`
2024-12-18 15:46:31 +08:00
The maximum length of the model's output, measured in the number of tokens (words or pieces of words). Defaults to `512` . If disabled, you lift the maximum token limit, allowing the model to determine the number of tokens in its responses.
2024-10-23 20:07:47 +08:00
- `"prompt"` : (*Body parameter*), `object`
2024-10-25 17:11:58 +08:00
Instructions for the LLM to follow. If it is not explicitly set, a JSON object with the following values will be generated as the default. A `prompt` JSON object contains the following attributes:
2024-11-15 15:17:34 +08:00
- `"similarity_threshold"` : `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2` .
2024-10-23 20:07:47 +08:00
- `"keywords_similarity_weight"` : `float` This argument sets the weight of keyword similarity in the hybrid similarity score with vector cosine similarity or reranking model similarity. By adjusting this weight, you can control the influence of keyword similarity in relation to other similarity measures. The default value is `0.7` .
- `"top_n"` : `int` This argument specifies the number of top chunks with similarity scores above the `similarity_threshold` that are fed to the LLM. The LLM will *only* access these 'top N' chunks. The default value is `8` .
- `"variables"` : `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations** . Note that:
2024-10-24 20:04:50 +08:00
- `"knowledge"` is a reserved variable, which represents the retrieved chunks.
2024-10-23 20:07:47 +08:00
- All the variables in 'System' should be curly bracketed.
2024-10-24 20:04:50 +08:00
- The default value is `[{"key": "knowledge", "optional": true}]` .
- `"rerank_model"` : `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
2024-12-30 19:22:57 +08:00
- `top_k` : `int` Refers to the process of reordering or selecting the top-k items from a list or set based on a specific ranking criterion. Default to 1024.
2024-10-23 22:58:37 +08:00
- `"empty_response"` : `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank.
2024-10-23 20:07:47 +08:00
- `"opener"` : `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"` .
2024-10-24 16:14:07 +08:00
- `"show_quote` : `boolean` Indicates whether the source of text should be displayed. Defaults to `true` .
2024-10-31 13:34:04 +08:00
- `"prompt"` : `string` The prompt content.
2024-11-01 18:57:58 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 0,
"data": {
"avatar": "",
2024-10-24 20:10:47 +08:00
"create_date": "Thu, 24 Oct 2024 11:18:29 GMT",
"create_time": 1729768709023,
"dataset_ids": [
"527fa74891e811ef9c650242ac120006"
],
2024-10-12 13:48:43 +08:00
"description": "A helpful Assistant",
"do_refer": "1",
2024-10-24 20:10:47 +08:00
"id": "b1f2f15691f911ef81180242ac120003",
2024-10-12 13:48:43 +08:00
"language": "English",
"llm": {
"frequency_penalty": 0.7,
"max_tokens": 512,
2024-10-24 20:10:47 +08:00
"model_name": "qwen-plus@Tongyi -Qianwen",
2024-10-12 13:48:43 +08:00
"presence_penalty": 0.4,
"temperature": 0.1,
"top_p": 0.3
},
2024-10-24 20:10:47 +08:00
"name": "12234",
2024-10-12 13:48:43 +08:00
"prompt": {
2024-10-24 20:10:47 +08:00
"empty_response": "Sorry! No relevant content was found in the knowledge base!",
2024-10-12 13:48:43 +08:00
"keywords_similarity_weight": 0.3,
2024-10-24 20:10:47 +08:00
"opener": "Hi! I'm your assistant, what can I do for you?",
2024-10-31 13:34:04 +08:00
"prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n ",
2024-10-12 13:48:43 +08:00
"rerank_model": "",
"similarity_threshold": 0.2,
"top_n": 6,
"variables": [
{
"key": "knowledge",
"optional": false
}
]
},
"prompt_type": "simple",
"status": "1",
"tenant_id": "69736c5e723611efb51b0242ac120007",
"top_k": 1024,
2024-10-24 20:10:47 +08:00
"update_date": "Thu, 24 Oct 2024 11:18:29 GMT",
"update_time": 1729768709023
2024-10-12 13:48:43 +08:00
}
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 09:47:59 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 102,
"message": "Duplicated chat name in creating dataset."
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Update chat assistant
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**PUT** `/api/v1/chats/{chat_id}`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Updates configurations for a specified chat assistant.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: PUT
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats/{chat_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-23 20:07:47 +08:00
- Body:
- `"name"` : `string`
- `"avatar"` : `string`
2024-10-24 16:14:07 +08:00
- `"dataset_ids"` : `list[string]`
2024-10-23 20:07:47 +08:00
- `"llm"` : `object`
- `"prompt"` : `object`
2024-11-01 18:57:58 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 19:50:45 +08:00
2024-10-12 13:48:43 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request PUT \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats/{chat_id} \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"name":"Test"
}'
2024-10-12 13:48:43 +08:00
```
2024-10-21 09:47:59 +08:00
2024-10-12 13:48:43 +08:00
#### Parameters
2024-10-21 09:47:59 +08:00
2024-10-24 16:14:07 +08:00
- `chat_id` : (*Path parameter*)
The ID of the chat assistant to update.
2024-10-23 20:07:47 +08:00
- `"name"` : (*Body parameter*), `string` , *Required*
2024-10-25 17:11:58 +08:00
The revised name of the chat assistant.
2024-10-24 20:04:50 +08:00
- `"avatar"` : (*Body parameter*), `string`
Base64 encoding of the avatar.
- `"dataset_ids"` : (*Body parameter*), `list[string]`
The IDs of the associated datasets.
2024-10-23 20:07:47 +08:00
- `"llm"` : (*Body parameter*), `object`
2024-10-24 20:04:50 +08:00
The LLM settings for the chat assistant to create. If it is not explicitly set, a dictionary with the following values will be generated as the default. An `llm` object contains the following attributes:
2024-10-23 20:07:47 +08:00
- `"model_name"` , `string`
2024-10-24 20:04:50 +08:00
The chat model name. If not set, the user's default chat model will be used.
2024-10-23 20:07:47 +08:00
- `"temperature"` : `float`
2024-12-18 15:46:31 +08:00
Controls the randomness of the model's predictions. A lower temperature results in more conservative responses, while a higher temperature yields more creative and diverse responses. Defaults to `0.1` .
2024-10-23 20:07:47 +08:00
- `"top_p"` : `float`
Also known as “nucleus sampling”, this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
- `"presence_penalty"` : `float`
This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2` .
- `"frequency penalty"` : `float`
Similar to the presence penalty, this reduces the model’ s tendency to repeat the same words frequently. Defaults to `0.7` .
- `"max_token"` : `integer`
2024-12-18 15:46:31 +08:00
The maximum length of the model's output, measured in the number of tokens (words or pieces of words). Defaults to `512` . If disabled, you lift the maximum token limit, allowing the model to determine the number of tokens in its responses.
2024-10-23 20:07:47 +08:00
- `"prompt"` : (*Body parameter*), `object`
Instructions for the LLM to follow. A `prompt` object contains the following attributes:
2024-11-15 15:17:34 +08:00
- `"similarity_threshold"` : `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted rerank score during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2` .
2024-10-23 20:07:47 +08:00
- `"keywords_similarity_weight"` : `float` This argument sets the weight of keyword similarity in the hybrid similarity score with vector cosine similarity or reranking model similarity. By adjusting this weight, you can control the influence of keyword similarity in relation to other similarity measures. The default value is `0.7` .
- `"top_n"` : `int` This argument specifies the number of top chunks with similarity scores above the `similarity_threshold` that are fed to the LLM. The LLM will *only* access these 'top N' chunks. The default value is `8` .
- `"variables"` : `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations** . Note that:
2024-10-24 20:04:50 +08:00
- `"knowledge"` is a reserved variable, which represents the retrieved chunks.
2024-10-23 20:07:47 +08:00
- All the variables in 'System' should be curly bracketed.
2024-10-24 16:14:07 +08:00
- The default value is `[{"key": "knowledge", "optional": true}]`
2024-10-24 20:04:50 +08:00
- `"rerank_model"` : `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
2024-10-23 22:58:37 +08:00
- `"empty_response"` : `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank.
2024-10-23 20:07:47 +08:00
- `"opener"` : `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"` .
2024-10-24 16:14:07 +08:00
- `"show_quote` : `boolean` Indicates whether the source of text should be displayed. Defaults to `true` .
2024-10-31 13:34:04 +08:00
- `"prompt"` : `string` The prompt content.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 0
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 102,
"message": "Duplicated chat name in updating dataset."
}
```
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### Delete chat assistants
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**DELETE** `/api/v1/chats`
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
Deletes chat assistants by ID.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
2024-10-12 13:48:43 +08:00
- Method: DELETE
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-12 13:48:43 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"ids"` : `list[string]`
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 09:47:59 +08:00
2024-10-12 13:48:43 +08:00
```bash
curl --request DELETE \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"ids": ["test_1", "test_2"]
}'
2024-10-12 13:48:43 +08:00
```
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-12 13:48:43 +08:00
2024-10-23 20:07:47 +08:00
- `"ids"` : (*Body parameter*), `list[string]`
2024-10-24 20:04:50 +08:00
The IDs of the chat assistants to delete. If it is not specified, all chat assistants in the system will be deleted.
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 0
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 09:47:59 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 102,
"message": "ids are required"
}
```
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
---
2024-12-18 19:01:05 +08:00
### List chat assistants
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**GET** `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
2024-10-09 20:26:51 +08:00
2024-10-22 17:10:23 +08:00
Lists chat assistants.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: GET
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-09 20:26:51 +08:00
2024-10-12 13:48:43 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request GET \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats?page={page}& page_size={page_size}& orderby={orderby}& desc={desc}& name={dataset_name}& id={dataset_id} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > '
2024-10-12 13:48:43 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-21 09:47:59 +08:00
2024-10-25 17:11:58 +08:00
- `page` : (*Filter parameter*), `integer`
2024-10-23 20:07:47 +08:00
Specifies the page on which the chat assistants will be displayed. Defaults to `1` .
2024-10-25 17:11:58 +08:00
- `page_size` : (*Filter parameter*), `integer`
2024-11-05 15:21:37 +08:00
The number of chat assistants on each page. Defaults to `30` .
2024-10-25 17:11:58 +08:00
- `orderby` : (*Filter parameter*), `string`
2024-10-23 20:07:47 +08:00
The attribute by which the results are sorted. Available options:
2024-10-24 20:04:50 +08:00
- `create_time` (default)
- `update_time`
2024-10-25 17:11:58 +08:00
- `desc` : (*Filter parameter*), `boolean`
2024-10-24 16:14:07 +08:00
Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `true` .
2024-10-25 17:11:58 +08:00
- `id` : (*Filter parameter*), `string`
2024-10-23 22:58:37 +08:00
The ID of the chat assistant to retrieve.
2024-10-25 17:11:58 +08:00
- `name` : (*Filter parameter*), `string`
2024-10-23 22:58:37 +08:00
The name of the chat assistant to retrieve.
2024-10-12 13:48:43 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 0,
"data": [
{
"avatar": "",
2024-10-24 20:10:47 +08:00
"create_date": "Fri, 18 Oct 2024 06:20:06 GMT",
"create_time": 1729232406637,
2024-10-12 13:48:43 +08:00
"description": "A helpful Assistant",
"do_refer": "1",
2024-10-24 20:10:47 +08:00
"id": "04d0d8e28d1911efa3630242ac120006",
"dataset_ids": ["527fa74891e811ef9c650242ac120006"],
2024-10-12 13:48:43 +08:00
"language": "English",
"llm": {
"frequency_penalty": 0.7,
"max_tokens": 512,
2024-10-24 20:10:47 +08:00
"model_name": "qwen-plus@Tongyi -Qianwen",
2024-10-12 13:48:43 +08:00
"presence_penalty": 0.4,
"temperature": 0.1,
"top_p": 0.3
},
2024-10-24 20:10:47 +08:00
"name": "13243",
2024-10-12 13:48:43 +08:00
"prompt": {
2024-10-24 20:10:47 +08:00
"empty_response": "Sorry! No relevant content was found in the knowledge base!",
2024-10-12 13:48:43 +08:00
"keywords_similarity_weight": 0.3,
2024-10-24 20:10:47 +08:00
"opener": "Hi! I'm your assistant, what can I do for you?",
2024-10-31 13:34:04 +08:00
"prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n",
2024-10-12 13:48:43 +08:00
"rerank_model": "",
"similarity_threshold": 0.2,
"top_n": 6,
"variables": [
{
"key": "knowledge",
"optional": false
}
]
},
"prompt_type": "simple",
"status": "1",
"tenant_id": "69736c5e723611efb51b0242ac120007",
"top_k": 1024,
2024-10-24 20:10:47 +08:00
"update_date": "Fri, 18 Oct 2024 06:20:06 GMT",
"update_time": 1729232406638
2024-10-12 13:48:43 +08:00
}
]
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 09:47:59 +08:00
2024-10-12 13:48:43 +08:00
```json
{
"code": 102,
"message": "The chat doesn't exist"
}
```
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
---
2024-12-19 14:36:51 +08:00
## SESSION MANAGEMENT
2024-12-18 19:01:05 +08:00
---
### Create session with chat assistant
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/chats/{chat_id}/sessions`
2024-10-09 20:26:51 +08:00
2024-11-14 18:44:37 +08:00
Creates a session with a chat assistant.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats/{chat_id}/sessions`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-12 19:35:19 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"name"` : `string`
2025-01-06 20:25:47 +08:00
- `"user_id"` : `string` (optional)
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 19:50:45 +08:00
2024-10-12 19:35:19 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats/{chat_id}/sessions \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"name": "new session"
}'
2024-10-12 19:35:19 +08:00
```
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-10-21 09:47:59 +08:00
2024-10-24 16:14:07 +08:00
- `chat_id` : (*Path parameter*)
The ID of the associated chat assistant.
2024-10-23 20:07:47 +08:00
- `"name"` : (*Body parameter*), `string`
The name of the chat session to create.
2024-12-24 15:59:11 +08:00
- `"user_id"` : (*Body parameter*), `string`
Optional user-defined ID.
2024-10-12 19:35:19 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 0,
"data": {
"chat_id": "2ca4b22e878011ef88fe0242ac120005",
"create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
"create_time": 1728636374571,
"id": "4606b4ec87ad11efbc4f0242ac120006",
"messages": [
{
"content": "Hi! I am your assistant, can I help you?",
"role": "assistant"
}
],
"name": "new session",
"update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
"update_time": 1728636374571
}
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 09:47:59 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 102,
2024-12-19 14:36:51 +08:00
"message": "Name cannot be empty."
2024-10-12 19:35:19 +08:00
}
```
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
---
2024-12-19 14:36:51 +08:00
### Update chat assistant's session
2024-10-21 09:47:59 +08:00
2024-10-28 14:15:36 +08:00
**PUT** `/api/v1/chats/{chat_id}/sessions/{session_id}`
2024-10-21 09:47:59 +08:00
2024-11-14 18:44:37 +08:00
Updates a session of a specified chat assistant.
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-21 09:47:59 +08:00
- Method: PUT
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats/{chat_id}/sessions/{session_id}`
2024-10-21 09:47:59 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-21 09:47:59 +08:00
- Body:
2024-10-31 11:56:30 +08:00
- `"name` : `string`
2025-01-06 20:25:47 +08:00
- `"user_id` : `string` (optional)
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-31 13:34:04 +08:00
2024-10-21 09:47:59 +08:00
```bash
curl --request PUT \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats/{chat_id}/sessions/{session_id} \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
2024-10-25 17:11:58 +08:00
"name": "< REVISED_SESSION_NAME_HERE > "
2024-10-24 16:14:07 +08:00
}'
2024-10-21 09:47:59 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request Parameter
2024-10-21 19:50:45 +08:00
2024-10-24 16:14:07 +08:00
- `chat_id` : (*Path parameter*)
The ID of the associated chat assistant.
- `session_id` : (*Path parameter*)
The ID of the session to update.
2024-12-19 14:36:51 +08:00
- `"name"` : (*Body Parameter*), `string`
2024-10-25 17:11:58 +08:00
The revised name of the session.
2024-12-24 15:59:11 +08:00
- `"user_id"` : (*Body parameter*), `string`
Optional user-defined ID.
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-21 09:47:59 +08:00
```json
{
"code": 0
}
```
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-21 09:47:59 +08:00
```json
{
"code": 102,
2024-10-24 20:04:50 +08:00
"message": "Name cannot be empty."
2024-10-21 09:47:59 +08:00
}
```
---
2024-12-19 14:36:51 +08:00
### List chat assistant's sessions
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**GET** `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
2024-10-09 20:26:51 +08:00
2024-10-23 20:07:47 +08:00
Lists sessions associated with a specified chat assistant.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: GET
2024-12-24 15:59:11 +08:00
- URL: `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}&user_id={user_id}`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 09:47:59 +08:00
2024-10-12 19:35:19 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request GET \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats/{chat_id}/sessions?page={page}& page_size={page_size}& orderby={orderby}& desc={desc}& name={session_name}& id={session_id} \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > '
2024-10-12 19:35:19 +08:00
```
2024-12-18 19:01:05 +08:00
##### Request Parameters
2024-10-21 09:47:59 +08:00
2024-10-24 16:14:07 +08:00
- `chat_id` : (*Path parameter*)
The ID of the associated chat assistant.
2024-10-24 20:04:50 +08:00
- `page` : (*Filter parameter*), `integer`
2024-10-23 20:07:47 +08:00
Specifies the page on which the sessions will be displayed. Defaults to `1` .
2024-10-24 20:04:50 +08:00
- `page_size` : (*Filter parameter*), `integer`
2024-11-05 15:21:37 +08:00
The number of sessions on each page. Defaults to `30` .
2024-10-24 20:04:50 +08:00
- `orderby` : (*Filter parameter*), `string`
2024-10-23 20:07:47 +08:00
The field by which sessions should be sorted. Available options:
2024-10-24 20:04:50 +08:00
- `create_time` (default)
- `update_time`
- `desc` : (*Filter parameter*), `boolean`
2024-10-24 16:14:07 +08:00
Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true` .
2024-10-24 20:04:50 +08:00
- `name` : (*Filter parameter*) `string`
2024-10-23 22:58:37 +08:00
The name of the chat session to retrieve.
2024-10-24 20:04:50 +08:00
- `id` : (*Filter parameter*), `string`
2024-10-24 16:14:07 +08:00
The ID of the chat session to retrieve.
2024-12-24 15:59:11 +08:00
- `user_id` : (*Filter parameter*), `string`
The optional user-defined ID passed in when creating session.
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 0,
"data": [
{
"chat": "2ca4b22e878011ef88fe0242ac120005",
"create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
"create_time": 1728636403974,
"id": "578d541e87ad11ef96b90242ac120006",
"messages": [
{
"content": "Hi! I am your assistant, can I help you?",
"role": "assistant"
}
],
"name": "new session",
"update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
"update_time": 1728636403974
}
]
}
```
2024-10-21 09:47:59 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 09:47:59 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 102,
"message": "The session doesn't exist"
}
```
2024-10-21 09:47:59 +08:00
---
2024-10-12 19:35:19 +08:00
2024-12-19 14:36:51 +08:00
### Delete chat assistant's sessions
2024-10-12 19:35:19 +08:00
2024-10-28 14:15:36 +08:00
**DELETE** `/api/v1/chats/{chat_id}/sessions`
2024-10-12 19:35:19 +08:00
2024-11-14 18:44:37 +08:00
Deletes sessions of a chat assistant by ID.
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: DELETE
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats/{chat_id}/sessions`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-12 19:35:19 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"ids"` : `list[string]`
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 09:47:59 +08:00
2024-10-12 19:35:19 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request DELETE \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats/{chat_id}/sessions \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-11-07 19:26:03 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data '
{
"ids": ["test_1", "test_2"]
}'
2024-10-12 19:35:19 +08:00
```
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request Parameters
2024-10-21 19:50:45 +08:00
2024-10-24 16:14:07 +08:00
- `chat_id` : (*Path parameter*)
The ID of the associated chat assistant.
2024-10-23 20:07:47 +08:00
- `"ids"` : (*Body Parameter*), `list[string]`
2024-10-24 20:04:50 +08:00
The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified chat assistant will be deleted.
2024-10-21 19:50:45 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Success:
2024-10-21 19:50:45 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 0
}
```
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 102,
"message": "The chat doesn't own the session"
}
```
2024-10-09 20:26:51 +08:00
2024-10-21 09:47:59 +08:00
---
2024-10-12 19:35:19 +08:00
2024-12-18 19:01:05 +08:00
### Converse with chat assistant
2024-10-09 20:26:51 +08:00
2024-10-28 14:15:36 +08:00
**POST** `/api/v1/chats/{chat_id}/completions`
2024-10-09 20:26:51 +08:00
2024-11-14 18:44:37 +08:00
Asks a specified chat assistant a question to start an AI-powered conversation.
:::tip NOTE
- In streaming mode, not all responses include a reference, as this depends on the system's judgement.
- In streaming mode, the last message is an empty message:
2024-12-19 14:36:51 +08:00
```json
2024-11-14 18:44:37 +08:00
data:
{
"code": 0,
"data": true
}
```
:::
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-10-09 20:26:51 +08:00
- Method: POST
2024-10-28 14:15:36 +08:00
- URL: `/api/v1/chats/{chat_id}/completions`
2024-10-09 20:26:51 +08:00
- Headers:
2024-10-21 19:50:45 +08:00
- `'content-Type: application/json'`
2024-10-31 11:56:30 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-10-12 19:35:19 +08:00
- Body:
2024-10-23 11:00:35 +08:00
- `"question"` : `string`
2024-10-23 20:07:47 +08:00
- `"stream"` : `boolean`
2025-01-06 20:25:47 +08:00
- `"session_id"` : `string` (optional)
- `"user_id` : `string` (optional)
2024-10-09 20:26:51 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-10-21 09:47:59 +08:00
2024-10-12 19:35:19 +08:00
```bash
2024-10-09 20:26:51 +08:00
curl --request POST \
2024-10-28 14:15:36 +08:00
--url http://{address}/api/v1/chats/{chat_id}/completions \
2024-10-24 16:14:07 +08:00
--header 'Content-Type: application/json' \
2024-10-31 11:56:30 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
2024-10-24 16:14:07 +08:00
--data-binary '
{
}'
2024-10-12 19:35:19 +08:00
```
2024-12-13 10:25:52 +08:00
```bash
curl --request POST \
--url http://{address}/api/v1/chats/{chat_id}/completions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--data-binary '
{
"question": "Who are you",
"stream": true,
"session_id":"9fa7691cb85c11ef9c5f0242ac120005"
}'
```
2024-12-18 19:01:05 +08:00
##### Request Parameters
2024-10-21 19:50:45 +08:00
2024-10-24 16:14:07 +08:00
- `chat_id` : (*Path parameter*)
The ID of the associated chat assistant.
2024-11-14 18:44:37 +08:00
- `"question"` : (*Body Parameter*), `string` , *Required*
2024-10-25 17:11:58 +08:00
The question to start an AI-powered conversation.
2024-10-24 20:04:50 +08:00
- `"stream"` : (*Body Parameter*), `boolean`
2024-10-23 20:07:47 +08:00
Indicates whether to output responses in a streaming way:
2024-11-22 11:11:06 +08:00
- `true` : Enable streaming (default).
- `false` : Disable streaming.
2024-10-23 11:00:35 +08:00
- `"session_id"` : (*Body Parameter*)
2024-10-24 20:04:50 +08:00
The ID of session. If it is not provided, a new session will be generated.
2024-12-24 15:59:11 +08:00
- `"user_id"` : (*Body parameter*), `string`
The optional user-defined ID. Valid *only* when no `session_id` is provided.
2024-10-21 09:47:59 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-12-13 10:25:52 +08:00
Success without `session_id` :
2024-12-19 14:36:51 +08:00
```json
2024-12-13 10:25:52 +08:00
data:{
"code": 0,
"message": "",
"data": {
"answer": "Hi! I'm your assistant, what can I do for you?",
"reference": {},
"audio_binary": null,
"id": null,
"session_id": "b01eed84b85611efa0e90242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": true
}
```
2024-10-21 19:50:45 +08:00
2024-12-13 10:25:52 +08:00
Success with `session_id` :
2024-10-21 19:50:45 +08:00
2024-12-19 14:36:51 +08:00
```json
2024-11-06 18:03:45 +08:00
data:{
2024-10-12 19:35:19 +08:00
"code": 0,
"data": {
2024-11-06 18:03:45 +08:00
"answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a",
2024-10-12 19:35:19 +08:00
"reference": {},
"audio_binary": null,
2024-11-06 18:03:45 +08:00
"id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
"session_id": "82b0ab2a9c1911ef9d870242ac120006"
2024-10-12 19:35:19 +08:00
}
}
2024-11-06 18:03:45 +08:00
data:{
2024-10-12 19:35:19 +08:00
"code": 0,
"data": {
2024-11-06 18:03:45 +08:00
"answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base. My responses are based on the information available in the knowledge base and",
2024-10-12 19:35:19 +08:00
"reference": {},
"audio_binary": null,
2024-11-06 18:03:45 +08:00
"id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
"session_id": "82b0ab2a9c1911ef9d870242ac120006"
2024-10-12 19:35:19 +08:00
}
}
2024-11-06 18:03:45 +08:00
data:{
2024-10-12 19:35:19 +08:00
"code": 0,
"data": {
2024-11-06 18:03:45 +08:00
"answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base. My responses are based on the information available in the knowledge base and any relevant chat history.",
2024-10-12 19:35:19 +08:00
"reference": {},
"audio_binary": null,
2024-11-06 18:03:45 +08:00
"id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
"session_id": "82b0ab2a9c1911ef9d870242ac120006"
2024-10-12 19:35:19 +08:00
}
}
2024-11-06 18:03:45 +08:00
data:{
2024-10-12 19:35:19 +08:00
"code": 0,
"data": {
2024-11-06 18:03:45 +08:00
"answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base ##0 $$. My responses are based on the information available in the knowledge base and any relevant chat history.",
2024-10-12 19:35:19 +08:00
"reference": {
2024-11-06 18:03:45 +08:00
"total": 1,
2024-10-12 19:35:19 +08:00
"chunks": [
{
2024-11-06 18:03:45 +08:00
"id": "faf26c791128f2d5e821f822671063bd",
"content": "xxxxxxxx",
"document_id": "dd58f58e888511ef89c90242ac120006",
"document_name": "1.txt",
"dataset_id": "8e83e57a884611ef9d760242ac120006",
"image_id": "",
"similarity": 0.7,
"vector_similarity": 0.0,
"term_similarity": 1.0,
2024-10-12 19:35:19 +08:00
"positions": [
""
]
}
],
"doc_aggs": [
{
"doc_name": "1.txt",
2024-11-06 18:03:45 +08:00
"doc_id": "dd58f58e888511ef89c90242ac120006",
2024-10-24 20:10:47 +08:00
"count": 1
2024-10-12 19:35:19 +08:00
}
]
},
2024-11-06 18:03:45 +08:00
"prompt": "xxxxxxxxxxx",
"id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
"session_id": "82b0ab2a9c1911ef9d870242ac120006"
2024-10-12 19:35:19 +08:00
}
}
data:{
"code": 0,
"data": true
}
```
2024-10-21 19:50:45 +08:00
2024-10-23 20:07:47 +08:00
Failure:
2024-10-21 19:50:45 +08:00
2024-10-12 19:35:19 +08:00
```json
{
"code": 102,
"message": "Please input your question."
}
2024-11-06 18:03:45 +08:00
```
2024-11-14 18:44:37 +08:00
---
2024-12-18 19:01:05 +08:00
### Create session with agent
2024-11-06 18:03:45 +08:00
**POST** `/api/v1/agents/{agent_id}/sessions`
2024-11-14 18:44:37 +08:00
Creates a session with an agent.
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-11-06 18:03:45 +08:00
- Method: POST
2025-02-18 09:45:40 +08:00
- URL: `/api/v1/agents/{agent_id}/sessions?user_id={user_id}`
2024-11-06 18:03:45 +08:00
- Headers:
2025-02-18 09:45:40 +08:00
- `'content-Type: application/json' or 'multipart/form-data'`
2024-11-06 18:03:45 +08:00
- `'Authorization: Bearer <YOUR_API_KEY>'`
- Body:
2024-12-20 17:34:16 +08:00
- the required parameters:`str`
2025-02-18 09:45:40 +08:00
- other parameters:
The parameters in the begin component.
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
##### Request example
2024-12-20 17:34:16 +08:00
If `begin` component in the agent doesn't have required parameters:
```bash
curl --request POST \
--url http://{address}/api/v1/agents/{agent_id}/sessions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--data '{
}'
```
If `begin` component in the agent has required parameters:
2024-11-06 18:03:45 +08:00
```bash
curl --request POST \
--url http://{address}/api/v1/agents/{agent_id}/sessions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--data '{
2024-12-20 17:34:16 +08:00
"lang":"Japanese",
"file":"Who are you"
2024-11-06 18:03:45 +08:00
}'
```
2025-02-18 09:45:40 +08:00
If `begin` component in the agent has required file parameters:
```bash
curl --request POST \
--url http://{address}/api/v1/agents/{agent_id}/sessions?user_id={user_id} \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--form '< FILE_KEY > =@./test1.png'
```
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-11-06 18:03:45 +08:00
2024-11-14 18:44:37 +08:00
- `agent_id` : (*Path parameter*)
2024-12-19 18:19:56 +08:00
The ID of the associated agent.
2025-02-18 09:45:40 +08:00
- `user_id` : (*Filter parameter*), string
The optional user-defined ID for parsing docs(especially images) when creating session while uploading files.
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
#### Response
2024-11-06 18:03:45 +08:00
Success:
```json
{
"code": 0,
"data": {
2024-12-13 10:25:52 +08:00
"agent_id": "b4a39922b76611efaa1a0242ac120006",
"dsl": {
"answer": [],
"components": {
"Answer:GreenReadersDrum": {
"downstream": [],
"obj": {
"component_name": "Answer",
"inputs": [],
"output": null,
"params": {}
},
"upstream": []
},
"begin": {
"downstream": [],
"obj": {
"component_name": "Begin",
"inputs": [],
"output": {},
"params": {}
},
"upstream": []
}
},
"embed_id": "",
"graph": {
"edges": [],
"nodes": [
{
"data": {
"label": "Begin",
"name": "begin"
},
"dragging": false,
"height": 44,
"id": "begin",
"position": {
"x": 53.25688640427177,
"y": 198.37155679786412
},
"positionAbsolute": {
"x": 53.25688640427177,
"y": 198.37155679786412
},
"selected": false,
"sourcePosition": "left",
"targetPosition": "right",
"type": "beginNode",
"width": 200
},
{
"data": {
"form": {},
"label": "Answer",
2024-12-17 16:03:37 +08:00
"name": "dialog_0"
2024-12-13 10:25:52 +08:00
},
"dragging": false,
"height": 44,
"id": "Answer:GreenReadersDrum",
"position": {
"x": 360.43473114516974,
"y": 207.29298425089348
},
"positionAbsolute": {
"x": 360.43473114516974,
"y": 207.29298425089348
},
"selected": false,
"sourcePosition": "right",
"targetPosition": "left",
"type": "logicNode",
"width": 200
}
]
},
"history": [],
"messages": [],
"path": [
[
"begin"
],
[]
],
"reference": []
},
"id": "2581031eb7a311efb5200242ac120005",
2024-11-06 18:03:45 +08:00
"message": [
{
2024-12-13 10:25:52 +08:00
"content": "Hi! I'm your smart assistant. What can I do for you?",
2024-11-06 18:03:45 +08:00
"role": "assistant"
}
],
"source": "agent",
2024-12-13 10:25:52 +08:00
"user_id": "69736c5e723611efb51b0242ac120007"
2024-11-06 18:03:45 +08:00
}
}
```
Failure:
```json
{
"code": 102,
"message": "Agent not found."
}
```
2024-11-14 18:44:37 +08:00
---
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
### Converse with agent
2024-11-06 18:03:45 +08:00
**POST** `/api/v1/agents/{agent_id}/completions`
2024-11-14 18:44:37 +08:00
Asks a specified agent a question to start an AI-powered conversation.
:::tip NOTE
- In streaming mode, not all responses include a reference, as this depends on the system's judgement.
- In streaming mode, the last message is an empty message:
2024-12-19 14:36:51 +08:00
```json
2024-11-14 18:44:37 +08:00
data:
{
"code": 0,
"data": true
}
```
:::
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
#### Request
2024-11-06 18:03:45 +08:00
- Method: POST
- URL: `/api/v1/agents/{agent_id}/completions`
- Headers:
- `'content-Type: application/json'`
- `'Authorization: Bearer <YOUR_API_KEY>'`
- Body:
- `"question"` : `string`
- `"stream"` : `boolean`
- `"session_id"` : `string`
2024-12-24 15:59:11 +08:00
- `"user_id"` : `string` (optional)
2024-12-13 10:25:52 +08:00
- other parameters: `string`
2024-12-18 19:01:05 +08:00
##### Request example
2024-12-20 17:34:16 +08:00
If the `begin` component doesn't have parameters, the following code will create a session.
```bash
2024-11-06 18:03:45 +08:00
curl --request POST \
--url http://{address}/api/v1/agents/{agent_id}/completions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--data-binary '
{
}'
```
2024-12-20 17:34:16 +08:00
If the `begin` component have parameters, the following code will create a session.
2024-12-13 10:25:52 +08:00
```bash
curl --request POST \
--url http://{address}/api/v1/agents/{agent_id}/completions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--data-binary '
{
2024-12-20 17:34:16 +08:00
"lang":"English",
"file":"How is the weather tomorrow?"
2024-12-13 10:25:52 +08:00
}'
```
2024-12-20 17:34:16 +08:00
The following code will execute the completion process
2024-12-13 10:25:52 +08:00
```bash
curl --request POST \
--url http://{address}/api/v1/agents/{agent_id}/completions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer < YOUR_API_KEY > ' \
--data-binary '
{
2024-12-20 17:34:16 +08:00
"question": "Hello",
"stream": true,
"session_id": "cb2f385cb86211efa36e0242ac120005"
2024-12-13 10:25:52 +08:00
}'
```
2024-11-06 18:03:45 +08:00
2024-12-18 19:01:05 +08:00
##### Request Parameters
2024-11-06 18:03:45 +08:00
2024-11-14 18:44:37 +08:00
- `agent_id` : (*Path parameter*), `string`
2024-12-19 18:19:56 +08:00
The ID of the associated agent.
2024-11-14 18:44:37 +08:00
- `"question"` : (*Body Parameter*), `string` , *Required*
2024-11-06 18:03:45 +08:00
The question to start an AI-powered conversation.
- `"stream"` : (*Body Parameter*), `boolean`
2024-11-14 18:44:37 +08:00
Indicates whether to output responses in a streaming way:
2024-11-22 11:11:06 +08:00
- `true` : Enable streaming (default).
- `false` : Disable streaming.
2024-11-06 18:03:45 +08:00
- `"session_id"` : (*Body Parameter*)
2024-11-14 18:44:37 +08:00
The ID of the session. If it is not provided, a new session will be generated.
2024-12-24 15:59:11 +08:00
- `"user_id"` : (*Body parameter*), `string`
The optional user-defined ID. Valid *only* when no `session_id` is provided.
2024-12-13 10:25:52 +08:00
- Other parameters: (*Body Parameter*)
The parameters in the begin component.
2024-12-18 19:01:05 +08:00
#### Response
2024-12-13 10:25:52 +08:00
success without `session_id` provided and with no parameters in the `begin` component:
2024-12-19 14:36:51 +08:00
```json
2024-12-13 10:25:52 +08:00
data:{
"code": 0,
"message": "",
"data": {
"answer": "Hi! I'm your smart assistant. What can I do for you?",
"reference": {},
"id": "31e6091d-88d4-441b-ac65-eae1c055be7b",
"session_id": "2987ad3eb85f11efb2a70242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": true
}
```
2024-12-20 17:34:16 +08:00
Success without `session_id` provided and with parameters in the `begin` component:
2024-11-06 18:03:45 +08:00
2024-12-19 14:36:51 +08:00
```json
2024-11-06 18:03:45 +08:00
data:{
"code": 0,
"message": "",
"data": {
2024-12-20 17:34:16 +08:00
"session_id": "eacb36a0bdff11ef97120242ac120006",
2024-11-06 18:03:45 +08:00
"answer": "",
"reference": [],
2024-12-20 17:34:16 +08:00
"param": [
{
"key": "lang",
"name": "Target Language",
"optional": false,
"type": "line",
"value": "English"
},
{
"key": "file",
"name": "Files",
"optional": false,
"type": "file",
"value": "How is the weather tomorrow?"
},
{
"key": "hhyt",
"name": "hhty",
"optional": true,
"type": "line"
}
]
2024-11-06 18:03:45 +08:00
}
}
2024-12-20 17:34:16 +08:00
data:
2024-11-06 18:03:45 +08:00
```
2024-12-13 10:25:52 +08:00
Success with parameters in the `begin` component:
2024-12-19 14:36:51 +08:00
```json
2024-12-13 10:25:52 +08:00
data:{
"code": 0,
"message": "",
"data": {
"answer": "How",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": {
"answer": "How is",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": {
"answer": "How is the",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": {
"answer": "How is the weather",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": {
"answer": "How is the weather tomorrow",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": {
"answer": "How is the weather tomorrow?",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": {
"answer": "How is the weather tomorrow?",
"reference": {},
"id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
"session_id": "4399c7d0b86311efac5b0242ac120005"
}
}
data:{
"code": 0,
"message": "",
"data": true
}
```
2024-11-06 18:03:45 +08:00
Failure:
```json
{
"code": 102,
"message": "`question` is required."
}
2024-11-14 18:44:37 +08:00
```
2024-12-04 16:23:22 +08:00
---
2024-12-18 19:01:05 +08:00
### List agent sessions
2024-12-04 16:23:22 +08:00
2024-12-24 15:59:11 +08:00
**GET** `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id}`
2024-12-04 16:23:22 +08:00
Lists sessions associated with a specified agent.
2024-12-18 19:01:05 +08:00
#### Request
2024-12-04 16:23:22 +08:00
- Method: GET
- URL: `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}`
- Headers:
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-12-18 19:01:05 +08:00
##### Request example
2024-12-04 16:23:22 +08:00
```bash
curl --request GET \
2024-12-24 15:59:11 +08:00
--url http://{address}/api/v1/agents/{agent_id}/sessions?page={page}& page_size={page_size}& orderby={orderby}& desc={desc}& id={session_id}& user_id={user_id} \
2024-12-04 16:23:22 +08:00
--header 'Authorization: Bearer < YOUR_API_KEY > '
```
2024-12-18 19:01:05 +08:00
##### Request Parameters
2024-12-04 16:23:22 +08:00
- `agent_id` : (*Path parameter*)
The ID of the associated agent.
- `page` : (*Filter parameter*), `integer`
Specifies the page on which the sessions will be displayed. Defaults to `1` .
- `page_size` : (*Filter parameter*), `integer`
The number of sessions on each page. Defaults to `30` .
- `orderby` : (*Filter parameter*), `string`
The field by which sessions should be sorted. Available options:
- `create_time` (default)
- `update_time`
- `desc` : (*Filter parameter*), `boolean`
Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true` .
- `id` : (*Filter parameter*), `string`
The ID of the agent session to retrieve.
2024-12-24 15:59:11 +08:00
- `user_id` : (*Filter parameter*), `string`
The optional user-defined ID passed in when creating session.
2024-12-18 19:01:05 +08:00
#### Response
2024-12-04 16:23:22 +08:00
Success:
```json
{
"code": 0,
2024-12-11 12:38:57 +08:00
"data": {
"agent_id": "e9e2b9c2b2f911ef801d0242ac120006",
"dsl": {
"answer": [],
"components": {
"Answer:OrangeTermsBurn": {
"downstream": [],
"obj": {
"component_name": "Answer",
"params": {}
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"upstream": []
},
"Generate:SocialYearsRemain": {
"downstream": [],
"obj": {
"component_name": "Generate",
"params": {
"cite": true,
"frequency_penalty": 0.7,
"llm_id": "gpt-4o___OpenAI-API@OpenAI -API-Compatible",
"max_tokens": 256,
"message_history_window_size": 12,
"parameters": [],
"presence_penalty": 0.4,
"prompt": "Please summarize the following paragraph. Pay attention to the numbers and do not make things up. The paragraph is as follows:\n{input}\nThis is what you need to summarize.",
"temperature": 0.1,
"top_p": 0.3
}
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"upstream": []
},
"begin": {
"downstream": [],
"obj": {
"component_name": "Begin",
"params": {}
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"upstream": []
}
},
"graph": {
"edges": [],
"nodes": [
{
"data": {
"label": "Begin",
"name": "begin"
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"height": 44,
"id": "begin",
"position": {
"x": 50,
"y": 200
},
"sourcePosition": "left",
"targetPosition": "right",
"type": "beginNode",
"width": 200
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
{
"data": {
"form": {
2024-12-04 16:23:22 +08:00
"cite": true,
2024-12-11 12:38:57 +08:00
"frequencyPenaltyEnabled": true,
2024-12-04 16:23:22 +08:00
"frequency_penalty": 0.7,
"llm_id": "gpt-4o___OpenAI-API@OpenAI -API-Compatible",
2024-12-11 12:38:57 +08:00
"maxTokensEnabled": true,
2024-12-04 16:23:22 +08:00
"max_tokens": 256,
"message_history_window_size": 12,
2024-12-11 12:38:57 +08:00
"parameters": [],
"presencePenaltyEnabled": true,
2024-12-04 16:23:22 +08:00
"presence_penalty": 0.4,
2024-12-11 12:38:57 +08:00
"prompt": "Please summarize the following paragraph. Pay attention to the numbers and do not make things up. The paragraph is as follows:\n{input}\nThis is what you need to summarize.",
2024-12-04 16:23:22 +08:00
"temperature": 0.1,
2024-12-11 12:38:57 +08:00
"temperatureEnabled": true,
"topPEnabled": true,
2024-12-04 16:23:22 +08:00
"top_p": 0.3
},
2024-12-11 12:38:57 +08:00
"label": "Generate",
"name": "Generate Answer_0"
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"dragging": false,
"height": 105,
"id": "Generate:SocialYearsRemain",
"position": {
"x": 561.3457829707513,
"y": 178.7211182312641
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"positionAbsolute": {
"x": 561.3457829707513,
"y": 178.7211182312641
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"selected": true,
"sourcePosition": "right",
"targetPosition": "left",
"type": "generateNode",
"width": 200
},
{
"data": {
"form": {},
"label": "Answer",
"name": "Dialogue_0"
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"height": 44,
"id": "Answer:OrangeTermsBurn",
"position": {
"x": 317.2368194777658,
"y": 218.30635555445093
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"sourcePosition": "right",
"targetPosition": "left",
"type": "logicNode",
"width": 200
2024-12-04 16:23:22 +08:00
}
2024-12-11 12:38:57 +08:00
]
2024-12-04 16:23:22 +08:00
},
2024-12-11 12:38:57 +08:00
"history": [],
"messages": [],
"path": [],
"reference": []
},
"id": "792dde22b2fa11ef97550242ac120006",
"message": [
{
"content": "Hi! I'm your smart assistant. What can I do for you?",
"role": "assistant"
}
],
"source": "agent",
"user_id": ""
}
2024-12-04 16:23:22 +08:00
}
```
Failure:
```json
{
"code": 102,
"message": "You don't own the agent ccd2f856b12311ef94ca0242ac1200052."
}
```
2024-12-18 19:01:05 +08:00
2024-12-04 16:23:22 +08:00
---
2024-12-18 19:01:05 +08:00
2024-12-19 14:36:51 +08:00
## AGENT MANAGEMENT
---
2024-12-18 19:01:05 +08:00
### List agents
2024-12-04 16:23:22 +08:00
**GET** `/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id}`
Lists agents.
2024-12-18 19:01:05 +08:00
#### Request
2024-12-04 16:23:22 +08:00
- Method: GET
- URL: `/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id}`
- Headers:
- `'Authorization: Bearer <YOUR_API_KEY>'`
2024-12-18 19:01:05 +08:00
##### Request example
2024-12-04 16:23:22 +08:00
```bash
curl --request GET \
--url http://{address}/api/v1/agents?page={page}& page_size={page_size}& orderby={orderby}& desc={desc}& name={agent_name}& id={agent_id} \
--header 'Authorization: Bearer < YOUR_API_KEY > '
```
2024-12-18 19:01:05 +08:00
##### Request parameters
2024-12-04 16:23:22 +08:00
- `page` : (*Filter parameter*), `integer`
Specifies the page on which the agents will be displayed. Defaults to `1` .
- `page_size` : (*Filter parameter*), `integer`
The number of agents on each page. Defaults to `30` .
- `orderby` : (*Filter parameter*), `string`
The attribute by which the results are sorted. Available options:
- `create_time` (default)
- `update_time`
- `desc` : (*Filter parameter*), `boolean`
Indicates whether the retrieved agents should be sorted in descending order. Defaults to `true` .
- `id` : (*Filter parameter*), `string`
The ID of the agent to retrieve.
- `name` : (*Filter parameter*), `string`
The name of the agent to retrieve.
2024-12-18 19:01:05 +08:00
#### Response
2024-12-04 16:23:22 +08:00
Success:
```json
{
"code": 0,
"data": [
{
"avatar": null,
"canvas_type": null,
2024-12-11 12:38:57 +08:00
"create_date": "Thu, 05 Dec 2024 19:10:36 GMT",
"create_time": 1733397036424,
2024-12-04 16:23:22 +08:00
"description": null,
"dsl": {
"answer": [],
"components": {
"begin": {
2024-12-11 12:38:57 +08:00
"downstream": [],
2024-12-04 16:23:22 +08:00
"obj": {
"component_name": "Begin",
2024-12-11 12:38:57 +08:00
"params": {}
2024-12-04 16:23:22 +08:00
},
"upstream": []
}
},
"graph": {
2024-12-11 12:38:57 +08:00
"edges": [],
2024-12-04 16:23:22 +08:00
"nodes": [
{
"data": {
"label": "Begin",
"name": "begin"
},
"height": 44,
"id": "begin",
"position": {
"x": 50,
"y": 200
},
"sourcePosition": "left",
"targetPosition": "right",
"type": "beginNode",
"width": 200
}
]
},
2024-12-11 12:38:57 +08:00
"history": [],
"messages": [],
"path": [],
2024-12-04 16:23:22 +08:00
"reference": []
},
2024-12-11 12:38:57 +08:00
"id": "8d9ca0e2b2f911ef9ca20242ac120006",
"title": "123465",
"update_date": "Thu, 05 Dec 2024 19:10:56 GMT",
"update_time": 1733397056801,
2024-12-04 16:23:22 +08:00
"user_id": "69736c5e723611efb51b0242ac120007"
}
]
}
```
Failure:
```json
{
"code": 102,
"message": "The agent doesn't exist."
}
2024-12-18 19:01:05 +08:00
```
---