知识库管理
更新时间:2026-04-10
创建知识库
接口描述
创建一个新的知识库,并且可以在创建的同时为知识库上传文档,接口会返回知识库的唯一ID。
- 目前仅支持上传纯文本类型文档,且文档大小应小于100k。
请求语法
JSON
1POST /api/v{version}/rag/knowledgeBase HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求体
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| name | String | 是 | 知识库名称,长度不能超过60 |
| description | String | 是 | 知识库描述,长度不能超过256 |
| config | Object | 否 | 知识库配置项 |
| +index | Object | 否 | 索引配置 |
| ++chunkSize | Integer | 否 | 切片大小,默认值500 |
| ++chunkOverlap | Integer | 否 | 切片重叠大小,默认值50 |
| documents | List | 否 | 文档列表(可选,创建同时导入文档) |
| +name | String | 是 | 文档名称,长度不能超过128 |
| +contentType | String | 否 | 文档内容类型,暂时只支持取值 text |
| +sourceType | String | 是 | 文档来源类型,支持取值 string、fileUrl、fileData |
| +content | String | 否 | 字符串内容(sourceType=string时有意义且必须存在) |
| +fileUrl | String | 否 | 文件URL(sourceType=fileUrl时有意义且必须存在) |
| +fileData | byte[] | 否 | 文件二进制数据(sourceType=fileData时有意义且必须存在) |
请求示例
JSON
1POST /api/v1/rag/knowledgeBase HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
6
7{
8 "name": "中国历史",
9 "description": "中国历史简介,汉朝历史,唐朝历史",
10 "config": {
11 "index": {
12 "chunkSize": 500,
13 "chunkOverlap": 50
14 }
15 },
16 "documents": [
17 {
18 "name": "中国历史简介",
19 "contentType": "text",
20 "sourceType": "string",
21 "content": "xxx"
22 },
23 {
24 "name": "汉朝历史",
25 "contentType": "text",
26 "sourceType": "string",
27 "content": "xxx"
28 },
29 {
30 "name": "唐朝历史",
31 "contentType": "text",
32 "sourceType": "string",
33 "content": "xx"
34 }
35 ]
36}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| kbId | String | 知识库ID |
| name | String | 知识库名称 |
| description | String | 知识库描述 |
| config | Object | 知识库配置项 |
| +index | Object | 索引配置 |
| ++chunkSize | Integer | 切片大小 |
| ++chunkOverlap | Integer | 切片重叠大小 |
| status | String | 知识库状态,取值及说明见查询知识库详情接口 |
| docIds | List |
文档ID列表 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "kbId": "kbxxx",
10 "name": "中国历史",
11 "description": "中国历史简介,汉朝历史,唐朝历史",
12 "status": "PROCESSING",
13 "docIds": [
14 "docxxx",
15 "docxxx",
16 "docxxx"
17 ],
18 "config": {
19 "index": {
20 "chunkSize": 500,
21 "chunkOverlap": 50
22 }
23 }
24}
查询知识库列表
接口描述
查询当前账户下的知识库列表,支持分页查询。
请求语法
JSON
1GET /api/v{version}/v1/rag/knowledgeBase/list?pageNum={pageNum}&pageSize={pageSize} HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| pageNum | Integer | 否 | 页码,默认值为1 |
| pageSize | Integer | 否 | 每页数量,默认值为10 |
请求体
N/A
请求示例
JSON
1GET /api/v1/rag/knowledgeBase/list?pageNum=1&pageSize=10 HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| list | List | 知识库列表 |
| +kbId | String | 知识库ID |
| +name | String | 知识库名称 |
| +description | String | 知识库描述 |
| +status | String | 知识库状态,取值及说明见查询知识库详情接口 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "list": [
10 {
11 "kbId": "kbxxx",
12 "name": "各国历史",
13 "description": "中国历史,美国历史,欧洲历史",
14 "status": "READY"
15 },
16 {
17 "kbId": "kbxxx",
18 "name": "中国历史",
19 "description": "中国历史简介,汉朝历史,唐朝历史",
20 "status": "READY"
21 }
22 ]
23}
查询知识库详情
接口描述
根据知识库ID查询知识库详细信息。
请求语法
JSON
1GET /api/v{version}/rag/knowledgeBase/{kbId} HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
请求体
N/A
请求示例
JSON
1GET /api/v1/rag/knowledgeBase/kbxxx HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| kbId | String | 知识库ID |
| name | String | 知识库名称 |
| description | String | 知识库描述 |
| status | String | 知识库状态,取值:PROCESSING:知识库中有文件在处理中;READY:可用,知识库中文档全部成功处理完成;ERROR:异常,知识库异常、或者知识库中存在文档发生异常。 |
| config | Object | 知识库配置 |
| +index | Object | 索引配置 |
| ++chunkSize | Integer | 切片大小 |
| ++chunkOverlap | Integer | 切片重叠大小 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "kbId": "kbxxx",
10 "name": "中国历史",
11 "description": "中国历史简介,汉朝历史,唐朝历史",
12 "status": "READY",
13 "config": {
14 "index": {
15 "chunkSize": 500,
16 "chunkOverlap": 50
17 }
18 }
19}
删除知识库
接口描述
删除指定的知识库及其所有文档。
请求语法
JSON
1DELETE /api/v{version}/rag/knowledgeBase/{kbId} HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
请求体
N/A
请求示例
JSON
1DELETE /api/v1/rag/knowledgeBase/kbxxx HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
N/A
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
上传文档到知识库
接口描述
上传一个或多个文档到指定的知识库。
请求语法
JSON
1POST /api/v{version}/rag/knowledgeBase/{kbId}/document HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
请求体
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| documents | List | 是 | 文档列表 |
| +name | String | 是 | 文档名称,长度不能超过128 |
| +contentType | String | 否 | 文档内容类型,暂时只支持取值text |
| +sourceType | String | 是 | 文档来源类型,支持取值string、fileUrl、fileData |
| +content | String | 否 | 字符串内容(sourceType=string时有意义且必须存在) |
| +fileUrl | String | 否 | 文件URL(sourceType=fileUrl时有意义且必须存在) |
| +fileData | byte[] | 否 | 文件二进制数据(sourceType=fileData时有意义且必须存在) |
请求示例
JSON
1POST /api/v1/rag/knowledgeBase/kbxxx/document HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
6
7{
8 "documents": [
9 {
10 "name": "中国历史介绍",
11 "contentType": "text",
12 "sourceType": "string",
13 "content": "中国拥有约五千年的文明历史..."
14 }
15 ]
16}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| kbId | String | 知识库ID |
| addedCount | Integer | 新增文档数量 |
| docIds | List |
文档ID列表 |
| status | String | 知识库状态,取值及说明见查询知识库详情接口 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "kbId": "kbxxx",
10 "addedCount": 1,
11 "docIds": [
12 "docxxx"
13 ],
14 "status": "PROCESSING"
15}
查询知识库文档列表
接口描述
查询指定知识库下的文档列表。
请求语法
JSON
1GET /api/v{version}/rag/knowledgeBase/{kbId}/document/list HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
请求体
N/A
请求示例
JSON
1GET /api/v1/rag/knowledgeBase/kbxxx/document/list HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| kbId | String | 知识库ID |
| list | List | 文档列表 |
| +docId | String | 文档ID |
| +name | String | 文档名称 |
| +contentType | String | 文档内容类型,取值及说明见上传文档到知识库接口 |
| +sourceType | String | 文档来源类型,取值及说明见上传文档到知识库接口 |
| +status | String | 文档状态,取值及说明见查询知识库文档详情接口 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "kbId": "kbxxx",
10 "list": [
11 {
12 "docId": "docxxx",
13 "name": "中国历史简介",
14 "contentType": "text",
15 "sourceType": "string",
16 "status": "READY"
17 },
18 {
19 "docId": "docxxx",
20 "name": "汉朝历史",
21 "contentType": "text",
22 "sourceType": "string",
23 "status": "READY"
24 },
25 {
26 "docId": "docxxx",
27 "name": "唐朝历史",
28 "contentType": "text",
29 "sourceType": "string",
30 "status": "READY"
31 }
32 ]
33}
查询知识库文档详情
接口描述
查询知识库中指定文档的详细信息。
请求语法
JSON
1GET /api/v{version}/rag/knowledgeBase/{kbId}/document/{docId} HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
| docId | String | 是 | 文档ID |
请求体
N/A
请求示例
JSON
1GET /api/v1/rag/knowledgeBase/kbxxx/document/docxxx HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| docId | String | 文档ID |
| name | String | 文档名称 |
| contentType | String | 文档类型,取值及说明见上传文档到知识库接口 |
| sourceType | String | 文档来源,取值及说明见上传文档到知识库接口 |
| status | String | 文档状态,取值:PROCESSING:文档处理中;READY:可用,文档成功处理完成;ERROR:异常,文档处理发生异常。 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "docId": "docxxx",
10 "name": "中国历史简介",
11 "contentType": "text",
12 "sourceType": "string",
13 "status": "READY"
14}
删除文档
接口描述
删除知识库中的指定文档。
请求语法
JSON
1DELETE /api/v{version}/rag/knowledgeBase/{kbId}/document/{docId} HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
| docId | String | 是 | 文档ID |
请求体
N/A
请求示例
JSON
1DELETE /api/v1/rag/knowledgeBase/kbxxx/document/docxxx HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| kbId | String | 知识库 ID |
| deletedCount | Integer | 删除成功的文档数目 |
| docIds | List |
删除成功的文档ID列表 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "kbId": "kbxxx",
10 "deletedCount": 1,
11 "docIds": [
12 "docxxx"
13 ]
14}
批量删除文档
接口描述
批量删除知识库下的多个文档。
请求语法
JSON
1DELETE /api/v{version}/rag/knowledgeBase/{kbId}/document/batch?docIds={docIds} HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: <bce-authorization-string>
请求头域
除公共头域外,无其它特殊头域。
请求路径参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| kbId | String | 是 | 知识库ID |
请求参数
| 参数名 | 参数类型 | 必要性 | 参数描述 |
|---|---|---|---|
| docIds | List |
是 | 文档ID列表 |
请求示例
JSON
1DELETE /api/v1/rag/knowledgeBase/kbxxx/document/batch?docIds=docxxx,docxxx HTTP/1.1
2host: rtc-aiagent.baidubce.com
3content-type: application/json
4authorization: {bce-authorization-string}
5x-bce-request-id: {bce-request-id}
响应头域
除公共头域外,无其它特殊头域。
响应体
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
| kbId | String | 知识库 ID |
| deletedCount | Integer | 删除成功的文档数目 |
| docIds | List |
删除成功的文档ID列表 |
响应示例
JSON
1HTTP/1.1 200 OK
2x-bce-request-id: b06a9214-04d6-4a08-9f5d-966b04604cfb
3date: Mon, 05 Sep 2022 03:25:43 GMT
4transfer-encoding: chunked
5content-type: application/json;charset=UTF-8
6cache-control: no-cache
7
8{
9 "kbId": "kbxxx",
10 "deletedCount": 2,
11 "docIds": [
12 "docxxx",
13 "docxxx"
14 ]
15}
评价此篇文章
