CREATE MODEL registers an AI model in AnalyticDB for MySQL so you can call it directly in SQL queries. Use this statement to connect either the built-in inference platform or an external model service such as Alibaba Cloud Model Studio.
Syntax
CREATE MODEL model_name
OPTIONS(
type = 'internal|external',
name = 'connected_model_name',
provider = 'provider_name'
[, interface = 'interface_str'] -- optional; default: TEXT_TO_TEXT
[, api_key = 'sk-xxx'] -- required when type = 'external'
[, endpoint = 'endpoint_url'] -- required when type = 'external'
[, model_properties = ...] -- optional; Qwen series only
)Parameters
| Parameter | Required | Description |
|---|---|---|
model_name | Yes | The name you assign to the model in AnalyticDB for MySQL. |
name | Yes | The model name on the model service side. For example, qwen-max or qwen-plus for Alibaba Cloud Model Studio. |
type | Yes | The model service type. Set to internal to use the built-in inference platform of AnalyticDB for MySQL, or external to connect an external model service. |
provider | Yes | The model service provider. ADB_MODEL_SERVER for the built-in inference platform, or BAILIAN for Alibaba Cloud Model Studio. |
interface | No | The modality type. This parameter helps distinguish multimodal model services. Omit this parameter to use the default TEXT_TO_TEXT. Separate multiple values with commas. |
api_key | No | The API key for the external model service. Required when type = 'external'. |
endpoint | No | The endpoint URL of the external model service. Required when type = 'external'. |
model_properties | No | Hyperparameters that control model output. Currently limited to Alibaba Cloud Model Studio Qwen series models. |
Interface types
The interface parameter accepts the following values:
| Value | Description |
|---|---|
TEXT_TO_TEXT | Text generation model (default) |
TEXT_TO_EMBEDDING | Text embedding model |
IMAGE_TO_TEXT | Image-to-text model |
IMAGE_TO_EMBEDDING | Image embedding model |
AUDIO_TO_TEXT | Speech-to-text model |
AUDIO_TO_EMBEDDING | Speech embedding model |
Model parameters
The model_properties parameter accepts the following hyperparameters. Currently limited to Alibaba Cloud Model Studio Qwen series models.
| Parameter | Type | Description |
|---|---|---|
top_k | int | Samples from the top K most probable tokens. Lower values narrow the token pool and make output more deterministic. |
top_p | double | Nucleus sampling threshold. Selects the smallest set of tokens whose cumulative probability reaches top_p. Lower values focus the output more tightly. |
enable_search | boolean | Enables web search to retrieve up-to-date or external information. |
seed | int | Random seed for generation. Identical seeds produce identical outputs when all other parameters remain unchanged. |
temperature | float | Controls output randomness. Higher values increase diversity; lower values make the output more deterministic. Range: 0.0–2.0. |
max_tokens | int | Maximum number of tokens to generate. Applies to output length only, not input. |
Examples
Register an external model
Connect a Qwen model from Alibaba Cloud Model Studio. Before running this statement, configure the network to allow outbound access to the external service.
CREATE MODEL my_qwen_model
OPTIONS(
type = 'external',
name = 'qwen-plus',
provider = 'BAILIAN',
api_key = '<your-api-key>',
endpoint = '<your-endpoint-url>'
)Replace the placeholders with your actual values:
| Placeholder | Description |
|---|---|
<your-api-key> | Your model access key from Alibaba Cloud Model Studio |
<your-endpoint-url> | The model service endpoint for your selected model |