创建知识库
更新时间:2025-08-19
POST
https://qianfan.baidubce.com/v2/knowledgeBase?Action=CreateKnowledgeBase
为当前用户创建知识库
权限说明
调用本API,需使用API Key鉴权方式。Authorization的值为Bearer <API Key>。获取API Key流程,请查看授权。
请求参数
Headers 参数
除公共头域外,无其它特殊头域
Body 参数
name
string
知识库名称
必选
config
object {2}
知识库配置
必选
显示子属性
隐藏子属性
index
object {5}
知识库托管配置
必选
显示子属性
隐藏子属性
type
string
知识库托管资源选择
可选值:
public:AppBuilder共享资源
bes:百度 Elasticsearch
vdb:百度向量数据库VectorDB
必选
location
string
托管资源的区域
可选值:
bj:北京
bd:保定
sz:苏州
gz:广州
备注:type=bes 和 vdb 时填写需填写
可选
password
string
密码/API密钥
请在bes、vdb控制台中查看。
备注:type=bes 和 vdb 时填写需填写
可选
username
string
用户名/账号
请在bes、vdb控制台中查看。
备注:type=bes 和 vdb 时填写需填写
可选
clusterId
string
集群/实例 ID
请在bes、vdb控制台中查看。
备注:type=bes 和 vdb 时填写需填写
可选
catalogue
object {1}
知识库目录配置
可选
显示子属性
隐藏子属性
pathPrefix
string
知识库创建到指定目录下,最大层级为5, 默认为根目录下
可选
description
string
知识库描述
可选
请求结构
POST /v2/knowledgeBase?Action=CreateKnowledgeBase HTTP/1.1
HOST: qianfan.baidubce.com
Authorization: Bearer <API Key>
Content-Type: application/json
{
"name": "knowledge_base_name",
"description": "knowledge_base description",
"config": {
"index": {
"type": "bes",
"username": "####",
"password": "####",
"location":"bj",
"clusterId":"985231####0126080"
},
"catalogue":{
"pathPrefix": "/全部群组/##/##"
}
}
}
示例代码
curl
curl --location 'https://qianfan.baidubce.com/v2/knowledgeBase?Action=CreateKnowledgeBase' \
--header 'Authorization: Bearer <API Key>' \
--header 'Content-Type: application/json' \
--data '{
"name": "openapi_knowledgeBase",
"config": {
"index": {
"type": "bes",
"username": "####",
"password": "####",
"location":"bj",
"clusterId":"985231####0126080"
},
"catalogue":{
"pathPrefix": "/全部群组/##/##"
}
}
}'
返回响应
Headers 参数
除公共头域外,无其它特殊头域
返回参数
id
string
知识库id
必选
name
string
知识库名称
必选
config
object {1}
知识库配置
必选
显示子属性
隐藏子属性
index
object {1}
知识库托管配置
必选
显示子属性
隐藏子属性
type
string
知识库托管资源
可选值:
public:AppBuilder共享资源
bes:百度 Elasticsearch
vdb:百度向量数据库VectorDB
必选
requestId
string
requestId
必选
description
string
知识库描述
必选
JSON
HTTP/1.1 200 OK
{
"requestId": "b970f03e-0761-489d-beb7-59fd771de589",
"id": "81f864e4-ce78-4def-acfd-5cef72e1ba23",
"name": "openapi_knowledgeBase",
"description": "",
"config": {
"index": {
"type": "bes"
}
}
}
JSON
HTTP/1.1 400
{
"code": "InvalidRequestArgumentError",
"message": "index type invalid",
"requestId": "20123341-d278-4a43-b04c-db5bc68c4769"
}