Import semantic entries

Import semantic entries into the knowledge base in batches, with the option of appending or overwriting, and previewing before writing.

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

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, and confirm the existing semantic entries of the target knowledge base and the import method this time. 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/import" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
  "entries": [
    {
      "kind": "metric",
      "key": "total_rows",
      "spec": {
        "name": "GMV",
        "metric_type": "aggregate",
        "aggregation": "SUM",
        "field": "amount"
      }
    }
  ]
}'

Parameter

Type

Required

Description

model_id

integer

Yes

Receives the imported knowledge base ID.

Request body

Field

Type

Required

Description

format

string

No

Import format. Value: empty string, moi.knowledge.semantics.

schema_version

string

No

Semantic entry format version. Value: empty string, 1.3.

mode

string

No

processing mode. Values: empty string, append, overwrite.

dry_run

boolean

No

Is it a preview?

confirm_overwrite

boolean

No

Confirm coverage.

entries

array of object

Yes

For entries to be imported, existing entries are processed in append/overwrite mode. At least 1 items.

entries[].domain

string

No

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

entries[].kind

string

When the object is provided

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

entries[].key

string

When the object is provided

key. Cannot be empty.

entries[].tables

array of string or null

No

Table reference.

entries[].spec

object

When the object is provided

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

domain

string

No

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

kind

string

No

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

key

string

No

Key.

tables

array of string or null

No

Table reference.

spec

object

No

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.

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.

mode defaults to append, and overwrite is also supported. format defaults to moi.knowledge.semantics. schema_version supports empty string or 1.3.

The target knowledge base may already have entries. When overwriting, set confirm_overwrite to true. There is no need to confirm coverage during the preview. The service first verifies the complete set of entries, and then saves them in the selected mode after passing them.

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": {
    "imported": 1,
    "model_id": 401
  }
}

Field

Type

Description

data.imported

integer

The number of entries imported and written this time.

data.deleted

integer

Remove mark or quantity.

data.dry_run

boolean

Is it a preview?

data.model_id

integer

Receives the imported knowledge base ID.

Error response

JSON
{
  "code": "ErrConflict",
  "msg": "duplicate semantic entry key",
  "data": null
}

Field

Type

Description

code

string

error code.

msg

string

Error description.

data

null

null on error.

Last updated on