PolarDB for MySQL includes three built-in platform models that let you run LLM-powered inference directly from SQL—no external API calls, application-layer changes, or separate AI service connections required. You deploy a model once, create a SQL function, and then call it inside any SELECT statement.
Available models
| Function | Model name | File name (SONAME) | Return type | Use when |
|---|---|---|---|---|
polarchat | builtin_polarchat | #ailib#_builtin_polarchat.so | STRING | You need interactive Q&A backed by an LLM—ask a question and get a conversational answer. |
polarzixun | builtin_polarzixun | #ailib#_builtin_polarzixun.so | STRING | You need to query a knowledge base with retrieval-augmented generation (RAG)—answers are grounded in retrieved documents rather than model memory alone. |
qwen | builtin_qwen | #ailib#_builtin_qwen.so | STRING | You need general-purpose text generation using the Tongyi Qianwen model directly. |
How it works
All three models follow the same three-step pattern:
Deploy the model with
DEPLOY MODEL—this registers it with PolarDB for AI.Register the model as a SQL function with
CREATE FUNCTION.Call the function inside any
SELECTstatement.
Deploy and call polarzixun
The following steps walk through deploying builtin_polarzixun and calling it with SQL.
Prerequisites
Before you begin, ensure that you have:
PolarDB for AI enabled on your cluster
Cold data archiving enabled on your cluster
Step 1: Deploy the model
Connect to a database and run the following statement to deploy builtin_polarzixun:
/*polar4ai*/ DEPLOY MODEL builtin_polarzixun WITH (mode = 'in_db');To verify that deployment succeeded, check the model status:
/*polar4ai*/ SHOW MODEL builtin_polarzixun;The model is ready when its status shows serving.
Step 2: Create the function
CREATE FUNCTION polarzixun RETURNS STRING SONAME "#ailib#_builtin_polarzixun.so";Step 3: Call the function
Pass any question as a string argument:
SELECT polarzixun("Can ECS instances and PolarDB clusters that are deployed in different regions or across accounts communicate with each other over an internal network?") AS answer;SELECT polarzixun("How does PolarDB implement load balancing across nodes?") AS answer;SELECT polarzixun("How do I purchase a PolarDB cluster?") AS answer;Query results are displayed in Chinese only.