Create a Knowledge Base and import files in a single call (merges CreateIndex and SubmitIndexJob). On success, the response returns the Knowledge Base ID (data.pipelineId) and the import job ID (data.ingestionId).
Prerequisites
Get an API key and a workspace ID, and configure authentication first. See API overview and Authentication.
Endpoint
POST /api/v1/indices/rag/index/create_v2
Create a Knowledge Base and import files in a single call (merges CreateIndex and SubmitIndexJob).
Request body
Basic parameters
| Field | Required | Type | Description |
|---|---|---|---|
name | Yes | string | Knowledge Base name, 1-20 characters. Must be unique within the workspace. |
description | No | string | Knowledge Base description, 0-500 characters. Empty by default. |
structureType | Yes | string | Structure type: unstructured or structured. Use unstructured for document, image, and multimedia, and structured for table. |
knowledgeType | No | string | Knowledge Base type: document (Document Search), table (Data Query), image (Image Q&A), or multimedia (Audio and Video Search). Supply together with knowledgeScene or omit both. When both are omitted, the system applies defaults based on structureType. See the scenario constraints below. |
knowledgeScene | No | string | Usage scenario. The value depends on knowledgeType and must be supplied together with it or omitted together. lite_document_qa requires sinkType=BUILT_IN. visual_perception_qa and image_qa require multimodalEmbeddingModelName. document also accepts visual_document_qa, but the console no longer exposes this option. |
sinkType | Yes | string | Vector storage type. DEFAULT and BUILT_IN both use platform-managed vector storage. ADB means AnalyticDB for PostgreSQL and requires sinkInstanceId and sinkRegion. lite_document_qa supports only BUILT_IN. |
sourceType | Yes | string | Import mode. DATA_CENTER_FILE requires docIds; DATA_CENTER_CATEGORY requires categoryIds; DATA_CENTER_STRUCTURED_TABLE requires tableIds and columns. The top-level sourceType determines which parameters are validated; the identically named field in dataSources cannot replace it. |
embeddingModelName | No | string | Embedding model, such as text-embedding-v3, text-embedding-v4, or qwen3.7-text-embedding. For basic document Q&A, the default is text-embedding-v3 when omitted. |
multimodalEmbeddingModelName | Conditional | string | Multimodal embedding model, such as qwen3-vl-embedding. Required when knowledgeScene is visual_perception_qa or image_qa. Missing or invalid values return invalid multi embedding model. Optional for audio and video search. |
docIds | Conditional | array<string> | Required when sourceType=DATA_CENTER_FILE. Providing only categoryIds is not a substitute. Values come from the fileId returned after registering a file with addFile, or query existing files through listFile. We recommend importing no more than 10,000. The parameter name is docIds — not file_ids or fileIds. However, validation error messages use the name file_ids. |
categoryIds | Conditional | array<string> | Required when sourceType=DATA_CENTER_CATEGORY. Providing only docIds is not a substitute. Specifying category IDs imports all files under the corresponding categories. We recommend importing no more than 10,000. Obtain category IDs through listCategory. |
dataSources | No | array<object> | Optional data source configuration. Its sourceType sub-field does not replace the top-level sourceType in determining the import mode. If provided, keep it consistent with the top-level sourceType. |
pipelineCommercialType | No | string | Edition: standard (default) or enterprise. |
pipelineCommercialCu | Conditional | integer | Number of RCUs, 1-200. Required when pipelineCommercialType=enterprise; otherwise the request returns Required parameter(index_commercial_cu) missing or invalid. |
pipelineRetrieveRateLimitStrategy | No | string | Rate-limit strategy for dependent retrieval links, for enterprise only. Currently supports downgrade (use the lightweight retrieval link), which is also the default. |
Chunking and parsing parameters
| Field | Required | Type | Description |
|---|---|---|---|
chunkMode | No | string | Chunking mode. Default: auto. Supported values: length, page, regex, and h1 through h5 for the corresponding heading levels. |
chunkSize | No | integer | Chunk size in characters. Default for basic document Q&A: 500. Valid range: 1-6000. Recommended: 300-800. When set below 100, you must also set overlapSize to a smaller value. |
overlapSize | No | integer | Overlap between adjacent chunks in characters. Default: 100. Valid range: 0-1024. Must be smaller than chunkSize. The console field chunkOverlap is equivalent; either name can be used. |
separator | Conditional | string | Sentence separator. Required and effective only when chunkMode=regex, for example (?<=。). Not needed for other modes. |
enableHeaders | No | boolean | Whether to treat the first row of xlsx and xls files as a header and prepend it to each data chunk. Default: false. Enable only when the spreadsheet contains headers. |
metaExtractColumns | No | array<object> | Metadata extraction configuration with up to five fields. It takes effect only when the knowledge base is created and cannot be added later through the update API. For element fields, see Metadata extraction configuration. |
Retrieval and reranking parameters
| Field | Required | Type | Description |
|---|---|---|---|
enableRewrite | No | boolean | Whether to enable conversational query rewriting. Default for basic document Q&A: true. |
rerankModelName | No | string | Reranking model. Default for basic document Q&A: qwen3-rerank. Also supports qwen3-rerank-hybrid, gte-rerank, and gte-rerank-hybrid. The latter two will no longer be updated and are not recommended. |
rerankMinScore | No | number | Similarity threshold. Default for basic document Q&A: 0.01. Valid range: 0.01-1.00. |
rerankTopN | No | integer | Default number of results after reranking. Default: 5. Valid range: 1-20. When set at creation, it becomes the default for subsequent Retrieve calls and can be overridden by RerankTopN in a Retrieve request. |
sparseSimilarityTopK | No | integer | Keyword retrieval TopK. Default: 100. Valid range: 0-100. The sum of sparseSimilarityTopK and denseSimilarityTopK must not exceed 200. |
denseSimilarityTopK | No | integer | Vector retrieval TopK. Default: 100. Valid range: 0-100. The sum of sparseSimilarityTopK and denseSimilarityTopK must not exceed 200. For basic document Q&A, it must also be at least rerankTopN so that enough candidates are available. |
rerankMode | No | string | Instruction mode of the reranking model: qa (default), similar, or custom. |
rerankInstruct | No | string | Custom reranking instruction. Effective only when rerankMode=custom. |
Structured data and external storage parameters
| Field | Required | Type | Description |
|---|---|---|---|
tableIds | Conditional | array<string> | Table IDs required for Data Query Knowledge Bases. If multiple IDs are provided, only the first is used. Obtain IDs from the table list in Data Connection. |
columns | Conditional | array<object> | Column configuration required for Data Query Knowledge Bases. Each element contains name (column name), type (string, double, long, datetime, or image_url), isSearch (whether the column participates in retrieval, default true), and isRecall (whether the column participates in model responses, default true). |
connectId | No | string | Custom database connector ID, which replaces the legacy datasourceCode field and is used with table. Not required when importing an existing data-center table through tableIds, and connectId + table cannot replace the tableIds required by this endpoint. |
datasourceCode | No | string | Legacy data source code. Use connectId instead. Required only for a custom database source and used with database and table. |
database | No | string | Custom database name. Required only for a custom database source and used with datasourceCode or connectId and table. |
table | No | string | Custom table name. Required only for a custom database source and used with datasourceCode or connectId and database. |
sinkInstanceId | Conditional | string | AnalyticDB for PostgreSQL instance ID. Required when sinkType=ADB; otherwise the request returns Required parameter(db_instance_id) missing or invalid. |
sinkRegion | Conditional | string | Region of the AnalyticDB for PostgreSQL instance. Required when sinkType=ADB. |
- To create a Data Query Knowledge Base from an existing data-center table, the minimum parameter set is
sourceType=DATA_CENTER_STRUCTURED_TABLE,tableIds, andcolumns.connectId,datasourceCode,database, andtableare used only for custom database sources and are not required for this path. createIndexTypeandchannelTypeare not available. Do not pass them.- Browser network requests from the console use an internal console gateway and console-specific parameters. Their authentication, endpoints, and parameter contract differ from the public API. Use this page as the public API reference instead of copying console payloads.
- This endpoint does not support enabling the console's Automatically sync knowledge index feature through
dataSync; passingdataSync:truehas no effect. After new files are added to a category, call Submit import job to append the category again. Re-uploading a file with the same name in the dataset may create a new file ID and does not automatically replace the old document in the Knowledge Base. Appending does not delete documents that were removed from the dataset; delete files from the dataset and the Knowledge Base separately. - In console payloads,
dataTypemaps tostructureType, andcornerstoneParamis a console-internal field; neither is an independent public parameter of this endpoint.
Wiki configuration parameters
For a Flagship knowledge base (pipelineCommercialType=enterprise) with knowledge scene basic_document_qa, you can enable Wiki and the ontology knowledge graph while creating the knowledge base. For the feature and billing, see Wiki and Ontology Knowledge Graph.
| Field | Required | Type | Description |
|---|---|---|---|
wikiEnabled | Yes | boolean | Whether to enable Wiki while creating the knowledge base. Omitted or null means not enabled; set true to enable |
wikiAutoUpdate | Conditional | boolean | Wiki auto-update switch. Required when wikiEnabled is true; only auto-update mode is supported, so it must be true. Existing documents are submitted for generation automatically, and newly imported documents are submitted after import completes |
wikiConfig.extraction.synthesisModelId | Conditional | string | Wiki extraction model. Required, non-blank, and case-sensitive when enabling Wiki; one of qwen3.8-flash, qwen3.8-max, qwen3.7-plus |
wikiConfig.extraction.extractionGranularity | Conditional | string | Extraction granularity. Required when enabling Wiki, no default; one of focused, standard, exhaustive |
wikiConfig.extraction.contentInstructions | No | string | Wiki content generation requirements, controlling the emphasis of summaries, pages, and the home page. Length is counted in Unicode characters, up to 4000 |
wikiConfig.extraction.extractionInstructions | No | string | Wiki extraction focus, specifying the domain entities and concepts to prioritize. Length is counted in Unicode characters, up to 4000 |
When
wikiEnabled is true, wikiConfig is required and must include the extraction group. If Wiki configuration validation fails, the create request fails outright and the knowledge base is not created; if validation passes, the knowledge base is created first and Wiki is enabled asynchronously afterwards — a success response only means the enable request was accepted. On configuration validation failure, field names in message are snake_case. Enabling and generation are asynchronous with no status-query endpoint; confirm the search_type=wiki service is published via List Agents before a trial retrieval.Knowledge Base type and usage scenario
knowledgeType and knowledgeScene correspond to Knowledge Base Type and Usage Scenario in step 1 of the console creation wizard. They must be supplied together or omitted together — sending only one returns knowledgeType and knowledgeScene cannot be empty. When both are omitted, the system applies defaults based on structureType.
The console only offers a Usage Scenario choice for Document Search. The other three types have a fixed scenario that the console fills in automatically. When creating through the API, you may omit both fields and let the system apply defaults based on structureType. They are required as a pair only when you need a non-default type or scenario.
| knowledgeType | Console label | structureType | Available knowledgeScene |
|---|---|---|---|
document | Document Search | unstructured | basic_document_qa (basic document Q&A)visual_perception_qa (visual understanding, rich text documents)lite_document_qa (express Q&A) |
table | Data Query | structured | basic_table_qa (fixed) |
image | Image Q&A | unstructured | image_qa (fixed) |
multimedia | Audio and Video Search | unstructured | basic_multimedia_qa (fixed) |
- An incompatible
knowledgeTypeandstructureTypepair returnsknowledgeType and structureType do not match. AknowledgeScenethat does not belong to the selected type returnsknowledgeType and knowledgeScene do not match. lite_document_qa(express Q&A) requiressinkTypeto beBUILT_IN. Using the defaultDEFAULTreturnsLite Rag only supports BUILT_IN sink type.visual_perception_qaandimage_qamust specify a multimodal embedding model throughmultimodalEmbeddingModelName(for exampleqwen3-vl-embedding), otherwise the request returnsinvalid multi embedding model.- The
documenttype also has avisual_document_qa(rich media answers) scenario. The API still accepts this value, but the console no longer exposes it, so avoid it for new Knowledge Bases.
Metadata extraction configuration
metaExtractColumns generates metadata for documents when the knowledge base is created and its index is built. Each array element supports the following fields:
| Field | Required | Type | Description |
|---|---|---|---|
key | Yes | string | Metadata field name. It must be 1-50 characters long and contain only letters and underscores. |
desc | No | string | Chinese description of the metadata field, 0-1000 characters. The default value is empty. Chinese characters, letters, digits, underscores (_), hyphens (-), periods (.), and colons (:) are supported. |
type | Yes | string | Extraction method: constant, variable, custom_prompt (LLM), regular (regular expression), or keywords (keyword search). |
value | Yes | string | Extraction rule corresponding to type, as described in the following table. |
enableSearch | No | boolean | Whether the metadata field and its values participate in knowledge retrieval with the text chunk. Default: false. |
enableLlm | No | boolean | Whether the metadata field and its values are passed to the LLM as input for response generation. Default: false. |
type | value description | Example |
|---|---|---|
constant | A fixed value assigned to all files in the knowledge base. | meta_test |
variable | A file variable. file_name uses the file name, and cat_name uses the name of the category containing the file. | file_name |
custom_prompt | An entity description that guides the LLM to extract relevant information from each file. | The main product name in the document. Extract only one complete product name. |
regular | A regular expression used to match and extract document content. | StarHub X1 |
keywords | Preset keywords separated by commas. Only keywords that actually appear in the document are returned. | smartphone,battery life,water resistance |
name and docIds:
enableSearch and enableLlm serve different purposes from metadata_filter at query time. To filter documents by metadata when calling an application through the API, specify both pipeline_ids and metadata_filter in rag_options. For more information, see Application call parameters. After the index is built, inspect the actual extraction results in meta_extract_info through the List file details API.Request example
sourceType to DATA_CENTER_CATEGORY and pass categoryIds. You do not need docIds or dataSources:
pipelineCommercialType is omitted, the default is standard:
knowledgeType=image, knowledgeScene=image_qa, requires sinkType=BUILT_IN and a multimodal embedding model):
wikiEnabled=true; see Wiki configuration parameters):
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 when successful. |
status_code | integer | HTTP status code. |
success | boolean | Whether the request succeeded. true when successful. |
message | string | Response message. success when successful. |
request_id | string | Unique request identifier. Provide this ID when troubleshooting. |
status | string | Request status. SUCCESS when successful. |
data | object | Response data. Sub-fields: pipelineId (string, Knowledge Base ID; used as the knowledge base identifier in subsequent APIs), ingestionId (string, the import job ID for this request; track import progress through the Get Import Job Status endpoint), status (string, import job status; PENDING on successful creation), created_at (integer, Knowledge Base creation time as a Unix timestamp in milliseconds), updated_at (integer, last update time as a Unix timestamp in milliseconds). |
Error codes
| HTTP status code | Error code (code) | Description |
|---|---|---|
| 400 | Index.InvalidParameter | description exceeds 500 characters: Required parameter(description length range[1-500]) missing or invalid, please check the request parameters. |
| 400 | Index.InvalidParameter | docIds is missing or empty when sourceType=DATA_CENTER_FILE. This error occurs even if categoryIds is provided: Required parameter(file_ids) missing or invalid, please check the request parameters. |
| 400 | Index.InvalidParameter | categoryIds is missing when sourceType=DATA_CENTER_CATEGORY. This error occurs if only docIds is provided or the category parameter is incorrectly named source_ids: Required parameter(source_ids) missing or invalid, please check the request parameters. |
| 400 | Index.InvalidParameter | The top-level sourceType is missing. This error occurs even if dataSources is provided: Required parameter(data_sources) missing or invalid, please check the request parameters. |
| 400 | Index.FileEmptyError | A file ID in docIds does not exist: fetch empty file list from data center. |
| 401 | InvalidApiKey | Invalid or missing API key: Invalid API-key provided. |
| 400 | Index.WikiEditionNotSupported | The knowledge base is not Flagship when enabling Wiki (unspecified specification is treated as Standard) |
| 400 | Index.WikiSceneNotSupported | knowledgeScene is not basic_document_qa when enabling Wiki |
| 400 | Index.WikiConfigInvalid | Invalid Wiki configuration key, e.g. missing extraction group, missing or non-whitelisted synthesisModelId, invalid extractionGranularity, or over-length instructions; locate by the field name in message |
| 400 | Index.InvalidParameter | wikiAutoUpdate missing or not true when enabling Wiki |