SubmitIndexAddDocumentsJob

Updated at:

Adds parsed files to the specified knowledge base.

Operation description

  • This API does not support knowledge bases for data queries or image Q&A. To update these types of knowledge bases, see the instructions on updating knowledge bases in the knowledge base documentation.
  • A RAM user (sub-account) must first obtain the API permission for Alibaba Cloud Model Studio (the AliyunBailianDataFullAccess policy, which includes the sfm:SubmitIndexAddDocumentsJob permission point) and join a workspace before calling this API. An Alibaba Cloud account (primary account) can call this API directly without authorization. We recommend that you call this API using the latest version of the Alibaba Cloud Model Studio SDK.
  • Before calling this API, ensure your knowledge base exists and has a valid knowledge base ID (IndexId).
  • Before calling this API, you must first upload files to Alibaba Cloud Model Studio using the AddFile API.
  • After calling this API, the job runs in the background and may take several hours to complete, especially during peak times. Do not submit duplicate requests until the job is complete. To check the job status, call the GetIndexJobStatus API. The Documents file list returned by the GetIndexJobStatus API contains all files for the job, which is uniquely identified by the job_id you provided. You can check this list to verify whether each file was imported (parsed) successfully. Note that frequent calls to the GetIndexJobStatus API are subject to rate limiting. Do not exceed 20 calls per minute.
  • After this API is called successfully, the job takes some time to run. Do not submit duplicate requests before the response is returned. This API is not idempotent.

Rate limiting: Frequent calls to this API are subject to rate limiting. Do not exceed 10 calls per second. If you are rate-limited, retry later.

Try it now

You can run this API directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After a successful run, OpenAPI Explorer can automatically generate SDK code examples.

RAM authorization

The following table describes the authorization information for this API. You can use the Action element in RAM permission policy statements to grant RAM users or RAM roles the permission to call this API. For more information:

  • Operation: the specific permission.

  • Access level: the access level of each operation. Valid values: Write, Read, or List.

  • Resource type: the resource types that support authorization for the operation. For more information:

    • Required resource types are marked with a leading asterisk (*).
    • For operations that do not support resource-level authorization, All Resources is used.
  • Condition key: the condition keys defined by the cloud service itself.

  • Dependent action: other permissions required to successfully perform the operation. The caller must have the permissions of all dependent actions for the operation to succeed.

Operation

Access level

Resource type

Condition key

Dependent action

sfm:SubmitIndexAddDocumentsJob

create

*All Resources

*

NoneNone

Request syntax

POST /{WorkspaceId}/index/add_documents_to_index HTTP/1.1

Path Parameters

Parameter

Type

Required

Description

Example

WorkspaceId

string

Yes

The ID of the workspace to which the knowledge base belongs. For information about how to obtain it, see How to use workspaces.

llm-3shx2gu255oqxxxx

Request parameters

Parameter

Type

Required

Description

Example

IndexId

string

Yes

The knowledge base ID. This is the Data.Id returned by the CreateIndex API.

79c0alxxxx

SourceType

string

Yes

The type of the data source. Valid values:

  • DATA_CENTER_CATEGORY: Category type, that is, importing all documents under the specified categories in Collections. You can import documents from multiple categories.

  • DATA_CENTER_FILE: Document type, that is, importing the specified files from application data. You can import multiple files.

If you set this parameter to DATA_CENTER_CATEGORY, you must specify the CategoryIds parameter. If you set this parameter to DATA_CENTER_FILE, you must specify the DocumentIds parameter.

Valid values:

  • DATA_CENTER_CATEGORY :

    Category type

  • DATA_CENTER_FILE :

    Document type

DATA_CENTER_FILE

DocumentIds

array

No

A list of file IDs.

string

No

The file ID. This is the FileId returned by the AddFile API. You can also obtain the ID on the application data page by clicking the ID icon next to the file name.

doc_ea4a504d9ce545508d8aa6d90371bf54xxxxxxxx

CategoryIds

array

No

A list of category IDs.

string

No

The category ID. This is the CategoryId returned by the AddCategory API. You can also obtain the ID on the File tab of the application data page by clicking the ID icon next to the category name.

cate_21a407a3372c4ba7aedc649709143f0cxxxxxxxx

ChunkMode

string

No

