添加表格类文档
添加表格类文档
批量添加上传表格类型的文档,并依次执行分块/切片、嵌入/向量化及储存,获得新的文档 ID。
注意:
可通过embedding_model_version_id指定嵌入模型;不传时使用系统默认的嵌入模型。
仅返回上传结果,不返回最终的嵌入结果。您可以通过“查询文档状态”API 获取最终结果。
请求方式
POST
调用地址
https://api-${endpoint}.gptbots.ai/v1/bot/doc/spreadsheet/add
调用验证
详情参见 API 概述的鉴权方式说明。
请求
请求示例
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/bot/doc/spreadsheet/add' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"knowledge_base_id": "67457fea6f658672d6482542",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"chunk_token": 700,
"header_row": 5,
"files": [
{
"file_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_base64": "SGVsbG8sIEJhc2U2NCBFbmNvZGluZyE=",
"source_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_name": "spreadsheet_1.xlsx"
}
]
}'
curl -X POST 'https://api-${endpoint}.gptbots.ai/v1/bot/doc/spreadsheet/add' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"knowledge_base_id": "67457fea6f658672d6482542",
"embedding_model_version_id": "6620f06262390a0be1411c5d",
"chunk_token": 700,
"header_row": 5,
"files": [
{
"file_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_base64": "SGVsbG8sIEJhc2U2NCBFbmNvZGluZyE=",
"source_url": "https://www.gptbots.ai/doc/spreadsheet_1.xlsx",
"file_name": "spreadsheet_1.xlsx"
}
]
}'
此代码块在浮窗中显示
请求头
| 字段 | 类型 | 描述 |
|---|---|---|
| Authorization | Bearer ${API Key} | 使用 Authorization: Bearer ${API Key}进行调用验证,请在 API 密钥页面获取密钥作为 API Key。 |
| Content-Type | application/json | 数据类型,取值为 application/json 。 |
请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| knowledge_base_id | String | 否 | 文档添加的目标知识库。若不填写,则默认添加至“Default”知识库。 |
| files | Array<Object> | 是 | 添加的文档列表。最多支持同时添加 20 个文档。 |
| file_url | String | 否 | 添加的文档的 URL。 文档支持的格式:csv/xls/xlsx。每个文档最大 10MB。 注:URL 和 base64 二选一。当同时入参时,优先使用 base64。 |
| file_base64 | String | 否 | 添加的文档的 base64。 文档支持的格式:csv/xls/xlsx。每个文档最大 10MB。 注:URL 和 base64 二选一。当同时入参时,优先使用 base64。 |
| file_name | String | 是 | 添加的文档的名称。1-200 字符。 |
| source_url | String | 否 | 添加的文档的来源 URL。必须符合 URL 格式规范。 |
| embedding_model_version_id | String | 否 | 用于向量化本批文档的嵌入模型版本 ID。不传时使用系统默认的嵌入模型。取值为获取模型列表 API 返回的 EMBEDDING 分组下的 modelId。 |
| chunk_token | Integer | 否 | 分块时,单个知识块的最大 Token 数。默认值为 600。填写范围 1-1000。 |
| header_row | Integer | 否 | 作为表头的最大行数。表格类文档以“表头+数据行”为单位进行分块。默认值为 1。填写范围 1-5。 |
响应
响应示例
{
"doc": [
{
"doc_id": "xxxxxx",
"doc_name": "test_1.csv"
},
{
"doc_id": "xxxxxx",
"doc_name": "test_2.xlsx"
}
],
"failed": [
"file_1",
"file_2"
]
}
{
"doc": [
{
"doc_id": "xxxxxx",
"doc_name": "test_1.csv"
},
{
"doc_id": "xxxxxx",
"doc_name": "test_2.xlsx"
}
],
"failed": [
"file_1",
"file_2"
]
}
此代码块在浮窗中显示
成功响应
| 字段名 | 类型 | 说明 |
|---|---|---|
| doc | Array<Object> | 添加的文档列表。 |
| doc_id | String | 添加的文档的 ID。 |
| doc_name | String | 添加的文档的名称。 |
| failed | Array<Object> | 添加失败的文档名称列表。 |
失败响应
| 字段 | 类型 | 描述 |
|---|---|---|
| code | Integer | 错误码。 |
| message | String | 错误详情。 |
错误码
| Code | Message |
|---|---|
| 40000 | 参数错误 |
| 40000 | The embedding_model_version_id does not exist:传入的模型版本 ID 在平台模型目录中不存在 |
| 40000 | The embedding_model_version_id is not an embedding model:传入的模型不是嵌入模型(例如传了对话模型的 modelId) |
| 40000 | The embedding_model_version_id is not an available embedding model:该嵌入模型的厂商暂不支持通过 API 指定 |
| 40127 | 开发者鉴权失败 |
| 20059 | Agent 已删除 |
注意:
embedding_model_version_id校验不通过时,整批文档都不会被创建,也不会出现在failed列表中,而是直接返回上述错误响应。
