import { CodeGroup } from '@/app/components/develop/code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty, PropertyInstruction, Paragraph } from '@/app/components/develop/md.tsx'
# 知识库 API
  ### 鉴权
  Dify Service API 使用 `API-Key` 进行鉴权。
  建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。
  所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  
    ```javascript
      Authorization: Bearer {API_KEY}
    ```
  
  
    此接口基于已存在知识库,在此知识库的基础上通过文本创建新的文档
    ### Path
    
      
        知识库 ID
      
    
    ### Request Body
    
      
        文档名称
      
      
        文档内容
      
      
        索引方式
          - high_quality 高质量:使用  embedding 模型进行嵌入,构建为向量数据库索引
          - economy 经济:使用 keyword table index 的倒排索引进行构建
      
      
        索引内容的形式
          - text_model text 文档直接 embedding,经济模式默认为该模式
          - hierarchical_model parent-child 模式
          - qa_model Q&A 模式:为分片文档生成 Q&A 对,然后对问题进行 embedding
      
      
        在 Q&A 模式下,指定文档的语言,例如:English、Chinese
      
      
        处理规则
          - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
          - rules (object) 自定义规则(自动模式下,该字段为空)
            - pre_processing_rules (array[object]) 预处理规则
              - id (string) 预处理规则的唯一标识符
                - 枚举:
                  - remove_extra_spaces 替换连续空格、换行符、制表符
                  - remove_urls_emails 删除 URL、电子邮件地址
              - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值
            - segmentation (object) 分段规则
              - separator 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
              - max_tokens 最大长度(token)默认为 1000
            - parent_mode 父分段的召回模式 full-doc 全文召回 / paragraph 段落召回
            - subchunk_segmentation (object) 子分段规则
              - separator 分段标识符,目前仅允许设置一个分隔符。默认为 ***
              - max_tokens 最大长度 (token) 需要校验小于父级的长度
              - chunk_overlap 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
      
      当知识库未设置任何参数的时候,首次上传需要提供以下参数,未提供则使用默认选项:
      
        检索模式
          - search_method (string) 检索方法
            - hybrid_search 混合检索
            - semantic_search 语义检索
            - full_text_search 全文检索
          - reranking_enable (bool) 是否开启rerank
          - reranking_model (object) Rerank 模型配置
            - reranking_provider_name (string) Rerank 模型的提供商
            - reranking_model_name (string) Rerank 模型的名称
          - top_k (int) 召回条数
          - score_threshold_enabled (bool)是否开启召回分数限制
          - score_threshold (float) 召回分数限制
      
      
        Embedding 模型名称
      
      
        Embedding 模型供应商
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create-by-text' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "name": "text",
        "text": "text",
        "indexing_technique": "high_quality",
        "process_rule": {
            "mode": "automatic"
        }
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "document": {
        "id": "",
        "position": 1,
        "data_source_type": "upload_file",
        "data_source_info": {
            "upload_file_id": ""
        },
        "dataset_process_rule_id": "",
        "name": "text.txt",
        "created_from": "api",
        "created_by": "",
        "created_at": 1695690280,
        "tokens": 0,
        "indexing_status": "waiting",
        "error": null,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "archived": false,
        "display_status": "queuing",
        "word_count": 0,
        "hit_count": 0,
        "doc_form": "text_model"
      },
      "batch": ""
    }
    ```
    
  
  
    此接口基于已存在知识库,在此知识库的基础上通过文件创建新的文档
    ### Path
    
      
        知识库 ID
      
    
    ### Request Body
    
      
        - original_document_id 源文档 ID(选填)
          - 用于重新上传文档或修改文档清洗、分段配置,缺失的信息从源文档复制
          - 源文档不可为归档的文档
          - 当传入 original_document_id 时,代表文档进行更新操作,process_rule 为可填项目,不填默认使用源文档的分段方式
          - 未传入 original_document_id 时,代表文档进行新增操作,process_rule 为必填
        - indexing_technique 索引方式
          - high_quality 高质量:使用  embedding 模型进行嵌入,构建为向量数据库索引
          - economy 经济:使用 keyword table index 的倒排索引进行构建
        - doc_form 索引内容的形式
          - text_model text 文档直接 embedding,经济模式默认为该模式
          - hierarchical_model parent-child 模式
          - qa_model Q&A 模式:为分片文档生成 Q&A 对,然后对问题进行 embedding
        - doc_language 在 Q&A 模式下,指定文档的语言,例如:English、Chinese
        - process_rule 处理规则
          - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
          - rules (object) 自定义规则(自动模式下,该字段为空)
            - pre_processing_rules (array[object]) 预处理规则
              - id (string) 预处理规则的唯一标识符
                - 枚举:
                  - remove_extra_spaces 替换连续空格、换行符、制表符
                  - remove_urls_emails 删除 URL、电子邮件地址
              - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值
            - segmentation (object) 分段规则
              - separator 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
              - max_tokens 最大长度(token)默认为 1000
            - parent_mode 父分段的召回模式 full-doc 全文召回 / paragraph 段落召回
            - subchunk_segmentation (object) 子分段规则
              - separator 分段标识符,目前仅允许设置一个分隔符。默认为 ***
              - max_tokens 最大长度 (token) 需要校验小于父级的长度
              - chunk_overlap 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
      
      
        需要上传的文件。
      
      当知识库未设置任何参数的时候,首次上传需要提供以下参数,未提供则使用默认选项:
      
        检索模式
          - search_method (string) 检索方法
            - hybrid_search 混合检索
            - semantic_search 语义检索
            - full_text_search 全文检索
          - reranking_enable (bool) 是否开启rerank
          - reranking_model (object) Rerank 模型配置
            - reranking_provider_name (string) Rerank 模型的提供商
            - reranking_model_name (string) Rerank 模型的名称
          - top_k (int) 召回条数
          - score_threshold_enabled (bool)是否开启召回分数限制
          - score_threshold (float) 召回分数限制
      
      
        Embedding 模型名称
      
      
        Embedding 模型供应商
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/document/create-by-file' \
    --header 'Authorization: Bearer {api_key}' \
    --form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \
    --form 'file=@"/path/to/file"'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "document": {
        "id": "",
        "position": 1,
        "data_source_type": "upload_file",
        "data_source_info": {
          "upload_file_id": ""
        },
        "dataset_process_rule_id": "",
        "name": "Dify.txt",
        "created_from": "api",
        "created_by": "",
        "created_at": 1695308667,
        "tokens": 0,
        "indexing_status": "waiting",
        "error": null,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "archived": false,
        "display_status": "queuing",
        "word_count": 0,
        "hit_count": 0,
        "doc_form": "text_model"
      },
      "batch": ""
    }
    ```
    
  
  
    ### Request Body
    
      
        知识库名称(必填)
      
      
        知识库描述(选填)
      
      
        索引模式(选填,建议填写)
          - high_quality 高质量
          - economy 经济
      
      
        权限(选填,默认 only_me)
          - only_me 仅自己
          - all_team_members 所有团队成员
          - partial_members 部分团队成员
      
      
        Provider(选填,默认 vendor)
          - vendor 上传文件
          - external 外部知识库
      
      
        外部知识库 API_ID(选填)
      
      
        外部知识库 ID(选填)
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
      "name": "name",
      "permission": "only_me"
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "id": "",
      "name": "name",
      "description": null,
      "provider": "vendor",
      "permission": "only_me",
      "data_source_type": null,
      "indexing_technique": null,
      "app_count": 0,
      "document_count": 0,
      "word_count": 0,
      "created_by": "",
      "created_at": 1695636173,
      "updated_by": "",
      "updated_at": 1695636173,
      "embedding_model": null,
      "embedding_model_provider": null,
      "embedding_available": null
    }
    ```
    
  
  
    ### Query
    
      
        页码
      
      
        返回条数,默认 20,范围 1-100
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request GET '${props.apiBaseUrl}/datasets?page=1&limit=20' \
    --header 'Authorization: Bearer {api_key}'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": [
        {
          "id": "",
          "name": "知识库名称",
          "description": "描述信息",
          "permission": "only_me",
          "data_source_type": "upload_file",
          "indexing_technique": "",
          "app_count": 2,
          "document_count": 10,
          "word_count": 1200,
          "created_by": "",
          "created_at": "",
          "updated_by": "",
          "updated_at": ""
        },
        ...
      ],
      "has_more": true,
      "limit": 20,
      "total": 50,
      "page": 1
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}' \
    --header 'Authorization: Bearer {api_key}'
    ```
    
    
    ```text {{ title: 'Response' }}
    204 No Content
    ```
    
  
  
    此接口基于已存在知识库,在此知识库的基础上通过文本更新文档
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
    
    ### Request Body
    
      
        文档名称(选填)
      
      
        文档内容(选填)
      
      
        处理规则(选填)
          - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
          - rules (object) 自定义规则(自动模式下,该字段为空)
            - pre_processing_rules (array[object]) 预处理规则
              - id (string) 预处理规则的唯一标识符
                - 枚举:
                  - remove_extra_spaces 替换连续空格、换行符、制表符
                  - remove_urls_emails 删除 URL、电子邮件地址
              - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值
            - segmentation (object) 分段规则
              - separator 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
              - max_tokens 最大长度(token)默认为 1000
            - parent_mode 父分段的召回模式 full-doc 全文召回 / paragraph 段落召回
            - subchunk_segmentation (object) 子分段规则
              - separator 分段标识符,目前仅允许设置一个分隔符。默认为 ***
              - max_tokens 最大长度 (token) 需要校验小于父级的长度
              - chunk_overlap 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update-by-text' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "name": "name",
        "text": "text"
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "document": {
        "id": "",
        "position": 1,
        "data_source_type": "upload_file",
        "data_source_info": {
          "upload_file_id": ""
        },
        "dataset_process_rule_id": "",
        "name": "name.txt",
        "created_from": "api",
        "created_by": "",
        "created_at": 1695308667,
        "tokens": 0,
        "indexing_status": "waiting",
        "error": null,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "archived": false,
        "display_status": "queuing",
        "word_count": 0,
        "hit_count": 0,
        "doc_form": "text_model"
      },
      "batch": ""
    }
    ```
    
  
  
    此接口基于已存在知识库,在此知识库的基础上通过文件更新文档的操作。
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
    
    ### Request Body
    
      
        文档名称(选填)
      
      
        需要上传的文件
      
      
        处理规则(选填)
          - mode (string) 清洗、分段模式 ,automatic 自动 / custom 自定义
          - rules (object) 自定义规则(自动模式下,该字段为空)
            - pre_processing_rules (array[object]) 预处理规则
              - id (string) 预处理规则的唯一标识符
                - 枚举:
                  - remove_extra_spaces 替换连续空格、换行符、制表符
                  - remove_urls_emails 删除 URL、电子邮件地址
              - enabled (bool) 是否选中该规则,不传入文档 ID 时代表默认值
            - segmentation (object) 分段规则
              - separator 自定义分段标识符,目前仅允许设置一个分隔符。默认为 \n
              - max_tokens 最大长度(token)默认为 1000
            - parent_mode 父分段的召回模式 full-doc 全文召回 / paragraph 段落召回
            - subchunk_segmentation (object) 子分段规则
              - separator 分段标识符,目前仅允许设置一个分隔符。默认为 ***
              - max_tokens 最大长度 (token) 需要校验小于父级的长度
              - chunk_overlap 分段重叠指的是在对数据进行分段时,段与段之间存在一定的重叠部分(选填)
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/update-by-file' \
    --header 'Authorization: Bearer {api_key}' \
    --form 'data="{\"name\":\"Dify\",\"indexing_technique\":\"high_quality\",\"process_rule\":{\"rules\":{\"pre_processing_rules\":[{\"id\":\"remove_extra_spaces\",\"enabled\":true},{\"id\":\"remove_urls_emails\",\"enabled\":true}],\"segmentation\":{\"separator\":\"###\",\"max_tokens\":500}},\"mode\":\"custom\"}}";type=text/plain' \
    --form 'file=@"/path/to/file"'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "document": {
        "id": "",
        "position": 1,
        "data_source_type": "upload_file",
        "data_source_info": {
          "upload_file_id": ""
        },
        "dataset_process_rule_id": "",
        "name": "Dify.txt",
        "created_from": "api",
        "created_by": "",
        "created_at": 1695308667,
        "tokens": 0,
        "indexing_status": "waiting",
        "error": null,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "archived": false,
        "display_status": "queuing",
        "word_count": 0,
        "hit_count": 0,
        "doc_form": "text_model"
      },
      "batch": "20230921150427533684"
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        上传文档的批次号
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{batch}/indexing-status' \
    --header 'Authorization: Bearer {api_key}' \
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data":[{
        "id": "",
        "indexing_status": "indexing",
        "processing_started_at": 1681623462.0,
        "parsing_completed_at": 1681623462.0,
        "cleaning_completed_at": 1681623462.0,
        "splitting_completed_at": 1681623462.0,
        "completed_at": null,
        "paused_at": null,
        "error": null,
        "stopped_at": null,
        "completed_segments": 24,
        "total_segments": 100
      }]
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}' \
    --header 'Authorization: Bearer {api_key}' \
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "result": "success"
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
    
    ### Query
    
      
        搜索关键词,可选,目前仅搜索文档名称
      
      
        页码,可选
      
      
        返回条数,可选,默认 20,范围 1-100
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents' \
    --header 'Authorization: Bearer {api_key}' \
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": [
        {
          "id": "",
          "position": 1,
          "data_source_type": "file_upload",
          "data_source_info": null,
          "dataset_process_rule_id": null,
          "name": "dify",
          "created_from": "",
          "created_by": "",
          "created_at": 1681623639,
          "tokens": 0,
          "indexing_status": "waiting",
          "error": null,
          "enabled": true,
          "disabled_at": null,
          "disabled_by": null,
          "archived": false
        },
      ],
      "has_more": false,
      "limit": 20,
      "total": 9,
      "page": 1
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
    
    ### Request Body
    
      
        - content (text) 文本内容/问题内容,必填
        - answer (text) 答案内容,非必填,如果知识库的模式为 Q&A 模式则传值
        - keywords (list) 关键字,非必填
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
      "segments": [
        {
          "content": "1",
          "answer": "1",
          "keywords": ["a"]
        }
      ]
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": [{
        "id": "",
        "position": 1,
        "document_id": "",
        "content": "1",
        "answer": "1",
        "word_count": 25,
        "tokens": 0,
        "keywords": [
            "a"
        ],
        "index_node_id": "",
        "index_node_hash": "",
        "hit_count": 0,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "status": "completed",
        "created_by": "",
        "created_at": 1695312007,
        "indexing_at": 1695312007,
        "completed_at": 1695312007,
        "error": null,
        "stopped_at": null
      }],
      "doc_form": "text_model"
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
    
     ### Query
    
      
        搜索关键词,可选
      
      
        搜索状态,completed
      
      
        页码,可选
      
      
        返回条数,可选,默认 20,范围 1-100
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": [{
        "id": "",
        "position": 1,
        "document_id": "",
        "content": "1",
        "answer": "1",
        "word_count": 25,
        "tokens": 0,
        "keywords": [
            "a"
        ],
        "index_node_id": "",
        "index_node_hash": "",
        "hit_count": 0,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "status": "completed",
        "created_by": "",
        "created_at": 1695312007,
        "indexing_at": 1695312007,
        "completed_at": 1695312007,
        "error": null,
        "stopped_at": null
      }],
      "doc_form": "text_model",
      "has_more": false,
      "limit": 20,
      "total": 9,
      "page": 1
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
      
        文档分段ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "result": "success"
    }
    ```
    
  
  
    ### POST
    
      
        知识库 ID
      
      
        文档 ID
      
      
        文档分段ID
      
    
    ### Request Body
    
      
        - content (text) 文本内容/问题内容,必填
        - answer (text) 答案内容,非必填,如果知识库的模式为 Q&A 模式则传值
        - keywords (list) 关键字,非必填
        - enabled (bool) false/true,非必填
        - regenerate_child_chunks (bool) 是否重新生成子分段,非必填
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
      "segment": {
          "content": "1",
          "answer": "1",
          "keywords": ["a"],
          "enabled": false
      }
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": {
        "id": "",
        "position": 1,
        "document_id": "",
        "content": "1",
        "answer": "1",
        "word_count": 25,
        "tokens": 0,
        "keywords": [
            "a"
        ],
        "index_node_id": "",
        "index_node_hash": "",
        "hit_count": 0,
        "enabled": true,
        "disabled_at": null,
        "disabled_by": null,
        "status": "completed",
        "created_by": "",
        "created_at": 1695312007,
        "indexing_at": 1695312007,
        "completed_at": 1695312007,
        "error": null,
        "stopped_at": null
      },
      "doc_form": "text_model"
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
      
        分段 ID
      
    
    ### Request Body
    
      
        子分段内容
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "content": "子分段内容"
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": {
        "id": "",
        "segment_id": "",
        "content": "子分段内容",
        "word_count": 25,
        "tokens": 0,
        "index_node_id": "",
        "index_node_hash": "",
        "status": "completed",
        "created_by": "",
        "created_at": 1695312007,
        "indexing_at": 1695312007,
        "completed_at": 1695312007,
        "error": null,
        "stopped_at": null
      }
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
      
        分段 ID
      
    
    ### Query
    
      
        搜索关键词(选填)
      
      
        页码(选填,默认1)
      
      
        每页数量(选填,默认20,最大100)
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks?page=1&limit=20' \
    --header 'Authorization: Bearer {api_key}'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": [{
        "id": "",
        "segment_id": "",
        "content": "子分段内容",
        "word_count": 25,
        "tokens": 0,
        "index_node_id": "",
        "index_node_hash": "",
        "status": "completed",
        "created_by": "",
        "created_at": 1695312007,
        "indexing_at": 1695312007,
        "completed_at": 1695312007,
        "error": null,
        "stopped_at": null
      }],
      "total": 1,
      "total_pages": 1,
      "page": 1,
      "limit": 20
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
      
        分段 ID
      
      
        子分段 ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request DELETE '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \
    --header 'Authorization: Bearer {api_key}'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "result": "success"
    }
    ```
    
  
  
    ### 错误信息
    
      
        返回的错误代码
      
    
    
      
        返回的错误状态
      
    
    
      
        返回的错误信息
      
    
  
  
    
    ```json {{ title: 'Response' }}
      {
        "code": "no_file_uploaded",
        "message": "Please upload your file.",
        "status": 400
      }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
      
        分段 ID
      
      
        子分段 ID
      
    
    ### Request Body
    
      
        子分段内容
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request PATCH '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "content": "更新的子分段内容"
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "data": {
        "id": "",
        "segment_id": "",
        "content": "更新的子分段内容",
        "word_count": 25,
        "tokens": 0,
        "index_node_id": "",
        "index_node_hash": "",
        "status": "completed",
        "created_by": "",
        "created_at": 1695312007,
        "indexing_at": 1695312007,
        "completed_at": 1695312007,
        "error": null,
        "stopped_at": null
      }
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
      
        文档 ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request GET '${props.apiBaseUrl}/datasets/{dataset_id}/documents/{document_id}/upload-file' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "id": "file_id",
      "name": "file_name",
      "size": 1024,
      "extension": "txt",
      "url": "preview_url",
      "download_url": "download_url",
      "mime_type": "text/plain",
      "created_by": "user_id",
      "created_at": 1728734540,
    }
    ```
    
  
  
    ### Path
    
      
        知识库 ID
      
    
    ### Request Body
    
      
        检索关键词
      
      
        检索参数(选填,如不填,按照默认方式召回)
        - search_method (text) 检索方法:以下三个关键字之一,必填
          - keyword_search 关键字检索
          - semantic_search 语义检索
          - full_text_search 全文检索
          - hybrid_search 混合检索
        - reranking_enable (bool) 是否启用 Reranking,非必填,如果检索模式为 semantic_search 模式或者 hybrid_search 则传值
        - reranking_mode (object) Rerank 模型配置,非必填,如果启用了 reranking 则传值
            - reranking_provider_name (string) Rerank 模型提供商
            - reranking_model_name (string) Rerank 模型名称
        - weights (float) 混合检索模式下语意检索的权重设置
        - top_k (integer) 返回结果数量,非必填
        - score_threshold_enabled (bool) 是否开启 score 阈值
        - score_threshold (float) Score 阈值
      
      
          未启用字段
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    curl --location --request POST '${props.apiBaseUrl}/datasets/{dataset_id}/retrieve' \
    --header 'Authorization: Bearer {api_key}' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "query": "test",
        "retrieval_model": {
            "search_method": "keyword_search",
            "reranking_enable": false,
            "reranking_mode": null,
            "reranking_model": {
                "reranking_provider_name": "",
                "reranking_model_name": ""
            },
            "weights": null,
            "top_k": 2,
            "score_threshold_enabled": false,
            "score_threshold": null
        }
    }'
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "query": {
        "content": "test"
      },
      "records": [
        {
          "segment": {
            "id": "7fa6f24f-8679-48b3-bc9d-bdf28d73f218",
            "position": 1,
            "document_id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
            "content": "Operation guide",
            "answer": null,
            "word_count": 847,
            "tokens": 280,
            "keywords": [
              "install",
              "java",
              "base",
              "scripts",
              "jdk",
              "manual",
              "internal",
              "opens",
              "add",
              "vmoptions"
            ],
            "index_node_id": "39dd8443-d960-45a8-bb46-7275ad7fbc8e",
            "index_node_hash": "0189157697b3c6a418ccf8264a09699f25858975578f3467c76d6bfc94df1d73",
            "hit_count": 0,
            "enabled": true,
            "disabled_at": null,
            "disabled_by": null,
            "status": "completed",
            "created_by": "dbcb1ab5-90c8-41a7-8b78-73b235eb6f6f",
            "created_at": 1728734540,
            "indexing_at": 1728734552,
            "completed_at": 1728734584,
            "error": null,
            "stopped_at": null,
            "document": {
              "id": "a8c6c36f-9f5d-4d7a-8472-f5d7b75d71d2",
              "data_source_type": "upload_file",
              "name": "readme.txt",
            }
          },
          "score": 3.730463140527718e-05,
          "tsne_position": null
        }
      ]
    }
    ```
    
  
  
    ### Params
    
      
        知识库 ID
      
    
    ### Request Body
    
      
        - type (string) 元数据类型,必填
        - name (string) 元数据名称,必填
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "id": "abc",
      "type": "string",
      "name": "test",
    }
    ```
    
  
  
    ### Params
    
      
        知识库 ID
      
      
        元数据 ID
      
    
    ### Request Body
    
      
        - name (string) 元数据名称,必填
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "id": "abc",
      "type": "string",
      "name": "test",
    }
    ```
    
  
  
    ### Params
    
      
        知识库 ID
      
      
        元数据 ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    ```
    
  
  
    ### Params
    
      
        知识库 ID
      
      
        disable/enable
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    ```
    
  
  
    ### Params
    
      
        知识库 ID
      
    
    ### Request Body
    
      
        - document_id (string) 文档 ID
        - metadata_list (list) 元数据列表
          - id (string) 元数据 ID
          - type (string) 元数据类型
          - name (string) 元数据名称
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    ```
    
  
  
    ### Query
    
      
        知识库 ID
      
    
  
  
    
    ```bash {{ title: 'cURL' }}
    ```
    
    
    ```json {{ title: 'Response' }}
    {
      "doc_metadata": [
        {
          "id": "",
          "name": "name",
          "type": "string",
          "use_count": 0,
        },
        ...
      ],
      "built_in_field_enabled": true
    }
    ```
    
  
  
    ### 错误信息
    
      
        返回的错误代码
      
    
    
      
        返回的错误状态
      
    
    
      
        返回的错误信息
      
    
  
  
    
    ```json {{ title: 'Response' }}
      {
        "code": "no_file_uploaded",
        "message": "Please upload your file.",
        "status": 400
      }
    ```
    
  
  
    
      | code | 
      status | 
      message | 
    
  
  
    
      | no_file_uploaded | 
      400 | 
      Please upload your file. | 
    
    
      | too_many_files | 
      400 | 
      Only one file is allowed. | 
    
    
      | file_too_large | 
      413 | 
      File size exceeded. | 
    
    
      | unsupported_file_type | 
      415 | 
      File type not allowed. | 
    
    
      | high_quality_dataset_only | 
      400 | 
      Current operation only supports 'high-quality' datasets. | 
    
    
      | dataset_not_initialized | 
      400 | 
      The dataset is still being initialized or indexing. Please wait a moment. | 
    
    
      | archived_document_immutable | 
      403 | 
      The archived document is not editable. | 
    
    
      | dataset_name_duplicate | 
      409 | 
      The dataset name already exists. Please modify your dataset name. | 
    
    
      | invalid_action | 
      400 | 
      Invalid action. | 
    
    
      | document_already_finished | 
      400 | 
      The document has been processed. Please refresh the page or go to the document details. | 
    
    
      | document_indexing | 
      400 | 
      The document is being processed and cannot be edited. | 
    
    
      | invalid_metadata | 
      400 | 
      The metadata content is incorrect. Please check and verify. |