> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新文档中的分段

> 更新分段的内容、关键词或回答。修改后的分段将重新触发索引。



## OpenAPI

````yaml /zh/api-reference/openapi_knowledge.json post /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}
openapi: 3.0.1
info:
  title: 知识库 API
  description: >-
    用于管理知识库、文档、分段、元数据和标签的 API，包括创建、检索和配置操作。**注意：**单个知识库 API
    密钥有权操作同一账户下所有可见的知识库。请注意数据安全。
  version: 1.0.0
servers:
  - url: https://{api_base_url}
    description: Knowledge API 的基础 URL。自部署时，替换为你的 API 基础 URL。
    variables:
      api_base_url:
        default: api.dify.ai/v1
        description: API 基础 URL 的主机与路径，不含 `https://` 前缀。
security:
  - ApiKeyAuth: []
tags:
  - name: 知识库
    description: 用于管理知识库的操作，包括创建、配置和检索。
  - name: 文档
    description: 用于在知识库中创建、更新和管理文档的操作。
  - name: 分段
    description: 用于管理分段和子分段的操作。
  - name: 元数据
    description: 用于管理知识库元数据字段和文档元数据值的操作。
  - name: 标签
    description: 用于管理知识库标签和标签绑定的操作。
  - name: 模型
    description: 用于获取可用模型的操作。
  - name: 知识流水线
    description: 用于管理和运行知识流水线的操作，包括数据源插件和流水线执行。
paths:
  /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}:
    post:
      tags:
        - 分段
      summary: 更新文档中的分段
      description: 更新分段的内容、关键词或回答。修改后的分段将重新触发索引。
      operationId: updateSegment
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: 知识库 ID。
        - name: document_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: 文档 ID.
        - name: segment_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: Chunk ID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - segment
              properties:
                segment:
                  type: object
                  properties:
                    content:
                      type: string
                      description: 分段文本内容。
                    answer:
                      type: string
                      description: QA 模式的回答内容。
                    keywords:
                      type: array
                      items:
                        type: string
                      description: 分段的关键词。
                    enabled:
                      type: boolean
                      description: 分段是否已启用。
                    regenerate_child_chunks:
                      type: boolean
                      default: false
                      description: 是否重新生成子分段。
                    attachment_ids:
                      type: array
                      items:
                        type: string
                      description: 附件文件 ID。
                    summary:
                      type: string
                      nullable: true
                      description: 摘要索引的摘要内容。
                  description: 要更新的分段数据。
      responses:
        '200':
          description: 分段更新成功。
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Segment'
                  doc_form:
                    type: string
                    description: 该文档使用的分块模式。
              examples:
                success:
                  summary: 响应示例
                  value:
                    data:
                      id: f3d1c7be-9f3a-40d8-8eb8-3a1ef9c3f2c1
                      position: 1
                      document_id: a8e0e5b5-78c6-4130-a5ce-25feb0e0b4ac
                      content: Dify is an open-source LLM app development platform.
                      sign_content: ''
                      answer: ''
                      word_count: 9
                      tokens: 12
                      keywords:
                        - dify
                        - platform
                        - llm
                      index_node_id: a1b2c3d4-e5f6-7890-abcd-000000000001
                      index_node_hash: abc123def456
                      hit_count: 0
                      enabled: true
                      disabled_at: null
                      disabled_by: null
                      status: completed
                      created_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                      created_at: 1741267200
                      updated_at: 1741267200
                      updated_by: ad313dd6-ef04-4dd1-a5b0-c0f0b9e2e7e4
                      indexing_at: 1741267200
                      completed_at: 1741267200
                      error: null
                      stopped_at: null
                      child_chunks: []
                      attachments: []
                      summary: null
                    doc_form: text_model
components:
  schemas:
    Segment:
      type: object
      properties:
        id:
          type: string
          description: 分段的唯一标识符。
        position:
          type: integer
          description: 分段在文档中的位置。
        document_id:
          type: string
          description: 该分段所属文档的 ID。
        content:
          type: string
          description: 分段的文本内容。
        sign_content:
          type: string
          description: 用于完整性验证的签名内容哈希。
        answer:
          type: string
          description: 回答内容，用于问答模式文档。
        word_count:
          type: integer
          description: 分段内容的字数。
        tokens:
          type: integer
          description: 分段内容的令牌数。
        keywords:
          type: array
          description: 与该分段关联的关键词，用于基于关键词的检索。
          items:
            type: string
        index_node_id:
          type: string
          description: 向量存储中索引节点的 ID。
        index_node_hash:
          type: string
          description: 索引内容的哈希值，用于检测变更。
        hit_count:
          type: integer
          description: 该分段在检索查询中被匹配的次数。
        enabled:
          type: boolean
          description: 该分段是否启用检索。
        disabled_at:
          type: number
          nullable: true
          description: 分段被禁用的时间戳。启用时为 `null`。
        disabled_by:
          type: string
          nullable: true
          description: 禁用该分段的用户 ID。启用时为 `null`。
        status:
          type: string
          description: 分段的当前索引状态，例如 `completed`、`indexing`、`error`。
        created_by:
          type: string
          description: 创建该分段的用户 ID。
        created_at:
          type: number
          description: 创建时间戳（Unix 纪元，单位为秒）。
        updated_at:
          type: number
          description: 最后更新时间戳（Unix 纪元，单位为秒）。
        updated_by:
          type: string
          description: 最后更新该分段的用户 ID。
        indexing_at:
          type: number
          nullable: true
          description: 索引开始的时间戳。尚未开始时为 `null`。
        completed_at:
          type: number
          nullable: true
          description: 索引完成的时间戳。尚未完成时为 `null`。
        error:
          type: string
          nullable: true
          description: 索引失败时的错误消息。无错误时为 `null`。
        stopped_at:
          type: number
          nullable: true
          description: 索引停止的时间戳。未停止时为 `null`。
        child_chunks:
          type: array
          description: 属于该分段的子分段。仅在分层模式文档中存在。
          items:
            $ref: '#/components/schemas/ChildChunk'
        attachments:
          type: array
          description: 附加到该分段的文件。
          items:
            type: object
            properties:
              id:
                type: string
                description: 附件文件标识符。
              name:
                type: string
                description: 原始文件名。
              size:
                type: integer
                description: 文件大小（字节）。
              extension:
                type: string
                description: 文件扩展名。
              mime_type:
                type: string
                description: 文件的 MIME 类型。
              source_url:
                type: string
                description: 访问附件的 URL。
        summary:
          type: string
          nullable: true
          description: AI 生成的分段内容摘要。未启用摘要索引时为 `null`。
    ChildChunk:
      type: object
      properties:
        id:
          type: string
          description: 子分段的唯一标识符。
        segment_id:
          type: string
          description: 该子分段所属的父分段 ID。
        content:
          type: string
          description: 子分段的文本内容。
        position:
          type: integer
          description: 子分段在父分段中的位置。
        word_count:
          type: integer
          description: 子分段内容的字数。
        type:
          type: string
          description: 子分段的创建方式。系统生成为 `automatic`，手动创建为 `custom`。
        created_at:
          type: number
          description: 创建时间戳（Unix 纪元，单位为秒）。
        updated_at:
          type: number
          description: 最后更新时间戳（Unix 纪元，单位为秒）。
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key 认证。对于所有 API 请求，请在 `Authorization` HTTP 头中包含您的 API Key，并加上
        `Bearer ` 前缀。示例：`Authorization: Bearer {API_KEY}`。**强烈建议将 API Key
        存储在服务端，不要在客户端共享或存储，以避免 API Key 泄漏导致严重后果。**

````