Docs Home
Viewing docs for
BYOCSelf-Managed

Model DDLs

On this page

This topic describes the data definition language (DDL) statements for registering, viewing, modifying, and deleting AI models.

Usage Notes

  • The system supports various large model services with OpenAI compatible interfaces.

CREATE MODEL

Register a Model

Run a CREATE MODEL command in the SQL editor to register a model.

Syntax

SQL
1CREATE [TEMPORARY] MODEL [catalog_name.][db_name.]model_name
2INPUT ( { <physical_column_definition> [, ...n] )
3OUTPUT ( { <physical_column_definition> [, ...n] )
4WITH (key1=val1, key2=val2, ...)
5
6<physical_column_definition>:
7  column_name column_type [COMMENT column_comment]
ClauseDescriptionKey parametersSchema requirementsExample
INPUTDefines the fields, field types, and field order of input data.column_name, column_type, COMMENTExactly one STRING field is required.INPUT (input_text STRING COMMENT 'User comment')
OUTPUTDefines the fields, field types, and field order of output data.column_name, column_type, COMMENTConstraints for different task types:- chat/completions: Exactly one STRING field is required.- embeddings: Exactly one ARRAY<FLOAT> field is required.OUTPUT (sentiment_label STRING COMMENT 'Sentiment label')
WITHSee Parameters.provider, endpoint, apiKey, modelNone.WITH ('provider'='openai', 'endpoint'='${ENDPOINT}', 'model'='gpt-4.1', 'apiKey'='${KEY}')

Examples

Completion Model

The following example registers a model for sentiment analysis using an OpenAI-compatible completion service. You can use a proxy to access the API if needed.

SQL
1CREATE MODEL sentiment_analysis_model
2INPUT (input STRING)
3OUTPUT (output STRING)
4WITH (
5  'provider' = 'openai',
6  'task' = 'completions',
7  'endpoint' = 'https://proxy.example.com/v1/chat/completions',
8  'apiKey' = '<your-api-key>',
9  'system_prompt' = 'Analyze the sentiment of the text and return only POSITIVE, NEGATIVE, or NEUTRAL.',
10  'model' = 'gpt-4.1'
11);

When you call this model, the following happens:

  1. You pass a string of text via the input column.
  2. The model sends this to the API with the system prompt.
  3. The model analyzes the text and responds with POSITIVE, NEGATIVE, or NEUTRAL.
  4. The result is returned in the output field.

Embedding Model

The following example registers an embedding model to convert text into numerical vectors.

SQL
1CREATE MODEL text_embedding_model
2INPUT (input STRING)
3OUTPUT (embedding ARRAY<FLOAT>)
4WITH (
5  'provider' = 'openai',
6  'endpoint' = 'https://api.example.com/v1/chat/embeddings',
7  'apiKey' = '<your-api-key>',
8  'model' = 'text-embedding-v3'
9);

These embeddings are useful for:

  • Semantic search: Find relevant documents based on meaning rather than keyword matches.
  • Duplicate detection: Identify semantically identical entries.
  • Text clustering: Automatically group similar documents.
  • Recommendation systems: Suggest items based on content similarity.
  • Anomaly detection: Find unusual or unexpected text entries.

Parameters

General

ParameterDescriptionData typeRequiredDefault valueNote
providerThe model service provider.StringYesNoneSet to openai for OpenAI-compatible services.
endpointThe API endpoint for chat, completions, or embeddings.StringYesNoneRefer to your service's API documentation for the correct endpoint.
api-keyThe API key used to access the model service.StringYesNoneIn VERA Engine 4.1, use apiKey.
max-context-sizeThe maximum context length in a single request.IntegerNoNoneSupported in VERA Engine 4.3 and later.
context-overflow-actionSpecifies how to handle a context exceeding the limit.StringNotruncated-tailSupported in VERA Engine 4.3 and later. See Context Overflow Handling for more information.

chat/completions

ParameterDescriptionData typeRequiredDefault value
modelThe model to call (e.g., gpt-4.1).StringYesNone
system-promptThe system prompt for the request.StringYes"You are a helpful assistant."
temperatureControls the randomness of the output (0 to 2).FloatNoNone
top-pSpecifies cumulative probability for sampling.FloatNoNone
stopThe stop sequence string.StringNoNone
max-tokensMaximum length of generated texts.IntegerNoNone

embeddings

ParameterDescriptionData typeRequiredDefault valueNote
modelThe model to call.StringYesNone
dimensionControls the output vector dimension.IntegerNo1024Valid values: 1024, 768, 512.

View Models

Use the following commands to view information about registered models.

  • Show registered models:
SQL
1SHOW MODELS [ ( FROM | IN ) [catalog_name.]database_name ];
  • Show model registration statement:
SQL
1SHOW CREATE MODEL [catalog_name.][db_name.]model_name;
  • Show model schema:
SQL
1DESCRIBE MODEL [catalog_name.][db_name.]model_name;

Modify Models

Use the ALTER MODEL command to modify an existing model.

SQL
1ALTER MODEL [IF EXISTS] [catalog_name.][db_name.]model_name {
2  RENAME TO new_model_name
3  SET (key1=val1, ...)
4  RESET (key1, ...)
5}

Examples

  • Rename a model:
SQL
1ALTER MODEL m RENAME TO m1;
  • Modify a parameter:
SQL
1ALTER MODEL m SET ('endpoint' = 'https://new-endpoint.example.com');
  • Reset a parameter:
SQL
1ALTER MODEL m RESET ('endpoint');

Context Overflow Handling

VERA Engine 4.3 introduces configurable strategies to handle inputs that exceed an AI model's maximum context window. You can define these strategies using the max-context-size and context-overflow-action parameters in the WITH clause of your CREATE MODEL statement.

Supported Overflow Actions

The following table describes the supported actions for handling context overflow.

ActionDescription
truncated-tailDefault. Truncates the input from the end to fit the max-context-size.
truncated-tail-logTruncates the input from the end and logs the action.
truncated-headTruncates the input from the beginning to fit the max-context-size.
truncated-head-logTruncates the input from the beginning and logs the action.
skippedSkips the input entirely without processing it.
skipped-logSkips the input and logs the action.

SQL Examples

The following examples demonstrate how to use context overflow parameters with ML_PREDICT.

Chat and Completions

This example uses a completion model with a small context size and truncated-tail action.

SQL
1CREATE TEMPORARY MODEL `gpt-model`
2INPUT (`input` STRING)
3OUTPUT (`output` STRING)
4WITH (
5    'provider' = 'openai-compat',
6    'endpoint' = 'https://api.openai.com/v1/chat/completions',
7    'max-context-size' = '4',
8    'context-overflow-action' = 'truncated-tail',
9    'api-key' = '${secret_values.openai-key}',
10    'model' = 'gpt-4o'
11);
12
13-- Use ML_PREDICT to call the model
14SELECT `value`, `output`
15FROM ML_PREDICT(
16  INPUT => TABLE `source_table`,
17  MODEL => MODEL `gpt-model`,
18  ARGS => DESCRIPTOR(`value`)
19);

Embeddings

This example uses an embedding model with a max-context-size of 2 and truncated-tail action. If the input contains more than two words, it is truncated before generating the embedding.

SQL
1CREATE TEMPORARY MODEL `embedding-model`
2INPUT (`input` STRING)
3OUTPUT (`output` ARRAY<FLOAT>)
4WITH (
5    'provider' = 'openai-compat',
6    'endpoint' = 'https://api.openai.com/v1/embeddings',
7    'max-context-size' = '2',
8    'context-overflow-action' = 'truncated-tail',
9    'api-key' = '${secret_values.openai-key}',
10    'model' = 'text-embedding-3-small',
11    'dimension' = '1536'
12);
13
14-- Use ML_PREDICT to generate embeddings
15SELECT `value`, `output`
16FROM ML_PREDICT(
17  INPUT => TABLE `source_table`,
18  MODEL => MODEL `embedding-model`,
19  ARGS => DESCRIPTOR(`value`)
20);

Delete Models

Use the DROP MODEL command to delete a registered model.

SQL
1DROP [TEMPORARY] MODEL [IF EXISTS] [catalog_name.][db_name.]model_name

Example

SQL
1DROP MODEL sentiment_analysis_model;
Was this helpful?