Import semantic entries¶
Batch import semantic entries into a knowledge base without semantic entries.
POST https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/import
Preparation before calling¶
First query the knowledge base list to obtain the knowledge base ID, and confirm that the target knowledge base has no semantic entries. 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: Receives the knowledge base ID of the imported entry.
Request example¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/import" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"entries": [
{
"kind": "metric",
"key": "total_rows",
"spec": {
"expr": "COUNT(*)"
}
}
]
}'
Path parameters¶
Parameters |
Type |
Description |
|---|---|---|
|
integer |
The knowledge base ID to receive the imported entry. |
Request body¶
The request body is an array of entries; each contains kind, key, optionally tables, and spec.
Field |
Type |
Required |
Description |
|---|---|---|---|
|
object[] |
Yes |
The entry to import; cannot be empty. The target knowledge base cannot already have semantic entries. |
|
string |
Yes |
Entry type; it determines the structure of |
|
string |
Yes |
A stable reference key within the knowledge base; cannot be repeated in the same request. |
|
array[string] |
No |
The name of the association table. |
|
object |
Yes |
A type-specific configuration object. Its fields and constraints are the same as Create semantic entry. |
In field paths, [] means each item in an array. For example, entries[].kind is the kind field of each item in entries.
Successful response¶
Returns 200 on success. imported is the number of writes this time; then list the entries and run verification, not just checking the HTTP status.
{
"code": "OK",
"msg": "OK",
"data": {
"imported": 1,
"model_id": 401
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
integer |
The number of entries imported and written this time. |
|
integer |
Receives the imported knowledge base ID. |
Error response¶
{
"code": "ErrConflict",
"msg": "duplicate semantic entry key",
"data": null
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
|
Resubmit the entire batch after correcting each entry; if the target already has entries, use a knowledge base without semantic entries instead. |
|
|
The API Key is invalid or has expired. |
Check API Key. |
|
|
The caller does not have import permissions. |
Check workspace and object authorization. |
|
|
The knowledge base does not exist or is not visible. |
Reconfirm |
|
|
There is a duplicate |
Resubmit after removing duplicates. |
|
|
The service failed to import the entry. |
Keep the desensitized response information and try again. |
Follow-up operations¶
Query semantic entries and Verify semantic entries to confirm the import results.