Create semantic entries

Create semantic configuration entries to supplement data tables with field, metric, correlation, and business rule definitions.

HTTP
POST $CLOUDSIGMA_API_BASE/semantic-models/{model_id}/entries

Before you call

Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region. First query the knowledge base list to obtain the knowledge base ID. Prepare a personal access token and target workspace ID that can access the target workspace.

Request body

Replace $MODEL_ID, $CLOUDSIGMA_API_KEY, $WORKSPACE_ID in the example with actual values.

Shell
curl -X POST "$CLOUDSIGMA_API_BASE/semantic-models/$MODEL_ID/entries" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
  "kind": "metric",
  "key": "gmv",
  "tables": [
    "orders"
  ],
  "spec": {
    "name": "GMV",
    "metric_type": "aggregate",
    "aggregation": "SUM",
    "field": "amount",
    "source_table": "orders"
  }
}'

Parameter

Type

Required

Description

model_id

integer

Yes

The knowledge base ID for which the semantic entry is to be created.

Request body

Field

Type

Required

Description

domain

string

No

semantic domain. When creating and updating, omitting this field defaults to nl2sql. Values: empty string, nl2sql, rag.

kind

string

Yes

The entry type determines the structure of spec. Values: metric, table_description, field_description, business_rule, constraint, relationship, standard_qa, dynamic_query.

key

string

Yes

The entry’s reference key. Cannot be empty.

tables

array of string or null

No

The associated table name, not the Catalog table ID.

spec

object

Yes

Fill in the configuration listed in this section according to kind, and the content must comply with the verification rules of this type.

name

string

Yes

Name.

synonyms

array of string or null

No

Synonyms.

description

string

No

Description.

source_table

string

No

Source table.

metric_type

string

Yes

Indicator type.

aggregation

string

No

Aggregation functions.

field

string

No

field.

filter

object or null

No

Filter tree.

filter.type

string

No

type.

filter.op

string

No

Conditional connection method.

filter.children

array of object or null

No

sub-condition.

filter.field

string

No

field.

filter.operator

string

No

Comparison operators.

filter.value

any

No

Value.

multiplier

number

No

Multiplier.

formula

object or null

No

Formula tree.

formula.type

string

No

type.

formula.key

string

No

Key.

formula.value

number or null

No

Value.

formula.left

object or null

No

left operand.

formula.right

object or null

No

Right operand.

type

string

No

type.

op

string

No

Conditional connection method.

children

array of object or null

No

sub-condition.

operator

string

No

Comparison operators.

value

any

No

Value.

key

string

No

Key.

value

number or null

No

Value.

left

object or null

No

left operand.

right

object or null

No

Right operand.

table

string

No

Table name.

description

string

Yes

Description.

column

string

Yes

Column name.

nl2sql_enabled

boolean or null

No

Whether to enable natural language conversion to SQL.

rule

string

Yes

Business rules.

files

array of string or null

No

File configuration.

migration_status

string

No

Migration status.

filter

object

Yes

Filter tree.

left_table

string

Yes

Table left.

right_table

string

Yes

Right table.

join_type

string

No

Connection type.

conditions

array of object or null

No

Connection conditions.

conditions[].operator

string

No

Comparison operators.

conditions[].left

string

No

left operand.

conditions[].right

string

No

Right operand.

left

string

No

left operand.

right

string

No

Right operand.

question

string

Yes

question.

similar_questions

array of string or null

No

Similar questions.

sql

string

No

SQL text.

answer

string

No

answer.

usage_mode

string

No

Usage.

query_key

string

No

Query key.

sql

string

Yes

SQL text.

handling

string

No

processing method.

domain supports nl2sql and rag. When creating and updating, omit domain and default to nl2sql. You can filter by domain when querying the list.

  • nl2sql supports the 8 entries listed in the following table.

  • rag only supports business_rule and standard_qa.

  • standard_qa Fill in a single read-only SQL in nl2sql, and fill in answer in rag.

domain in the response is the domain to which the entry actually belongs.

Entries are uniquely keyed by a combination of domain, kind, and the normalized key. Imports and substitutions are also checked against this combination.

relationship must be filled with left_table, right_table and non-empty conditions. join_type defaults to left and supports left, inner, right and full. The conditional operator defaults to equals. For other operators, see the field description.

The combination requirements for each type of spec are as follows:

Type

Configuration requirements

metric

metric_type is aggregate or derived. aggregate must fill in field and aggregate functions (SUM, AVG, MIN, MAX, COUNT). derived The formula tree must be filled in. source_table can be omitted and the first item of tables is used. The selected table must belong to the knowledge base.

table_description

Fill in non-empty description. You can omit table and use the first item of tables. The selected table must belong to the knowledge base.

field_description

Fill in non-empty column. table can be omitted and the first item of tables used. When nl2sql_enabled is omitted or null is filled in, true is used by default.

business_rule

Fill in non-empty rule. files is an optional file reference.

constraint

Fill in non-empty filter. Nodes at each level must comply with the verification rules of the filter tree.

relationship

left_table and right_table must belong to the knowledge base, and conditions cannot be empty. join_type defaults to left and supports left, inner, right, and full. Each condition must be filled with non-empty left and right. operator defaults to equals and supports equals, not_equals, greater_than, greater_than_or_equal, less_than, and less_than_or_equal.

standard_qa

Fill in non-empty question. usage_mode defaults to reference, and force is also supported. nl2sql must fill in the single read-only sql, rag must fill in the non-empty answer.

dynamic_query

sql must be a single read-only statement, and the length of UTF-8 does not exceed 16 KiB. handling defaults to delegated_analysis, and direct_context is also supported.

The type of the filter tree is group or condition. group uses and / or with non-null children.

condition.operator supports equals, not_equals, in, not_in, contains, between, is_null, is_not_null. In addition to the two null value judgment operations, value must be provided. Explicit null is also a supplied value.

type of the formula tree supports metric_ref, constant, add, subtract, multiply and divide.

  • metric_ref: Use non-null key to reference an existing indicator, and the indicator reference cannot form a cycle.

  • constant: value that is not null must be filled in, 0 is allowed.

  • Binary operations: left and right are required.

children is an array of nodes with the same structure. Fill in recursively according to the field definitions in this section.

left and right are formula nodes with the same structure. Fill in recursively according to the field definitions in this section.

Successful response

JSON
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 501,
    "domain": "nl2sql",
    "kind": "metric",
    "key": "gmv",
    "tables": [
      "orders"
    ],
    "spec": {
      "name": "GMV",
      "metric_type": "aggregate",
      "aggregation": "SUM",
      "field": "amount",
      "source_table": "orders"
    },
    "created_at": 1735632000,
    "updated_at": 1735632000
  }
}

Field

Type

Description

data.id

integer

New entry ID.

data.domain

string

The actual semantic domain of the entry. Value: nl2sql, rag.

data.kind

string

The type of entry created. Values: metric, table_description, field_description, business_rule, constraint, relationship, standard_qa, dynamic_query.

data.key

string

The entry’s reference key.

data.tables

array of string

Association table name. Can be omitted if not set.

data.spec

object

The configuration,structure of the entry depends on data.kind. For field descriptions, see the configuration table of each type on this page.

data.sql_preview

string

SQL preview.

data.created_at

integer

Unix timestamp.

data.updated_at

integer

Unix timestamp.

Error response

JSON
{
  "code": "ErrParamInvalid",
  "msg": "invalid semantic entry",
  "data": null
}

Field

Type

Description

code

string

error code.

msg

string

Error description.

data

null

null on error.

Last updated on