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

# Chunk APIs

<Badge icon="arrow-left" color="gray">[Back to API List](/ai-for-service/apis/searchai/api-list)</Badge>

## Get Chunks By Condition

This API returns the complete list of chunks that satisfy the given condition in the request body.

| Field             | Value                                         |
| ----------------- | --------------------------------------------- |
| **Method**        | POST                                          |
| **Endpoint**      | `<host_url>/api/public/bot/:botId/chunk/list` |
| **Content-Type**  | `application/json`                            |
| **Authorization** | `auth: <JWT Token>`                           |
| **API Scope**     | Chunk Management                              |

### Query Parameters

| Parameter | Description                       | Mandatory |
| --------- | --------------------------------- | --------- |
| Bot ID    | Provide your application ID here. | Yes       |

### Request Parameters

| Parameter           | Description                                                                                                                                                                                                                                                                                                                                                                        | Mandatory                                                |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| `filters`           | Used to set filters for selecting chunks. `filters` contains: **Conditions** — an array of conditions where each condition is a set of operands applied on the conditions; and **Operand** — the operand applied on all conditions in the array. For example, a logical OR on `sourceName`, another OR on `recordTitle`, and an AND combining both results. See the example below. | No. If no filters are provided, all chunks are returned. |
| **`enableFilters`** | Set to `true` to apply the `filter` field to chunks in the response.                                                                                                                                                                                                                                                                                                               | No                                                       |
| **`nextCursor`**    | Used for cursor-based pagination. Omit on first request; use the cursor value from the previous response to fetch the next set of results.                                                                                                                                                                                                                                         | No                                                       |
| **`prevCursor`**    | Used for cursor-based pagination. Use the cursor value from the previous request.                                                                                                                                                                                                                                                                                                  | No                                                       |

**Example filter:**

```json theme={null}
{
  "conditions": [
    {
      "operand": "or",
      "conditions": [
        { "key": "sourceName", "op": "equals", "value": "https://www.blogs.domain.com/" },
        { "key": "sourceName", "op": "equals", "value": "www.domain.com" }
      ]
    },
    {
      "operand": "or",
      "conditions": [
        { "key": "recordTitle", "op": "equals", "value": "FAQs" },
        { "key": "recordTitle", "op": "equals", "value": "Frequently Asked Questions" }
      ]
    }
  ],
  "operand": "and"
}
```

### Sample Response

```json theme={null}
{
  "count": 888,
  "chunks": [
    {
      "_id": "chk-fffb8f28-29c2-4afe-8d2c-9379dad4446c",
      "chunkTitle": "",
      "chunkText": "191 agreement of trial balance...",
      "sourceType": "file",
      "sourceName": "Default Directory",
      "extractionMethod": "text",
      "chunkType": "Text",
      "chunkContent": "chunkText : 191 agreement of trial balance...",
      "chunkId": "chk-fffb8f28-29c2-4afe-8d2c-9379dad4446c",
      "sourceUrl": "https://domain/api/getMediaStream/findly/f-e7e04183-c53a-5013-9f93-f77f438aa7f9.pdf?n=4272962592&s=IkFHSDh1L3MxejB0OHU0MFg0MEVPV3AwSXRQZy9rbUhOOHh3RGdKaVpCSVk9Ig$$",
      "pageNumber": 191,
      "recordTitle": "accounts.pdf",
      "recordUrl": "https://domain/api/getMediaStream/findly/f-e7e04183-c53a-5013-9f93-f77f438aa7f9.pdf?n=4272962592&s=IkFHSDh1L3MxejB0OHU0MFg0MEVPV3AwSXRQZy9rbUhOOHh3RGdKaVpCSVk9Ig$$#page=191",
      "docId": "fc-4de878cb-01a6-5557-a7a7-78992b743b77",
      "searchIndexId": "sidx-f9413800-94f8-51e0-b3d6-7d1b8187d6f6",
      "sourceId": "fs-4181a831-ef7b-5bb6-8adb-937be72ce275",
      "createdOn": "2024-11-19T13:45:45.914Z",
      "extractionStrategy": "Default Strategy",
      "fileType": "pdf",
      "chunkMeta": {}
    }
  ],
  "hasMore": true,
  "inOffsetPagination": true,
  "nextCursor": "eyJzZWFyY2hBZnRlciI6ImNoay1jMTFjZGMwZi05MmUwLTQzYTgtODc5OS1kZjAwZjA0MzExNDUiLCJza2lwIjoxMCwibGltaXQiOjEwLCJwcmV2Q3Vyc29yIjoiIn0=",
  "prevCursor": null
}
```

