创建知识库
更新时间:2025-02-18
接口描述
为当前用户创建知识库
在线调试
百度智能云千帆提供了 API在线调试平台-示例代码 ,用于帮助开发者调试接口,平台集成快速检索、查看开发文档、查看在线调用的请求内容和返回结果、复制和下载示例代码等功能,支持Python、Java、PHP、C#、Go、Node.js、C++ 7种主流语言示例代码自动生成。
权限说明
Authorization需要填写密钥
接口定义
Path | /v2/knowledgeBase?Action=CreateKnowledgeBase |
---|---|
Method | POST |
Content-Type | application/json |
Authorization | 请求签名(Bearer <AppBuilder API Key>) |
请求结构
Plain Text
1POST /v2/knowledgeBase?Action=CreateKnowledgeBase HTTP/1.1
2HOST: qianfan.baidubce.com
3Authorization: Bearer <AppBuilder API Key>
4Content-Type: application/json
5
6{
7 "name": "knowledge_base_name",
8 "description": "knowledge_base description",
9 "config": {
10 "index": {
11 "type": "bes",
12 "username": "####",
13 "password": "####",
14 "location":"bj",
15 "clusterId":"985231####0126080"
16 },
17 "catalogue":{
18 "pathPrefix": "/全部群组/##/##"
19 }
20 }
21}
请求头域
除公共头域外,无其它特殊头域。
请求参数
字段 | 类型 | 是否必须 | 说明 |
---|---|---|---|
name | string | 是 | 知识库名称 |
description | string | 否 | 知识库描述 |
config | dict | 是 | 知识库配置 |
config \ index | dict | 是 | 知识库托管配置 |
config \ index \ type | string | 是 | 知识库托管资源选择 可选值: public:AppBuilder共享资源 bes:百度 Elasticsearch vdb:百度向量数据库VectorDB |
config \ index \ clusterId | string | type=bes 和 vdb 时填写 | 集群/实例 ID 请在bes、vdb控制台中查看。 |
config \ index \ username | string | type=bes 和 vdb 时填写 | 用户名/账号 请在bes、vdb控制台中查看。 |
config \ index \ password | string | type=bes 和 vdb 时填写 | 密码/API密钥 请在bes、vdb控制台中查看。 |
config \ index \ location | string | type=bes 和 vdb 时填写 | 托管资源的区域 可选值: bj:北京 bd:保定 sz:苏州 gz:广州 |
config \ catalogue | dict | 否 | 知识库目录配置 |
config \ catalogue \ pathPrefix | string | 否 | 知识库创建到指定目录下,最大层级为5, 默认为根目录下 |
响应头域
除公共头域外,无其它特殊头域。
响应参数
字段 | 类型 | 必然存在 | 说明 |
---|---|---|---|
requestId | string | 是 | requestId |
id | string | 是 | 知识库id |
name | string | 是 | 知识库名称 |
description | string | 是 | 知识库描述 |
config \ index | dict | 是 | 知识库托管配置 |
config \ index \ type | string | 是 | 知识库托管资源 可选值: public:AppBuilder共享资源 bes:百度 Elasticsearch vdb:百度向量数据库VectorDB |
请求curl 示例
Plain Text
1curl --location 'https://qianfan.baidubce.com/v2/knowledgeBase?Action=CreateKnowledgeBase' \
2--header 'Authorization: Bearer <AppBuilder API Key>' \
3--header 'Content-Type: application/json' \
4--data '{
5 "name": "openapi_knowledgeBase",
6 "config": {
7 "index": {
8 "type": "bes",
9 "username": "####",
10 "password": "####",
11 "location":"bj",
12 "clusterId":"985231####0126080"
13 },
14 "catalogue":{
15 "pathPrefix": "/全部群组/##/##"
16 }
17 }
18}'
正确响应示例
Plain Text
1HTTP/1.1 200 OK
2{
3 "requestId": "b970f03e-0761-489d-beb7-59fd771de589",
4 "id": "81f864e4-ce78-4def-acfd-5cef72e1ba23",
5 "name": "openapi_knowledgeBase",
6 "description": "",
7 "config": {
8 "index": {
9 "type": "bes"
10 }
11 }
12}
错误响应示例
Plain Text
1HTTP/1.1 400
2{
3 "code": "InvalidRequestArgumentError",
4 "message": "index type invalid",
5 "requestId": "20123341-d278-4a43-b04c-db5bc68c4769"
6}