The custom chunking mode. This setting applies only to the documents added in the current job. For more information, see knowledge base. Valid values (you can specify only one value):

  • length: Splits the text by a fixed length. The chunking strictly follows the specified ChunkSize and OverlapSize. If you do not specify these parameters, the system uses the default values: a ChunkSize of 500 and an OverlapSize of 100. This mode ignores the Separator parameter.

  • page: Splits the text by page. If ChunkSize is specified, its value is also applied during chunking. If ChunkSize is not set, a default value of 500 is used. This mode ignores the OverlapSize and Separator parameters.

  • h1~h5: Splits the text by headings of the corresponding level (h1 for level-1 headings, and so on, with support down to h5 for level-5 headings). If ChunkSize is specified, its value is also applied during chunking. If ChunkSize is not set, a default value of 500 is used. This mode ignores the OverlapSize and Separator parameters.

  • regex: Splits the text by using a regular expression. The Separator parameter is required for this mode. If ChunkSize is specified, its value is also applied during chunking. If ChunkSize is not set, a default value of 500 is used. This mode ignores the OverlapSize parameter.

If this parameter is not set, intelligent chunking is used by default.

length

Separator

string

No

The sentence-split delimiter, which takes effect only when chunkMode is set to regex (it does not take effect even if specified for other modes). You can pass in a single regular expression (multiple ones are not supported) to split the file into small text chunks. For more information, see knowledge base.

When you use intelligent chunking (when chunkMode is not specified), keep the default empty value.

(?<=。)

ChunkSize

integer

No

The chunk size. Specifies the maximum number of characters for each text chunk. This setting applies only to the documents added in the current job. If a text segment exceeds this size, the behavior depends on the chunking mode:

  • Intelligent chunking (if ChunkMode is not set): The text may be truncated.

  • Custom chunking (if ChunkMode is set): The text is forcibly split.

The value must be in the range of [1-6000]. If this parameter is not specified, the default value 500 is used.

For more information, see knowledge base.

If you specify a ChunkSize less than 100, you must also specify the OverlapSize parameter. You can also omit both parameters to use the system defaults.

128

OverlapSize

integer

No

The chunk overlap length (applies only to the files appended this time). It indicates the number of characters that overlap between the current text chunk and the previous text chunk. For more information, see knowledge base. The value must be in the range of [0-1024].

If this parameter is not specified, the default value 100 is used.

The value of OverlapSize must be less than the value of ChunkSize. Otherwise, the chunking process may fail.

16

EnableHeaders

boolean

No

Specifies whether the headers of Excel files support concatenation. If enabled, the knowledge base treats the first row of all xlsx and xls files as the header and automatically concatenates it into each text chunk (data row). This prevents the large language model (LLM) from misinterpreting the header as a regular data row.

We recommend enabling this parameter only when all imported files are in xlsx or xls format and contain headers; otherwise, there is no need to enable it.

Valid values:

  • true: Enabled.

  • false: Disabled.

Default value: false.

Valid values:

  • true :

    Enabled

  • false :

    Disabled

false

Extra

object

No

uniqueId

string

No

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The request ID.

778C0B3B-xxxx-5FC1-A947-36EDD13606AB

Data

object

The business fields returned by the API.

Id

string

The job ID, also known as JobId.

42687eb254a34802bed398357f5498ae

Status

string

The status code returned by the API.

200

Success

boolean

Indicates whether the request was successful. Valid values:

  • true: The request was successful.

  • false: The request failed.

true

Message

string

The error message.

Required parameter(%s) missing or invalid, please check the request parameters.

Code

string

The error status code.

Index.InvalidParameter

Examples

Success response

JSON format

{
  "RequestId": "778C0B3B-xxxx-5FC1-A947-36EDD13606AB",
  "Data": {
    "Id": "42687eb254a34802bed398357f5498ae"
  },
  "Status": "200",
  "Success": true,
  "Message": "Required parameter(%s) missing or invalid, please check the request parameters.",
  "Code": "Index.InvalidParameter"
}

Error codes

HTTP status code

Error code

Error message

Description

400IdempotentParameterMismatchThe request uses the same client token as a previous, but non-identical request. Do not reuse a client token with different requests, unless the requests are identical.

Visit the Error Center to view more error codes.

Release notes

For more information, see change details.