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

# Regenerate Knowledge Base Item Chunks

> Chunks the item again from its source. The new chunks replace the current ones, including your edits, when they arrive. If chunking fails (`READING_FAILURE`), the current chunks and edits stay. Omit `chunkingConfig` to reuse the settings the current chunks were made with. The item goes to `PROCESSING`, then `PENDING_REVIEW` (or straight to indexing with `autoIndex: true`).



## OpenAPI

````yaml /api-reference/openapi.json post /v1/voice-agents/knowledge-base/{id}/chunks/regenerate
openapi: 3.0.1
info:
  title: Hamsa API
  description: >-
    The Hamsa API: voice agents and their calls, phone numbers, batch calls and
    knowledge bases; speech to text, text to speech, voices and AI content.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.tryhamsa.com
security: []
paths:
  /v1/voice-agents/knowledge-base/{id}/chunks/regenerate:
    post:
      summary: Regenerate chunks
      description: >-
        Chunks the item again from its source. The new chunks replace the
        current ones, including your edits, when they arrive. If chunking fails
        (`READING_FAILURE`), the current chunks and edits stay. Omit
        `chunkingConfig` to reuse the settings the current chunks were made
        with. The item goes to `PROCESSING`, then `PENDING_REVIEW` (or straight
        to indexing with `autoIndex: true`).
      parameters:
        - in: path
          name: id
          required: true
          description: ID of the knowledge base item.
          schema:
            type: string
            format: uuid
            example: d949f13f-40d2-4e48-ac86-b66633070603
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                chunkingConfig:
                  $ref: '#/components/schemas/KnowledgeBaseChunkingConfig'
                autoIndex:
                  type: boolean
                  default: false
                  description: >-
                    `false` or omitted: stop after chunking (`PENDING_REVIEW`)
                    so you can review the chunks. `true`: index as soon as
                    chunking finishes.
                  example: false
            examples:
              review:
                summary: New settings, review first
                value:
                  chunkingConfig:
                    strategy: BY_PARAGRAPH
                    targetTokens: 600
                  autoIndex: false
              same:
                summary: Same settings, index right away
                value:
                  autoIndex: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Chunks are being regenerated...
                  messageKey:
                    type: string
                    example: ChunksRegenerationStarted
                  data:
                    type: array
                    items: {}
                    example: []
                    description: 'Always an empty array: this endpoint returns no data.'
        '400':
          description: >-
            Invalid body, or the item has no source to chunk again
            (`KnowledgeBaseItemCannotBeRegenerated`), or a `chunkingConfig`
            whose sizes contradict each other
            (`ChunkingMinTokensExceedsHalfTarget`,
            `ChunkingOverlapTokensExceedsHalfTarget`,
            `ChunkingMaxTokensBelowTarget`,
            `ChunkingMinTokensExceedsMaxTokens`), or `overlapTokens` above 0
            with `QA_PAIRS` (`ChunkingOverlapTokensNotAllowedForQaPairs`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '401':
          description: 'Unauthorized: missing or invalid API key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: >-
            Your API key or role does not have the `knowledge_base:update`
            permission.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '404':
          description: Knowledge base item not found in this project.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '422':
          description: >-
            The item is still processing (`KnowledgeBaseItemIsProcessing`): wait
            for it to finish before changing its chunks.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '500':
          description: Server Side Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '503':
          description: >-
            Hamsa couldn't process the item right now: it is marked
            `READING_FAILURE`. Try again later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    KnowledgeBaseChunkingConfig:
      type: object
      properties:
        strategy:
          type: string
          enum:
            - SEMANTIC
            - BY_PARAGRAPH
            - QA_PAIRS
            - BY_PAGE
            - FIXED
            - LLM_GUIDED
          description: >-
            Chunking method: `SEMANTIC`: keeps a section that fits the target
            whole, otherwise splits it where the topic changes (default,
            slowest); `BY_PARAGRAPH`: groups paragraphs up to the target size
            without crossing headings; `LLM_GUIDED`: an AI model picks where
            each chunk starts, for text without headings or paragraphs;
            `QA_PAIRS`: one chunk per question and its answer; `BY_PAGE`: one
            chunk per page (files with pages); `FIXED`: equal pieces that end on
            sentence boundaries.
          default: SEMANTIC
          example: SEMANTIC
        targetTokens:
          type: integer
          minimum: 50
          maximum: 1500
          default: 400
          example: 400
          description: >-
            Size each chunk aims for, in tokens (50-1500). Agents read the first
            600 characters of each chunk, so 150-300 keeps a chunk whole: try
            150-250 for FAQs and 200-300 for manuals.
        minTokens:
          type: integer
          minimum: 0
          maximum: 500
          default: 40
          example: 40
          description: >-
            Smaller chunks are joined to a neighbour or flagged for review
            (0-500 tokens). At most half of `targetTokens` and not above
            `maxTokens`. Default 40, or half of `targetTokens` when that is
            smaller.
        maxTokens:
          type: integer
          minimum: 100
          maximum: 1800
          default: 1800
          example: 1800
          description: >-
            Hard limit: longer chunks are split at a sentence boundary (100-1800
            tokens). At least `targetTokens` (`ChunkingMaxTokensBelowTarget`).
        overlapTokens:
          type: integer
          minimum: 0
          maximum: 300
          description: >-
            Tokens repeated from the end of one chunk at the start of the next,
            so an idea that crosses the cut isn't lost (0-300, and at most half
            of `targetTokens`: `ChunkingOverlapTokensExceedsHalfTarget`). Every
            chunk takes one except the first, tables and Q&A pairs, across
            sections too. Must be `0` with `QA_PAIRS`
            (`ChunkingOverlapTokensNotAllowedForQaPairs`).
          default: 0
          example: 0
        respectHeadings:
          type: boolean
          default: true
          description: >-
            Never split across a heading, and start each chunk with the full
            path of headings it sits under.
        keepAtomicBlocks:
          type: boolean
          default: true
          description: Never cut lists, numbered steps or code blocks in the middle.
        splitTables:
          type: boolean
          description: >-
            Split large tables into groups of rows, each repeating the header
            row.
          default: true
        addContext:
          type: boolean
          description: >-
            Add a short sentence to each chunk saying where it sits in the
            document. Takes longer.
          default: false
      description: >-
        Chunking settings. Omitted values use the defaults. When a method can't
        be applied, the text is split by `BY_PARAGRAPH` instead (for example
        `QA_PAIRS` with no questions found, or `BY_PAGE` for text without
        pages). Values out of range or that contradict each other are refused
        with 400, never adjusted; when `targetTokens` is left out, the rules use
        400.
    ErrorSchema:
      type: object
      properties:
        code:
          type: integer
          description: >-
            Service error code: the HTTP status with a service prefix (for
            example `8404`). Missing when the service has no code for that
            status.
          example: 8404
        message:
          type: string
          description: >-
            What went wrong. Some services (calls and recordings) put the error
            key here, for example `CallNotFoundOrUnavailable`, and send no
            `messageKey`.
          example: Policy not found!
        messageKey:
          type: string
          description: >-
            Stable key for the error, safe to match on in code. Not returned by
            every service.
          example: PolicyNotFound
        params:
          type: object
          additionalProperties: true
          description: >-
            Details for some errors (for example `reason`). Not returned by
            every service.
          example:
            reason: NO_DRAFT
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Pass the API key in the Authorization header, You need to put Token
        keyword before the API key. e.g. 'Authorization: Token <api-key>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.