Create a knowledge base and add data sources¶
Create a knowledge base and submit the initial data source at the same time. A successful request only means that the source record and processing task have been created, but does not mean that the content is retrievable.
POST https://moi.matrixorigin.cn/newmoi/semantic-models/create-with-sources
Preparation before calling¶
First confirm the source: Catalog tables, Catalog files and batch selection can only reference data already in the Catalog; local files first obtain the file ID through Upload local file. Prepare a personal access token and target workspace ID that has access to the target workspace and permission to create a knowledge base.
The example below uses:
$AI_STUDIO_API_KEY: The actual personal access token, passed through theX-API-KeyHeader.$WORKSPACE_ID: The ID of the workspace to create the knowledge base, passed through theX-Workspace-IDHeader.
For direct sources, provide fields by source type:
Source type |
Required fields |
|---|---|
|
|
|
|
|
The uploaded |
source_selections can select only within a Catalog Database or Volume; do not pass data sources outside Catalog.
Request example¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/semantic-models/create-with-sources" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"name": "$KNOWLEDGE_BASE_NAME",
"sources": [
{
"source_type": "catalog_table",
"table_id": $TABLE_ID
}
]
}'
Request body¶
In addition to the knowledge base name, submit a direct source or source selection.
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
The name of the knowledge base. |
|
string |
No |
Knowledge base description. |
|
boolean |
No |
Whether to enable image indexing at creation time. |
|
object |
No |
File index extension configuration; the service will complete the fixed index settings required to create the knowledge base. |
|
object[] |
No |
Source added directly. |
|
string |
Conditionally required |
Source type. |
|
integer |
Conditionally required |
|
|
string |
Conditionally required |
The file ID of the file source. |
|
string |
Conditionally required |
|
|
integer |
Conditionally required |
|
|
object[] |
No |
Rules for selecting sources by database or volume. |
|
string |
Conditionally required |
|
|
integer |
Conditionally required |
Catalog Database ID of |
|
integer |
Conditionally required |
Catalog Volume ID of |
|
boolean |
Yes |
|
|
array |
Conditionally required |
Catalog table IDs explicitly selected when |
|
array |
Conditionally required |
Catalog file IDs explicitly selected when |
|
array |
No |
Catalog table IDs to exclude when |
|
array |
No |
Catalog file IDs to exclude when |
In field paths, [] means each item in an array. For example, sources[].source_type is the source_type field of each item in sources.
Successful response¶
On success, returns 201, which contains the new knowledge base, the created sources, and the processing of jobs. Save the origin’s row_id, which is used by subsequent origin, segmentation, and governance interfaces. The creation of jobs does not mean that source processing is complete.
{
"code": "OK",
"msg": "OK",
"data": {
"model": {
"id": 401,
"name": "product_docs",
"source_counts": {
"files": 0,
"tables": 0,
"total": 0
},
"created_at": 1735632000,
"updated_at": 1735632000
},
"data_domain": {
"model_id": 401,
"catalog_id": 10,
"database_id": 20,
"raw_volume_id": 30,
"processed_volume_id": 31,
"ensure_status": "ready",
"last_checked_at": 1735632000
},
"sources": [
{
"row_id": "src_01",
"source_type": "table",
"model_id": 401,
"resource_id": "123",
"ingest_status": "pending",
"effective_enabled": true
}
],
"jobs": [
{
"job_id": "job_01",
"source_id": "src_01",
"model_id": 401,
"job_type": "ingest",
"job_status": "pending",
"idempotency_key": "idem_01",
"retry_count": 0
}
]
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
object |
Snapshot of the new knowledge base. |
|
integer |
New knowledge base ID. |
|
object |
The data field parsed for this knowledge base; contains the Catalog, database, and volume IDs, and the check status of the data field. |
|
string |
The current guarantee status of the data field. |
|
object[] |
Created source record. |
|
string |
Provenance record ID, this value is used by subsequent provenance, segmentation, and governance interfaces. |
|
string |
Source type: |
|
string |
Source processing status; |
|
boolean |
The current enabled status. |
|
object[] |
The processing task created for the source. |
|
string |
Processing task ID. |
|
string |
The associated source ID. |
|
string |
Processing task type. |
|
string |
The current status of the processing task. |
|
string |
The idempotent key for this processing task. |
|
integer |
The current number of recorded retries. |
In field paths, [] means each item in an array. For example, data.sources[].row_id is the row_id field of each item in data.sources.
Error response¶
{
"code": "ErrParamInvalid",
"msg": "name is required",
"data": null
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
The request body is invalid, |
Correct the request body and try again. |
|
|
The API Key is invalid or has expired. |
Check API Key. |
|
|
The caller does not have permission to create the knowledge base or read the selected source. |
Check workspace and source object authorization. |
|
|
Repository or source status of service denial conflict. |
Adjust requests after reading existing objects. |
|
|
The service failed to create the knowledge base or submit source task. |
Keep the desensitized response information and try again. |
Follow-up operations¶
Use data.jobs[].job_id Query data processing tasks to confirm that source processing is completed before using the knowledge base.