All Products
Search
Document Center

PolarDB:Use a built-in platform model

Last Updated:Mar 26, 2024

This topic describes how to use a built-in platform model supported by Row-oriented AI.

The following table describes the information about the built-in platform models supported by Row-oriented AI.

Function

Model name

File name

Data type of return values

Description

polarchat

builtin_polarchat

#ailib#_builtin_polarchat.so

STRING

The function for interactive Q&A based on LLMs.

polarzixun

builtin_polarzixun

#ailib#_builtin_polarzixun.so

STRING

The function for consulting based on retrieval-augmented LLMs.

qwen

builtin_qwen

#ailib#_builtin_qwen.so

STRING

The function based on the Tongyi Qianwen model.

Step 1: Enable the PolarDB for AI and cold data archiving features

Before you import models, you must enable the PolarDB for AI and cold data archiving features for your cluster. For more information, see Enable the PolarDB for AI feature and Enable cold data archiving.

Step 2: Deploy the built-in platform model

Connect to a database and execute the following statement to deploy the built-in platform model:

/*polar4ai*/ DEPLOY MODEL builtin_model_name WITH (mode = 'in_db');

After executing the statement, you can use the SHOW MODEL script to view the model status. If the model status is serving, the model has been deployed.

/*polar4ai*/ SHOW MODEL builtin_model_name;
Note
  • The builtin_model_name parameter must be replaced with the name of the built-in platform model.

  • The mode parameter in the statement used to deploy the model must be set to in_db.

  • It may take a while to deploy the model. You need to wait until the model status changes to serving before you perform subsequent operations.

Step 3: Create a function

Important

To create a function, you need to use a privileged account or grant a standard account permissions on the mysql.func system table. You can execute the following statements in your MySQL client by using the privileged account to grant a standard account permissions on the system table:

-- root login:
mysql> grant insert on mysql.* to 'normal'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> grant delete on mysql.* to 'normal'@'localhost';
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)

mysql> select * from mysql.func;
Empty set (0.00 sec)

-- normal login:
mysql> select myfunc_int(1);
ERROR 1046 (3D000): No database selected
mysql> select * from mysql.func;
ERROR 1142 (42000): SELECT command denied to user 'normal'@'localhost' for table 'func'
mysql> create function myfunc_int returns int soname 'udf_example.so';
Query OK, 0 rows affected (0.01 sec)
mysql> select myfunc_int(1);
+---------------+
| myfunc_int(1) |
+---------------+
| 1             |
+---------------+
1 row in set (0.00 sec)
mysql> drop function myfunc_int;
Query OK, 0 rows affected (0.00 sec)

You can use the user-defined functions (the .so file) generated in Step 2 to create a function.

CREATE FUNCTION function_name RETURNS return_value SONAME "soname";

The following table describes the parameters that you can configure in the preceding statement.

Parameter

Description

function_name

The name of the built-in function. The function name is predefined. The function name must be consistent with the function name corresponding to the name of the model described in Step 2.

return_value

The return value. The REAL, STRING, and INTEGER types are supported.

soname

The name of the .so file. The file name must correspond to the name of the model described in Step 2.

After the function is created, you can execute the following statement to query the system table to check whether the function has been created:

SELECT * FROM mysql.func;

Step 4: Call the function to perform model inference

You can execute the following statements to call the function for model inference:

SELECT function_name(feature1, feature2) from predict_table;
SELECT function_name("content");

The following table describes the parameters that you can configure in the preceding statements.

Parameter

Description

function_name

The function name.

feature1

The name of the column used for model inference.

feature2

The name of the column used for model inference.

predict_table

The name of the table used for model inference.

content

The input information used for model inference.