***

## Update Chunks

This API updates a given chunk. Only parameters included in the request body are updated; omitted parameters retain their existing values.

| Field             | Value                                             |
| ----------------- | ------------------------------------------------- |
| **Method**        | POST                                              |
| **Endpoint**      | `<host_url>/api/public/bot/:botId/chunk/:chunkId` |
| **Content-Type**  | `application/json`                                |
| **Authorization** | `auth: <JWT Token>`                               |
| **API Scope**     | Chunk Management                                  |

### Query Parameters

| Parameter | Description                           | Mandatory |
| --------- | ------------------------------------- | --------- |
| Bot ID    | Provide your application ID here.     | Yes       |
| ChunkID   | Unique ID of the chunk to be updated. | Yes       |

### Request Parameters

Pass the full chunk info in the request body. Field names must match the example below.

#### Sample Request

```json theme={null}
{
  "chunkText": "text",
  "chunkTitle": "title1",
  "pageNumber": "1",
  "recordTitle": "recordTitle",
  "recordUrl": "recordUrl",
  "sourceUrl": "sourceUrl",
  "chunkMeta": {}
}
```

### Sample Response

```json theme={null}
{
  "indexPipelineId": "fip-8e8d41c7-e1c3-5f73-b764-09327de66de7_vector",
  "status_code": 200,
  "status_msg": "Documents updated successfully",
  "updated_documents": 1
}
```

***

## Delete Chunks by ID

This API enables targeted deletion of indexed content without a full re-index. Provide a list of chunk IDs to identify and delete the corresponding chunks from the Search Index. Useful for incremental cleanup, partial refresh scenarios, and lifecycle management of structured uploads.

| Field              | Value                                                  |
| ------------------ | ------------------------------------------------------ |
| **Method**         | POST                                                   |
| **URL**            | `/api/public/bot/{AppId}/search/delete-chunks-by-cond` |
| **Content-Type**   | `application/json`                                     |
| **Authentication** | `auth: <JWT Token>`                                    |
| **API Scope**      | Chunk Management                                       |

### Path Parameters

| Parameter | Type   | Required | Description                                                                                           |
| --------- | ------ | -------- | ----------------------------------------------------------------------------------------------------- |
| `AppId`   | string | Yes      | Your application ID. To view it, go to **Dev Tools** under **App Settings** and check the API scopes. |

### Request Body Parameters

| Field     | Type      | Required | Description                      |
| --------- | --------- | -------- | -------------------------------- |
| `chunkId` | string\[] | No       | An array of chunk IDs to delete. |

### Sample Request

**Example: Delete by chunkId**

```bash theme={null}
curl --location 'https://<HOST>/api/public/bot/<BOT_ID>/search/delete-chunks-by-cond' \
--header 'auth: <JWT_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
  "chunkId": ["chk-xxxx1", "chk-xxxx2"]
}'
```

### Response

**Response Fields**

| Field            | Description                              |
| ---------------- | ---------------------------------------- |
| `status`         | Status of the chunk deletion job.        |
| `totalRequested` | Number of chunks requested for deletion. |
| `totalDeleted`   | Number of chunks successfully deleted.   |
| `totalNotFound`  | Number of chunks that were not found.    |

#### Sample Response

```json theme={null}
{
  "Status": "success",
  "Data": {
    "totalRequested": 4,
    "totalDeleted": 4,
    "totalNotFound": 0
  }
}
```

### Error Messages

| Error Code | Message                           | When It Occurs                                 | Recommended Action                                          |
| ---------- | --------------------------------- | ---------------------------------------------- | ----------------------------------------------------------- |
| 400        | One or more chunkIds don't exist. | `chunkId` is not provided in the request body. | Provide exactly one of the required fields.                 |
| 401        | Unauthorized                      | Missing, invalid, or expired JWT token.        | Verify the `auth` header and regenerate the token.          |
| 404        | Resource not found                | Invalid `AppId` or resource doesn't exist.     | Verify the AppID.                                           |
| 500        | Internal server error             | Unexpected server-side failure.                | Retry the request or contact support if the issue persists. |
