You need to enable JavaScript to run this app.
导航

doc_chunking

最近更新时间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。
请求整体长度不超过4M。大文件解析需通过url方式。

chunk_size

int

500

切分长度

strategy

int

3

切分策略

extra

map

可传一些业务定制参数:
parse_table_for_pdf:是否识别pdf表格,'false'代表不识别,'true'代表识别,默认不识别;
parse_picture_for_pdf:是否识别pdf图片,'false'代表不识别,'true'代表识别,默认识别;
page_size_limit:pdf页数限制,默认200页;
merge_small_chunks:是否合并相邻的小chunk,只对策略1生效,'false'代表不合并,'true'代表合并,默认不合并;
pdf_with_ocr:是否解析扫描件,'false'代表不解析,'true'代表解析,默认不解析

响应消息

参数

参数说明

code

状态码

message

返回信息

request_id

标识每个请求的唯一标识符

data

返回结果。包含以下字段:

  • id:段落索引。
  • type:该 chunk 属于哪一种文档元素。title 表示全文大标题、section-title 表示章节标题、section-text 表示章节内容、image 表示图片、table 表示表格、header 表示页眉、footer 表示页脚、footnote 表示脚注、caption 表示图/表描述、toc 表示目录、others 表示其他。
  • label:段落的语义标签。以论文为例,有 title,author,abstract,introduction,related works 等。
  • Level:段落层级,类似飞书文档的 Hn。
  • parent:当前段落父节点索引。
  • children:当前段落所有子节点索引。
  • text:段落文本内容。
  • positions:chunk 的位置信息,pdf 文档中会有 bbox 和 page_no。

状态码说明

状态码

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"
}