最近更新时间:2024.05.13 17:29:59
首次发布时间:2024.04.17 14:21:07
/doc_chunking 接口用于解析文档内容并根据文档内文本段落的从属关系(如主标题、小标题和正文等)将原文划分为长度较短的文本片。接口的使用需要传入待解析的文档,返回的结果是一个包含多个文本片的数组。每个文本片均包含其在原文中的位置信息和文本内容。将文本切分为较小的文本片后有利于后续检索到更小粒度的信息,以及适应大语言模型输入窗口的限制。
说明
当前默认的文本切分策略:基于文档的语义标签(如摘要、引言等)切分。
URI | http://api-knowledgebase.ml_platform.cn-beijing.volces.com/api/knowledge/service/doc_chunking | 统一资源标识符 |
---|---|---|
方法 | POST | 客户端对 doc_chunking 服务请求的操作类型 |
请求头 | Content-Type: application/json | 请求消息类型 |
Authorization: HMAC-SHA256 *** | 鉴权 |
参数 | 类型 | 必选 | 子参数 | 类型 | 默认值 | 说明 |
---|---|---|---|---|---|---|
doc_infos | array | 是 | ||||
是 | doc_type | string | 文档的类型,当前支持pdf、markdown、doc、docx、txt,、pptx | |||
二选一 | url | string | 文档的下载链接。对应文档的大小不超过30M。 | |||
data | byte | 以base64方式上传的文档base64。 | ||||
否 | chunk_size | int | 500 | 切分长度 | ||
否 | strategy | int | 3 | 切分策略 | ||
否 | extra | map | 否 | 可传一些业务定制参数: |
参数 | 参数说明 |
---|---|
code | 状态码 |
message | 返回信息 |
request_id | 标识每个请求的唯一标识符 |
data | 返回结果。包含以下字段:
|
状态码 | http状态码 | 返回信息 | 状态码说明 |
---|---|---|---|
0 | 200 | success | 请求成功。 |
1000001 | 403 | check sign failed | 请求头中缺乏鉴权信息。 |
1000002 | 403 | account[xx] has no permission | 没有接口权限,请联系管理员添加。 |
1000003 | 400 | account[xx] request parse failed... | 非法参数,参数请求格式错误。 |
1000004 | 200 | account[xx] has arrived .... | qps 限制,请重试。 |
...... | |||
1001000 | 500 | ...... | 服务器内部错误,请联系管理员。 |
curl -X POST http://api-knowledgebase.ml_platform.cn-beijing.volces.com/api/knowledge/service/doc_chunking \ -H "Authorization:xxxxxxxxx" \ -d '{"doc_infos":[{"doc_type":"pdf","url":"{url}","chunk_size":100,"extra":{"pdf_with_ocr":true}},{"doc_type":"doc","url":"{url}"}]}'
{ "code": 0, "data": [ { // 每个文档请求一个块,里面一个"DocChunkingResults" "DocChunkingResults": { "DocChunks": [ "{\"id\": 0, \"block_id\": null, \"type\": \"section-text\", \"level\": -1, \"parent\": -1, \"children\": [], \"text\": \"\", \"label\": \"\", \"positions\": null, \"table_detail\": {\"tableIdx\": null, \"tableName\": null, \"caption\": null, \"text\": null, \"cells\": null}, \"image_detail\": {\"base64\": null, \"caption\": null, \"links\": null}}", "{\"id\": 1, \"block_id\": null, \"type\": \"section-text\", \"level\": -1, \"parent\": -1, \"children\": [], \"text\": \"\", \"label\": \"\", \"positions\": null, \"table_detail\": {\"tableIdx\": null, \"tableName\": null, \"caption\": null, \"text\": null, \"cells\": null}, \"image_detail\": {\"base64\": null, \"caption\": null, \"links\": null}}", "{\"id\": 2, \"block_id\": null, \"type\": \"title\", \"level\": -1, \"parent\": -1, \"children\": [6, 21, 46, 58, 71, 90, 102, 120], \"text\": \"个人贷款管理办法\", \"label\": \"\", \"positions\": null, \"table_detail\": {\"tableIdx\": null, \"tableName\": null, \"caption\": null, \"text\": null, \"cells\": null}, \"image_detail\": {\"base64\": null, \"caption\": null, \"links\": null}}", "{\"id\": 3, \"block_id\": null, \"type\": \"section-text\", \"level\": -1, \"parent\": -1, \"children\": [], \"text\": \"(2024年1月30日国家金融监督管理总局令2024年第3号公布 自2024年7月1日起施行)\", \"label\": \"\", \"positions\": null, \"table_detail\": {\"tableIdx\": null, \"tableName\": null, \"caption\": null, \"text\": null, \"cells\": null}, \"image_detail\": {\"base64\": null, \"caption\": null, \"links\": null}}", "{\"id\": 4, \"block_id\": null, \"type\": \"section-text\", \"level\": -1, \"parent\": -1, \"children\": [], \"text\": \"\", \"label\": \"\", \"positions\": null, \"table_detail\": {\"tableIdx\": null, \"tableName\": null, \"caption\": null, \"text\": null, \"cells\": null}, \"image_detail\": {\"base64\": null, \"caption\": null, \"links\": null}}", "{\"id\": 5, \"block_id\": null, \"type\": \"section-text\", \"level\": -1, \"parent\": -1, \"children\": [], \"text\": \"\", \"label\": \"\", \"positions\": null, \"table_detail\": {\"tableIdx\": null, \"tableName\": null, \"caption\": null, \"text\": null, \"cells\": null}, \"image_detail\": {\"base64\": null, \"caption\": null, \"links\": null}}" ], "Status": "{\"message\": \"chunking_success\", \"code\": 0, \"parser_engine\": \"docai\"}" } }, // 同一个request里有的成功,有的失败,下面是个失败的例子 { "DocChunkingResults": { "Status": "{\"message\": \"cannot open empty document\", \"code\": 7000}" } } ], "message": "success", "request_id": "02171334661047200000000000000000000ffff0a0060c93db5b5" }