创建智能体知识库¶
创建智能体可引用的知识库元数据,不执行文件解析、索引或检索。
要在资源中心创建可添加文件和数据表的知识库,使用创建空知识库。
POST https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/knowledge-bases
调用前准备¶
准备可访问目标工作区的个人访问令牌和目标工作区 ID。
请求体¶
curl -X POST "https://api.moi.matrixorigin.cn/v5/workspaces/$WORKSPACE_ID/knowledge-bases" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"name": "产品文档",
"description": "已审核的产品资料",
"status": "active",
"source_type": "catalog_resource",
"catalog_asset_refs": [
{
"type": "catalog",
"id": "<CATALOG_ID>",
"role": "source"
}
],
"visibility": "workspace",
"index_status": "ready",
"tags": ["产品", "文档"]
}'
catalog_asset_refs[].uri 不能包含凭据或敏感查询参数。
catalog_asset_refs[].config 和 metadata 不能包含密钥或提供商的运行、会话引用。
工作区取自请求路径,当前用户取自调用身份,无需在请求体中传入。
路径参数
字段 |
类型 |
是否必填 |
说明 |
|---|---|---|---|
|
string |
是 |
当前工作区 ID,必须与 X-Workspace-ID 一致。 |
请求体
创建时 labels、annotations 和资产引用中的 config 必须是对象,根值 null 会被拒绝。标签、注解的单个值允许字符串或 null。名称上限为 128 个 UTF-8 字节,说明和最近索引错误上限各为 4096 个 UTF-8 字节。
创建时省略 metadata 或设置为 null,会生成默认的 runtime_tool_refs。提供元数据但没有该键时,也会补充 13 个系统工具引用。显式设置为空数组或 null 则保留该值。不能引用已停用的 compute_result_table 工具。
字段 |
类型 |
是否必填 |
说明 |
|---|---|---|---|
|
string |
是 |
知识库名称。去除首尾空白后须非空,UTF-8 编码不能超过 128 字节。 |
|
string |
否 |
知识库 ID。未提供时由服务端生成。 |
|
string |
否 |
说明,去除首尾空白后最多 4096 个 UTF-8 字节。 |
|
string |
否 |
状态:draft、active、disabled 或 archived。未提供时为 draft。 |
|
string |
否 |
来源类型:manual、catalog_resource、file_collection、external_drive 或 connector_export。未提供时为 manual。 |
|
object(对象数组) |
否 |
关联的 Catalog 资产。成员说明见关联资产字段。 |
|
string |
否 |
默认检索配置引用。 |
|
string(字符串数组) |
否 |
标签。 |
|
string |
否 |
资源所有者 ID。未提供时使用当前用户 ID。 |
|
string |
否 |
可见范围:private 或 workspace。未提供时为 private。 |
|
string |
否 |
索引状态:empty、indexing、ready 或 failed。未提供时为 empty。 |
|
string |
否 |
最近索引时间,采用 RFC 3339 格式。 |
|
string |
否 |
最近索引错误信息,去除首尾空白后最多 4096 个 UTF-8 字节。 |
|
object |
否 |
字符串键值标签。 |
|
object |
否 |
字符串键值注释。 |
|
object |
否 |
扩展元数据。不能包含密钥、提供商运行信息或会话引用。 |
|
string |
是 |
资产类型。 |
|
string |
条件必填 |
资产 ID。未填写 uri 时必填。 |
|
string |
条件必填 |
资产 URI。未填写 id 时必填。 |
|
string |
否 |
资产版本。 |
|
string |
否 |
资产关联角色。 |
|
object |
否 |
资产配置。 |
名称可以包含 /,例如 产品文档/安装指南。/ 作为名称内容保存。查询和更新知识库元数据时,使用返回的 data.id 作为 knowledge_base_id。关联的 Catalog 资产由 catalog_asset_refs 指定。
catalog_asset_refs 中的每一项描述一个关联资产。type 为必填字段,id 和 uri 至少填写一个。
成功响应¶
{
"code": 0,
"data": {
"id": "kb_01",
"workspace_id": "ws_01",
"name": "产品文档",
"description": "已审核的产品资料",
"status": "active",
"source_type": "catalog_resource",
"catalog_asset_refs": [
{
"type": "catalog",
"id": "cat_01",
"role": "source"
}
],
"tags": [
"产品",
"文档"
],
"owner_user_id": "user_01",
"visibility": "workspace",
"index_status": "ready",
"version": 1,
"created_by": "user_01",
"updated_by": "user_01",
"created_at": "2026-08-18T01:00:00Z",
"updated_at": "2026-08-18T01:00:00Z",
"metadata": {
"runtime_tool_refs": [
{
"id": "find_rag_files",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "search_rag_chunks",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "search_visual_image",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "read_parsed_markdown",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "search_parsed_markdown",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "describe_schema",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "query_sql",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "upsert_knowledge_table",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "select_final_sources",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "read_artifact",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "read_artifact_page",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "write_file",
"workspace_id": "system",
"kind": "tool"
},
{
"id": "read_file",
"workspace_id": "system",
"kind": "tool"
}
]
}
}
}
字段 |
类型 |
说明 |
|---|---|---|
|
integer |
成功代码。 |
|
object |
本次操作返回的数据。 |
|
string |
知识库 ID。 |
|
string |
所属工作区 ID。 |
|
string |
知识库名称和说明。 |
|
string |
知识库名称和说明。 |
|
string |
知识库状态。取值为 |
|
string |
知识库来源类型。取值为 |
|
object(对象数组) |
关联的 Catalog 资产。成员说明见关联资产字段。 |
|
string |
类型。 |
|
string |
当前对象的 ID。 |
|
string |
资源 URI。 |
|
string |
当前资源版本。 |
|
string |
关联角色。 |
|
object |
配置对象对象允许扩展键。 |
|
string |
默认检索配置引用。 |
|
string(字符串数组) |
标签。 |
|
string |
所有者用户 ID。 |
|
string |
可见范围。取值为 |
|
string |
索引状态。取值为 |
|
string 或 null |
最近索引时间和错误信息。 |
|
string |
最近索引时间和错误信息。 |
|
integer |
资源版本,创建时为 1。 |
|
object |
字符串键值标签和注释对象允许扩展键。 |
|
object |
字符串键值标签和注释对象允许扩展键。 |
|
object |
扩展元数据对象允许扩展键。 |
|
string |
创建者和最近更新者 ID。 |
|
string |
创建者和最近更新者 ID。 |
|
string |
创建和最近更新时间,采用 RFC 3339 格式。 |
|
string |
创建和最近更新时间,采用 RFC 3339 格式。 |
错误响应¶
{
"code": 2,
"message": "invalid knowledge base metadata"
}
常见 HTTP 错误¶
HTTP 状态码 |
错误代码 |
常见原因 |
建议操作 |
|---|---|---|---|
400 |
|
请求字段、工作区或操作前置条件无效。 |
修正参数后再提交。 |
401 |
|
认证凭据缺失或无效。 |
检查凭据类型、有效期及认证头。 |
403 |
|
当前身份或有效角色无执行该操作的权限。 |
使用有权限的身份,或联系管理员授权。 |
404 |
|
目标对象或所需引用未找到。 |
核对对象标识、所属工作区和当前状态。 |
409 |
|
资源状态、请求内容或并发条件冲突。 |
重新读取当前状态和版本,按实际结果处理。 |
503 |
|
业务、运行时或授权依赖暂不可用。 |
恢复依赖后先核对已有结果,不自动重复写入。 |