Skip to main content

Create Knowledge Base and Import

Create a Knowledge Base and import files in a single call.

POST
/api/v1/indices/rag/index/create_v2
cURL
curl -X POST "https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/indices/rag/index/create_v2" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-knowledge-base",
    "description": "Knowledge Base description",
    "structureType": "unstructured",
    "sinkType": "DEFAULT",
    "sourceType": "DATA_CENTER_FILE",
    "embeddingModelName": "text-embedding-v4",
    "chunkSize": 600,
    "docIds": ["file_abc123", "file_def456"],
    "dataSources": [{"sourceType": "DATA_CENTER_FILE"}]
  }'
{
  "code": "Success",
  "status_code": 200,
  "success": true,
  "message": "success",
  "data": {
    "pipelineId": "your_pipeline_id",
    "ingestionId": "ing_abc123",
    "status": "PENDING",
    "created_at": 1783657930436,
    "updated_at": 1783657930436
  },
  "request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "SUCCESS"
}
Create a Knowledge Base and import files in a single call; you can also enable Wiki at creation time.
The file ID parameter is docIds — not file_ids or fileIds. However, the validation error message uses the internal name file_ids.
Wiki currently supports only auto-update mode: when enabling Wiki, wikiAutoUpdate must be true. Wiki requires a Flagship knowledge base (pipelineCommercialType=enterprise, with pipelineCommercialCu) and knowledgeScene=basic_document_qa. wikiConfig.extraction.synthesisModelId and extractionGranularity are required; granularity is one of focused / standard / exhaustive.If Wiki configuration validation fails, the Knowledge Base is not created. Otherwise, it is created first and Wiki is enabled asynchronously. Success only means the enable request was accepted. Enabling and generation have no status-query endpoint; confirm the search_type=wiki service is published via List Agents before a trial retrieval.

Import parameters and synchronization boundaries

description is optional, allows 0-500 characters, and defaults to an empty string. The top-level sourceType is required and determines which import parameters are validated:
sourceTypeRequired import parameters
DATA_CENTER_FILEdocIds; categoryIds cannot replace it
DATA_CENTER_CATEGORYcategoryIds; docIds cannot replace it
DATA_CENTER_STRUCTURED_TABLEtableIds and columns
dataSources is optional, and its sourceType cannot replace the top-level field. Importing an existing data-center table does not require connectId, datasourceCode, database, or table. These fields are for custom database sources only; connectId + table cannot replace tableIds.
  • createIndexType and channelType are not available. Do not pass them. Console network requests use an internal gateway and console-specific parameters; do not copy them to call the public API. In console payloads, dataType maps to structureType, and cornerstoneParam is internal, not a public parameter.
  • Passing dataSync:true does not enable the console's automatic knowledge-index synchronization. After adding files to a category, submit an import job to append the category again.
  • Category imports do not remove Knowledge Base documents deleted from the dataset. Re-uploading the same file name may produce a new file ID, not replace the old document. Delete both the dataset file and the Knowledge Base document; if the dataset file remains, the next category import will import it again.
  • metaExtractColumns supports up to five fields, only at creation; it cannot be added later through the update API. enableSearch and enableLlm differ from metadata_filter at query time.
Omitting the top-level sourceType fails even if dataSources is provided and may leave an empty Knowledge Base with the same name. Query the Knowledge Base list and check and clean up before retrying to avoid duplicate empty Knowledge Bases.

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 types have a fixed scenario filled in automatically. The API allows both fields to be omitted and applies defaults based on structureType. Supply the pair only when a non-default type or scenario is needed.
knowledgeTypeConsole labelstructureTypeAvailable knowledgeScene
documentDocument Searchunstructuredbasic_document_qa (basic document Q&A)
visual_perception_qa (visual understanding, rich text documents)
lite_document_qa (express Q&A)
tableData Querystructuredbasic_table_qa (fixed)
imageImage Q&Aunstructuredimage_qa (fixed)
multimediaAudio and Video Searchunstructuredbasic_multimedia_qa (fixed)
  • An incompatible knowledgeType and structureType pair returns knowledgeType and structureType do not match. A knowledgeScene that does not belong to the selected type returns knowledgeType and knowledgeScene do not match.
  • lite_document_qa (express Q&A) requires sinkType to be BUILT_IN. Using the default DEFAULT returns Lite Rag only supports BUILT_IN sink type.
  • visual_perception_qa and image_qa must specify a multimodal embedding model through multimodalEmbeddingModelName (for example qwen3-vl-embedding), otherwise the request returns invalid multi embedding model.
  • The document type also has a visual_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.
Example request body for image Q&A:
{
  "name": "image-kb",
  "description": "Image Q&A Knowledge Base",
  "structureType": "unstructured",
  "knowledgeType": "image",
  "knowledgeScene": "image_qa",
  "sinkType": "BUILT_IN",
  "sourceType": "DATA_CENTER_FILE",
  "multimodalEmbeddingModelName": "qwen3-vl-embedding",
  "docIds": ["file_abc123"],
  "dataSources": [{ "sourceType": "DATA_CENTER_FILE" }]
}

Error codes

This endpoint may return the following error codes; for detailed triggers and message, see the error reference.
codestatus_codeTrigger
InvalidParameter400Type and scene not supplied together or mismatched; ultra-fast Q&A / multimodal parameter constraints not met; wikiAutoUpdate missing or not true when enabling Wiki
Index.InvalidParameter400description exceeds 500 characters: Required parameter(description length range[1-500]) missing or invalid, please check the request parameters. Omitted or empty strings are valid
Index.InvalidParameter400Missing or empty docIds when sourceType=DATA_CENTER_FILE; the message names file_ids. categoryIds alone is not a substitute
Index.InvalidParameter400Missing categoryIds when sourceType=DATA_CENTER_CATEGORY; the message names source_ids. Providing only docIds or using the parameter name source_ids also fails
Index.InvalidParameter400Missing top-level sourceType; the message names data_sources. Providing dataSources does not prevent this error
Index.FileEmptyError400A file ID in docIds does not exist: fetch empty file list from data center.
WikiEditionNotSupported400The knowledge base is not enterprise when enabling Wiki (unspecified specification is treated as Standard)
WikiSceneNotSupported400knowledgeScene is not basic_document_qa when enabling Wiki
WikiConfigInvalid400An invalid Wiki configuration key was provided; locate it by the field name in message

Authorizations

string
header
required

DashScope API Key, obtained from the API Key page in the console.

Body

application/json
object

Response

200-application/json
string

Response code. Success on success.

integer

HTTP status code.

boolean

Whether the request succeeded. true on success.

string

Response message. success on success.

string

Unique request identifier. Include this ID when reporting an issue.

string

Request status. SUCCESS on success.

object