Row-oriented AI includes three built-in platform models that you can deploy and call directly from SQL, without external ML infrastructure. This guide walks you through deploying a model, creating a SQL function, and running inference queries.
| Function | Model name | File name | Return type | When to use |
|---|---|---|---|---|
| polarchat | builtin_polarchat | #ailib#_builtin_polarchat.so | STRING | Open-ended question answering over your data using LLMs. |
| polarzixun | builtin_polarzixun | #ailib#_builtin_polarzixun.so | STRING | Answers that draw from a knowledge base or document corpus, using retrieval-augmented LLMs. |
| qwen | builtin_qwen | #ailib#_builtin_qwen.so | STRING | General-purpose text generation and comprehension tasks, based on the Tongyi Qianwen model. |
Prerequisites
Before you begin, ensure that you have:
Step 1: Deploy the built-in platform model
Connect to a database and run the following statement to deploy the model:
/*polar4ai*/ DEPLOY MODEL builtin_model_name WITH (mode = 'in_db');
Replace builtin_model_name with the model name from the table above (for example, builtin_polarchat). Set mode to in_db.
It may take a while to deploy the model. Run SHOW MODEL to check the status:
/*polar4ai*/ SHOW MODEL builtin_model_name;
Wait until the status changes to serving before proceeding.
Step 2: Create a function
Use the user-defined function (UDF) .so file generated in Step 1 to create a SQL function:
CREATE FUNCTION function_name RETURNS return_value SONAME "soname";
| Parameter | Description |
|---|---|
function_name |
The predefined name of the built-in function. Must match the function name for the model deployed in Step 1. |
return_value |
The return type. Supported values: REAL, STRING, INTEGER. |
soname |
The .so file name. Must match the file name for the model deployed in Step 1. |
For example, to create a function for builtin_polarchat:
CREATE FUNCTION polarchat RETURNS STRING SONAME "#ailib#_builtin_polarchat.so";
To verify the function was created, query the system table:
SELECT * FROM mysql.func;
Grant permissions to a standard account
To create a function, use a privileged account or grant a standard account the necessary permissions on the mysql.func system table.
Run the following statements using the privileged account:
GRANT INSERT ON mysql.* TO 'normal'@'localhost';
GRANT DELETE ON mysql.* TO 'normal'@'localhost';
FLUSH PRIVILEGES;
Step 3: Call the function for model inference
Call the function using a SELECT statement. Two calling patterns are supported:
Query a table — pass one or more column values as input:
SELECT function_name(feature1, feature2) FROM predict_table;
Pass a string directly — use a literal string as input:
SELECT function_name("content");
| Parameter | Description |
|---|---|
function_name |
The function name created in Step 2. |
feature1, feature2 |
Column names from the table used for inference. |
predict_table |
The table used for inference. |
content |
A literal string passed directly as input. |
For example, to run interactive Q&A using polarchat against a support_tickets table:
SELECT polarchat(description) FROM support_tickets LIMIT 10;