Add data source¶
Append data sources to existing knowledge base. A successful request does not mean that the source has completed parsing or indexing.
POST https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/sources
Preparation before calling¶
First check whether the data source has been added and remove duplicates; when selecting in batches by database or volume, first preview the data source to be added]. Prepare a personal access token and target workspace ID that has access to the target workspace.
The example below uses:
$AI_STUDIO_API_KEY: The actual personal access token, passed through theX-API-KeyHeader.$WORKSPACE_ID: Target workspace ID, passed throughX-Workspace-IDHeader.$MODEL_ID: The knowledge base ID of the data source to be appended.
For direct sources, provide fields by source type:
Source type |
Required fields |
|---|---|
|
|
|
|
|
The file ID returned by Upload local file and the original |
Range selection supports Catalog Databases and Volumes only. Do not use source_selections to add data sources outside Catalog.
Request example¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/sources" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"sources": [
{
"source_type": "catalog_file",
"file_id": "$FILE_ID",
"volume_id": $VOLUME_ID
}
]
}'
Path parameters¶
Parameters |
Type |
Description |
|---|---|---|
|
integer |
The knowledge base ID of the data source to be appended. |
Request body¶
Field |
Type |
Required |
Description |
|---|---|---|---|
|
array |
Yes |
The source to add. |
|
string |
Yes |
Source type, such as |
|
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 selecting all. |
|
array |
No |
Catalog file IDs to exclude when selecting all. |
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¶
Returns 200 on success. Save the row_id for each source and confirm the actual processing results with the processing task status.
{
"code": "OK",
"msg": "OK",
"data": {
"data_domain": {
"model_id": 401,
"catalog_id": 10,
"database_id": 20,
"raw_volume_id": 30,
"processed_volume_id": 31,
"ensure_status": "ready"
},
"sources": [
{
"row_id": "src_01",
"source_type": "file",
"model_id": 401,
"resource_id": "file_01",
"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 |
The data field of the knowledge base and its guaranteed status. |
|
object[] |
Created source record. |
|
string |
Source record ID. |
|
string |
Source type. |
|
string |
Source resource ID. |
|
string |
Processing status; |
|
boolean |
Current actual effective status. |
|
object[] |
New processing task. |
|
string |
Task ID. |
|
string |
Associated source ID. |
|
string |
Task type. |
|
string |
Current task status. |
|
string |
Task idempotent key. |
|
integer |
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": "invalid source request",
"data": null
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
Invalid source type, file/table ID, or volume ID. |
Try again after providing the required fields by source type. |
|
|
The API Key is invalid or has expired. |
Check API Key. |
|
|
The caller does not have permission to update the knowledge base or read the source object. |
Check workspace and object authorization. |
|
|
The knowledge base or source object does not exist or is not visible to the current caller. |
Reconfirm ID. |
|
|
Service denied conflicting source write. |
Adjust requests after checking for existing sources. |
|
|
The service failed to create the source or process the 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.