Add a chunk to a specified knowledge base.
Prerequisites
Configure the endpoint and authentication first. See API overview and Authentication.
Endpoint
POST /api/v1/indices/rag/index/chunk/create
Add a chunk to a specified knowledge base.
Supports document search (document), data query (table), and image Q&A (image) knowledge bases; does not support audio/video search (multimedia). Data query and image Q&A knowledge bases only support the spreadsheet dataset (Excel) data source. This API is idempotent. Frequent calls will be rate-limited; do not exceed 10 calls per second.
The target document must finish importing (status
FINISH in List Documents) before chunks can be added. Calling this API while the document is still importing returns Required parameter(dataId) missing or invalid; this error does not indicate a problem with the dataId parameter itself.Request body
| Field | Required | Type | Description |
|---|---|---|---|
pipelineId | Yes | string | Knowledge base ID, the data.pipelineId returned by the createIndex API. |
dataId | No | string | File ID, the fileId returned by the addFile API. For document-search knowledge bases, specifies the document the chunk belongs to. |
field | Yes | object | Chunk content passed as key-value pairs. The structure varies by knowledge base type. Document search (document) uses fixed keys — sub-fields: content (string, required, chunk body text, maximum length 6000), title (string, optional, chunk title, maximum length 50), image_urls (array<string>, optional, image URLs contained in the chunk, up to 10). Data query (table) and image Q&A (image) keys are not fixed; they are determined by the data source table of the knowledge base — the key is the Excel column header and the value is the corresponding column value, and column headers that participate in retrieval or replies are required. Value requirements by type: String — maximum length 6000; Time — 13-digit timestamp in milliseconds; Long — integer, maximum 2147483647; Double — decimals supported; image_url — up to 5 images, with multiple images joined into a single string using English commas. |
Request example
Document search (document) knowledge base, using fixed keys:
BASE_URL is https://{workspace_id}.cn-beijing.maas.aliyuncs.com ({workspace_id} is the workspace ID), and BAILIAN_API_KEY is your Alibaba Cloud Model Studio API key.
Response example
Returns 200 on success.
Response fields
| Field | Type | Description |
|---|---|---|
code | string | Response code. Success on success. |
status_code | integer | HTTP status code. |
request_id | string | Unique request identifier. Provide this ID when troubleshooting. |
success | boolean | Whether the API call succeeded. |
message | string | Response message. success on success. |
status | string | Status returned by the API. SUCCESS on success. |
Error codes
| HTTP status code | Error code | Message | Description |
|---|---|---|---|
| 400 | Index.InvalidParameter | Required parameter missing or invalid. | Invalid request parameters. |
| 401 | InvalidApiKey | Invalid API-key provided. | Authentication failed. The API key is invalid or missing. |