CreateIndex
Use this API to create two types of knowledge bases: unstructured knowledge bases for documents, audio, or video, and structured knowledge bases for data queries or image Q&A.
Operation description
-
Permissions:
- RAM user (sub-account): You must first obtain the API permissions for Alibaba Cloud Model Studio (you can use the
AliyunBailianDataFullAccesspolicy, which includes the sfm:CreateIndex permission required for this operation) and join a workspace before you can call this operation. - Alibaba Cloud account (primary account): By default, an Alibaba Cloud account has the required permissions and can call this operation directly.
- RAM user (sub-account): You must first obtain the API permissions for Alibaba Cloud Model Studio (you can use the
-
How to call: We recommend that you use the latest version of the Alibaba Cloud Model Studio SDK to call this operation. The SDK encapsulates the complex signature calculation logic to simplify the process.
-
What to do next: This operation only initializes the knowledge base creation job. After you call this operation, you must call the SubmitIndexJob operation to complete the creation. Otherwise, you will get an empty knowledge base. For related code examples, see Knowledge base API guide.
-
Idempotence: This operation is not idempotent. Repeated calls may create multiple knowledge bases with the same name. We recommend that you implement idempotent calls by using the "query first, then create" logic.
Rate limiting: Frequent calls to this operation are subject to rate limiting. Do not exceed a frequency of 10 calls per second. If you encounter rate limiting, retry the call later.
Try it now
You can run this operation directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After a successful call, OpenAPI Explorer can automatically generate SDK code examples.
RAM authorization
The following table describes the authorization information of this API. You can use it in the Action element of a RAM policy statement to grant RAM users or RAM roles the permission to call this API. The details are as follows:
-
Action: The specific permission point.
-
Access level: The access level of each action. Valid values: Write, Read, or List.
-
Resource type: The resource types that support authorization for the action. The details are as follows:
- Required resource types are marked with an asterisk (*) before them.
- For operations that do not support resource-level authorization,
All Resourcesis used.
-
Condition key: The condition keys defined by the cloud service itself.
-
Dependent action: The other permissions required to successfully perform the operation. The caller must have the permissions of all dependent actions for the operation to succeed.
Action | Access level | Resource type | Condition key | Dependent action |
|---|---|---|---|---|
sfm:CreateIndex | create | *All Resources
| None | None |
Request syntax
POST /{WorkspaceId}/index/create HTTP/1.1
Path Parameters
Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| WorkspaceId | string | Yes | The workspace ID. The knowledge base is created in this workspace. For more information about how to obtain the workspace ID, see How to use workspaces. | llm-3z7uw7fwz0vexxxx |
Request parameters
Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| Name | string | Yes | The name of the knowledge base. The name can be 1 to 20 characters in length and can contain Chinese characters, letters, digits, underscores (_), hyphens (-), periods (.), and colons (:). | Enterprise doc lib |
| StructureType | string | Yes | The type of the knowledge base. Valid values:
Note that the type of a knowledge base cannot be changed after the knowledge base is created. Valid values:
| unstructured |
| EmbeddingModelName | string | No | The vector model used by the knowledge base. A vector model converts the original input prompt and knowledge text into numerical vectors so that the two can be compared for similarity. The text-embedding-v4 model is a comprehensive upgrade over the text-embedding-v3 model in terms of language support, vectorization of code snippets, and vector dimension selection. It is suitable for most scenarios. For more information, see Vectorization. Valid values:
The default value is empty, in which case the text-embedding-v3 model is used.
The default value is empty, in which case the text-embedding-v2 model is used. | text-embedding-v4 |
| RerankModelName | string | No | The reranking model used by the knowledge base. The reranking model is an external scoring system that calculates a similarity score between the user's question and each text chunk in the knowledge base, sorts the text chunks in descending order of the score, and returns the top K text chunks with the highest scores. Valid values:
The default value is empty, in which case qwen3-rerank is used. Use
Valid values:
| gte-rerank-hybrid |
| RerankMinScore | number | No | The similarity threshold. Only text chunks with a similarity score higher than this value are recalled. This parameter is used to filter the text chunks returned by the reranking model. Valid range: [0.01-1.00]. If you do not specify this parameter, the default value 0.01 is used. | 0.20 |
| ChunkSize | integer | No | The chunk size, which is the maximum number of characters in each text chunk. If this length is exceeded:
Valid range: [1-6000]. If you do not specify this parameter, the default value 500 is used. If you set | 128 |
| OverlapSize | integer | No | The chunk overlap size, which is the number of overlapping characters between the current text chunk and the previous one. Valid range: [0-1024]. If you do not specify this parameter, the default value 100 is used.
| 16 |
| Separator | string | No | The sentence separator, which takes effect only when For smart chunking (the | (?<=。) |
| SourceType | string | No | This parameter has become required in the latest SDK version. Otherwise, calling the SubmitIndexJob operation will fail with the error: Required parameter(data_sources) missing or invalid. The source of the imported data. Valid values:
If you set this parameter to DATA_CENTER_CATEGORY, you must specify the To create an empty knowledge base, use an empty category that contains no files: set this parameter to DATA_CENTER_CATEGORY and specify the ID of the empty category for Valid values:
| DATA_CENTER_FILE |
| DocumentIds | array | No | You can import files when you create a knowledge base. Specify the list of files to import (by file ID). We recommend importing no more than 10,000 files. If you have more files, you can call the SubmitIndexAddDocumentsJob operation later to import them. | |
string | No | The file ID, which is the | file_9a65732555b54d5ea10796ca5742ba22_xxxxxxxx | |
| CategoryIds | array | No | You can import files when you create a knowledge base. Specify category IDs to import all files under the corresponding categories. We recommend importing no more than 500 files. If you have more files, you can call the SubmitIndexAddDocumentsJob operation later to import them. | |
string | No | The category ID, which is the | ca_hiu2383nfxxxx | |
| TableIds | array | No | Obtain the table ID on the Tables tab of the table connector under Data Connections by clicking the ID icon next to the table name. If the list contains multiple IDs, only the first one is used. | |
string | No | |||
| SinkType | string | Yes | The vector storage type of the knowledge base. For more information, see Knowledge bases. Valid values:
If you have not used ADB storage on Alibaba Cloud Model Studio, go to the Create Knowledge Base page, set the vector storage type to ADB-PG, and follow the on-screen instructions to complete the authorization. If you specify ADB for this parameter, you must specify the Valid values:
| BUILT_IN |
| SinkInstanceId | string | No | The ID of the AnalyticDB for PostgreSQL instance (required only when | gp-bp32109xxxx |
| SinkRegion | string | No | The region where the AnalyticDB for PostgreSQL instance is located (required only when | cn-hangzhou |
| Columns | array<object> | No | The structure of the data table (column names, types, etc.). | |
object | No | This parameter is not available yet. Do not specify it. | ||
| Column | string | No | This parameter is not available yet. Do not specify it. | school |
| IsRecall | boolean | No | Specifies whether the column participates in model responses. If enabled, the retrieval results of this column are used as input for the LLM to generate answers. Valid values:
| true |
| IsSearch | boolean | No | Specifies whether the column participates in knowledge base retrieval. If enabled, the knowledge base is allowed to search this column for data. Valid values:
| true |
| Name | string | No | The field name. It must be consistent with the header of the data table created in Application Data. | School |
| Type | string | No | The field type. It must be consistent with the header of the data table created in Application Data. Valid values:
| string |
| Description | string | No | The description of the knowledge base. The description can be 0 to 1,000 English or Chinese characters in length. The default value is empty. | Enterprise doc lib includes important materials such as company policies and product lists. |
| metaExtractColumns | array<object> | No | The metadata extraction configuration. Metadata is a series of additional attributes related to unstructured data content. These attributes are integrated into text chunks as key-value pairs. For more information, see Knowledge bases. | |
object | No | |||
| Key | string | No | The metadata field, which can be 1 to 50 characters in length and must consist of letters or underscores. If you specify this parameter, you must also specify the | author |
| Value | string | No | The value of the metadata field. | Tim |
| Type | string | No | The method for obtaining the value of the metadata field. Valid values:
Valid values:
| constant |
| Desc | string | No | The Chinese description of the metadata field. The description can be 0 to 1,000 characters in length and can contain Chinese characters, letters, digits, underscores (_), hyphens (-), periods (.), and colons (:). The default value is empty. | Author name |
| EnableLlm | boolean | No | If enabled, the metadata field and its value participate in the LLM answer generation process along with the content of text chunks. Valid values:
The default value is false. Valid values:
| false |
| EnableSearch | boolean | No | If enabled, the metadata field and its value participate in the knowledge base retrieval process along with the content of text chunks. Valid values:
The default value is false. Valid values:
| false |
| enableHeaders | boolean | No | Specifies whether to use the first row of all .xlsx and .xls files as the table header and append it to each text chunk, preventing the LLM from treating the header as a regular data row. We recommend enabling this feature only when all imported files are in .xlsx or .xls format and contain a header. Otherwise, you do not need to enable it. Valid values:
If you do not specify this parameter, this feature is disabled by default. Valid values:
| false |
| chunkMode | string | No | Enables custom chunking and specifies the chunking policy. For more information, see Knowledge bases. Possible values (only one value can be specified at a time):
If you do not specify this parameter, smart chunking is used by default. Valid values:
| regex |
| EnableRewrite | boolean | No | Specifies whether to enable multi-turn conversation rewriting. Valid values:
If you do not specify this parameter, this feature is enabled by default. Valid values:
| true |
| CreateIndexType | string | No | This parameter is not available yet. Do not specify it. | standard |
| pipelineCommercialType | string | No | The edition type of the knowledge base. Valid values:
| standard |
| pipelineCommercialCu | integer | No | Specifies the number of RCUs for the knowledge base (required only when pipelineCommercialType is set to enterprise). Valid range: [1-200]. | 1 |
| pipelineRetrieveRateLimitStrategy | string | No | The rate limiting policy for the knowledge base dependency chain (required only when pipelineCommercialType is set to enterprise). Value: downgrade: Degrades the service (switches to a lightweight retrieval chain). If you do not specify this parameter, the default value downgrade is used. | downgrade |
| datasourceCode | string | No | The data source code. This parameter is required when creating a data query knowledge base and is used together with table and database. We recommend using the new parameter connectId, which you can obtain from the data connector card on the Data Connections page. The current parameter is still compatible but will no longer be maintained.
| 260xxx |
| table | string | No | The name of the data table. This parameter is required when creating a data query knowledge base. The data table must exist in the data source specified by connectId or datasourceCode. | lance |
| database | string | No | The name of the database. This parameter is required when creating a data query knowledge base. The database must exist in the data source specified by datasourceCode. | database_a6eacabe6 |
| knowledgeType | string | No | The specific knowledge type, which further indicates the type of data processed by the knowledge base. This parameter and knowledgeScene must be provided or omitted together. They cannot be set separately. If both are omitted, the system uses the default configuration based on structureType. Setting constraints: The value of this parameter must match the structureType you select and determines the valid values of knowledgeScene. Valid values:
| document |
| knowledgeScene | string | No | The specific usage scenario of the knowledge base. This parameter and knowledgeType must be provided or omitted together. They cannot be set separately. If both are omitted, the system uses the default configuration based on structureType. Setting constraints: The value of this parameter depends entirely on the knowledgeType you set. Values and linkage relationships:
| basic_document_qa |
| connectId | string | No | The connector identifier, which you can obtain from the data connector card on the Data Connections page. This parameter replaces the datasourceCode parameter. Use connectId going forward. When creating a data query knowledge base, you must also specify the table parameter. | conn_mysql_xxx_xxx |
| channelType | string | No | This parameter is not available yet. Do not specify it. | connector |
| RerankMode | string | No | Specifies the instruction intervention mode of the reranking model to determine its scoring preference. Valid values:
Valid values:
| qa |
| RerankInstruct | string | No | Provides a natural language instruction to fine-tune the behavior of the reranking model. This parameter takes effect only when rerank_mode is set to "custom". |
Response elements
Element | Type | Description | Example |
|---|---|---|---|
object | Schema of Response | ||
| Code | string | Error status code | |
| Data | object | The business data returned when the request is successful. | |
| Id | string | The knowledge base ID, also known as Keep this value safe. It will be used for all subsequent API operations related to this knowledge base. | jkurxhxxxx |
| Message | string | Error message | |
| RequestId | string | Request ID | 17204B98-xxxx-4F9A--2446A84821CA |
| Status | string | The status code returned by the interface. | "200" |
| Success | boolean | Indicates whether the request is successful. Possible values:
| true |
Examples
Success response
JSON format
{
"Code": "",
"Data": {
"Id": "jkurxhxxxx"
},
"Message": "",
"RequestId": "17204B98-xxxx-4F9A--2446A84821CA",
"Status": "\"200\"",
"Success": true
}
Error codes
Visit the Error Center to view more error codes.
Release notes
For more information, see Change details.