Create semantic entries¶
Create semantic configuration entries to supplement data tables with definitions of fields, indicators, associations, and business rules.
POST https://moi.matrixorigin.cn/newmoi/semantic-models/{model_id}/entries
Preparation before calling¶
First query the knowledge base list to obtain the knowledge base ID. 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: ID of the knowledge base for which the semantic entry is to be created.
Request example¶
curl -X POST "https://moi.matrixorigin.cn/newmoi/semantic-models/$MODEL_ID/entries" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H 'Content-Type: application/json' \
-d '{
"kind": "metric",
"key": "total_rows",
"tables": ["orders"],
"spec": {
"expr": "COUNT(*)"
}
}'
Path parameters¶
Parameters |
Type |
Description |
|---|---|---|
|
integer |
The knowledge base ID for which the semantic entry is to be created. |
Request body¶
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Entry type; it determines the structure of |
|
string |
Yes |
A stable reference key within the knowledge base. |
|
array[string] |
No |
The associated table name, not the Catalog table ID. |
|
object |
Yes |
A type-specific configuration object; fields are determined by |
key must be unique in the same knowledge base; tables can be omitted when not passed. When passed in, each name must be a configured table of the knowledge base.
spec configuration¶
In the same entry, first select kind and then submit the corresponding spec field according to the table below.
Console Name |
|
|
Purpose |
|---|---|---|---|
Dimension column |
|
|
Describes the fields used for grouping and filtering. |
Fact column |
|
|
Describes the fact fields that can participate in the calculation. |
Business indicators |
|
|
Define the indicator calculation expression. |
Table association |
|
|
Define the association of two configured tables. |
Column preferences |
|
|
Specify recommended and non-recommended columns. |
Named filter |
|
|
Define a reusable filter expression. |
Default constraints |
|
|
Defines the default filter constraints for the column; only supports configuration through API. |
Standard Q&A |
|
|
Save high-frequency questions and their SQL. |
Terminology explanation |
|
|
Define business terms and their meanings. |
Rule injection |
|
|
Apply business rules at the specified stage. |
SQL result set |
|
|
Save SQL result set definition. |
[] after a type means an array. For example, string[] is an array of strings.
Type-specific constraints¶
|
Field or condition |
Constraint |
|---|---|---|
|
|
The array cannot be empty; each item must contain a non-empty |
|
|
Neither value can be empty, and cannot be the same without case sensitivity. |
|
|
Contains at least one non-empty string; optional |
|
|
The array cannot be empty; each item can only be |
|
|
|
sql_resultset optional configuration¶
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
No |
Can only be |
|
integer |
No |
Cannot be less than |
|
integer |
No |
Cannot be less than |
|
integer |
No |
Range is |
|
object |
No |
SQL expansion configuration. Both |
|
string |
Conditionally required |
No more than 16 KiB; |
|
array[string] |
Conditionally required |
Quantity is |
|
object |
No |
Retrieve configuration. |
|
boolean |
No |
When set to |
|
string |
Conditionally required |
|
Successful response¶
Return 201 on success; save data.id for subsequent updates and deletions.
{
"code": "OK",
"msg": "OK",
"data": {
"id": 501,
"kind": "metric",
"key": "total_rows",
"tables": ["orders"],
"spec": {
"expr": "COUNT(*)"
},
"created_at": 1735632000,
"updated_at": 1735632000
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
integer |
New entry ID. |
|
string |
The type of entry created. |
|
string |
Stable reference key within the knowledge base. |
|
array[string] |
Association table name; may be omitted if not set. |
|
object |
Saved type-specific configuration object; fields determined by |
|
integer |
Unix timestamp. |
|
integer |
Unix timestamp. |
Error response¶
{
"code": "ErrParamInvalid",
"msg": "invalid semantic entry",
"data": null
}
Common HTTP errors¶
HTTP status code |
error code |
Common causes |
Recommended actions |
|---|---|---|---|
|
|
|
Fix the complete entry definition and try again. |
|
|
The API Key is invalid or has expired. |
Check API Key. |
|
|
The caller does not have permission to create entries. |
Check workspace and object authorization. |
|
|
The knowledge base does not exist or is not visible. |
Reconfirm |
|
|
A conflicting entry key already exists in the same knowledge base. |
Use a different |
|
|
The service failed to create the entry. |
Keep the desensitized response information and try again. |
Follow-up operations¶
Use data.id Update semantic entries or Delete semantic entries.