This topic describes how to register AI models and their access endpoints by using the DBMS_AI_SERVICE package, so that you can use AI functions in OceanBase Database.
Notice
You do not need to register a model or endpoint when using the AI_SPLIT_DOCUMENT function.
Prerequisites
- You have the required permissions for AI model operations. For details, see Permissions for AI function services.
- You have obtained the API key of the third-party model service.
Templates for registering models and endpoints
Use CREATE_AI_MODEL to register a model, and then use CREATE_AI_MODEL_ENDPOINT to register an access endpoint for the model. The following examples register three model keys: ob_complete, ob_embed, and ob_rerank, for text generation (AI_COMPLETE), vector embedding (AI_EMBED), and reranking (AI_RERANK), respectively. Replace access_key with your actual API key.
Note
If you only need to use a specific type of AI function, you can register only the corresponding model and endpoint. For example, if you only use AI_COMPLETE, complete the Register the text generation model and its endpoint step below.
Register an embedding model and endpoint
For AI_EMBED.
This example shows how to register an embedding model and its endpoint for Alibaba Cloud by using the OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_embed');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_embed_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_embed', '{
"type": "dense_embedding",
"model_name": "BAAI/bge-m3"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_embed_endpoint', '{
"ai_model_name": "ob_embed",
"url": "https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
This example shows how to register an embedding model and its endpoint for Alibaba Cloud DashScope by using the non-OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_embed');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_embed_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_embed', '{
"type": "dense_embedding",
"model_name": "BAAI/bge-m3"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_embed_endpoint', '{
"ai_model_name": "ob_embed",
"url": "https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
This example shows how to register an embedding model and its endpoint for SiliconFlow.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_embed');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_embed_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_embed', '{
"type": "dense_embedding",
"model_name": "BAAI/bge-m3"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_embed_endpoint', '{
"ai_model_name": "ob_embed",
"url": "https://api.siliconflow.cn/v1/embeddings",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
This example shows how to register an embedding model and its endpoint for Tencent Hunyuan by using the OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_embed');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_embed_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_embed', '{
"type": "dense_embedding",
"model_name": "BAAI/bge-m3"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_embed_endpoint', '{
"ai_model_name": "ob_embed",
"url": "https://api.hunyuan.cloud.tencent.com/v1/embeddings",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "hunyuan-openAI"
}');
Register text generation models and endpoints
For AI_COMPLETE and AI_PROMPT.
This example shows how to register a text generation model and its endpoint for Alibaba Cloud by using the OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_complete');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_complete_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_complete', '{
"type": "completion",
"model_name": "THUDM/GLM-4-9B-0414"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_complete_endpoint', '{
"ai_model_name": "ob_complete",
"url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
This example shows how to register a text generation model and its endpoint for Alibaba Cloud DashScope by using the non-OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_complete');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_complete_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_complete', '{
"type": "completion",
"model_name": "THUDM/GLM-4-9B-0414"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_complete_endpoint', '{
"ai_model_name": "ob_complete",
"url": "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
This example shows how to register a text generation model and its endpoint for DeepSeek.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_complete');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_complete_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_complete', '{
"type": "completion",
"model_name": "THUDM/GLM-4-9B-0414"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_complete_endpoint', '{
"ai_model_name": "ob_complete",
"url": "https://api.deepseek.com/chat/completions",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "deepseek"
}');
This example shows how to register a text generation model and its endpoint for SiliconFlow.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_complete');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_complete_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_complete', '{
"type": "completion",
"model_name": "THUDM/GLM-4-9B-0414"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_complete_endpoint', '{
"ai_model_name": "ob_complete",
"url": "https://api.siliconflow.cn/v1/chat/completions",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
This example shows how to register a text generation model and its endpoint for Tencent Hunyuan by using the OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_complete');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_complete_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_complete', '{
"type": "completion",
"model_name": "THUDM/GLM-4-9B-0414"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_complete_endpoint', '{
"ai_model_name": "ob_complete",
"url": "https://api.hunyuan.cloud.tencent.com/v1/chat/completions",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "hunyuan-openAI"
}');
Register a reranking model and endpoint
For AI_RERANK.
This example shows how to register a reranking model and its endpoint for Alibaba Cloud DashScope by using the non-OpenAI-compatible format.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_rerank');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_rerank_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_rerank', '{
"type": "rerank",
"model_name": "BAAI/bge-reranker-v2-m3"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_rerank_endpoint', '{
"ai_model_name": "ob_rerank",
"url": "https://dashscope.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
This example shows how to register a reranking model and its endpoint for SiliconFlow.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_rerank');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_rerank_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_rerank', '{
"type": "rerank",
"model_name": "BAAI/bge-reranker-v2-m3"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_rerank_endpoint', '{
"ai_model_name": "ob_rerank",
"url": "https://api.siliconflow.cn/v1/rerank",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
Register a multimodal image model
Notice
Image embedding and image understanding are supported starting from V5.0.1.
As with a text model, first use CREATE_AI_MODEL to register the model, and then use CREATE_AI_MODEL_ENDPOINT to register its endpoint. The following example uses Alibaba Cloud DashScope in the OpenAI-compatible format. Replace access_key with your actual API key.
Register an image embedding model and its endpoint
For AI_EMBED image embedding.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_vl_embed');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_vl_embed_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_vl_embed', '{
"type": "dense_embedding",
"model_name": "qwen2.5-vl-embedding"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_vl_embed_endpoint', '{
"ai_model_name": "ob_vl_embed",
"url": "https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
The following examples use an image URL and Base64-encoded binary image data:
-- Replace the image URL with the actual image URL.
SET @img_url = 'https://example.com/image.jpg';
-- Embed an image URL.
SELECT AI_EMBED('ob_vl_embed', @img_url, '{"type":"image"}');
-- Use Base64-encoded binary image data.
SET @img_base64 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
-- Embed binary image data.
SELECT AI_EMBED('ob_vl_embed', FROM_BASE64(@img_base64), '{"type":"image"}');
Register an image understanding model and its endpoint
For AI_COMPLETE and AI_PROMPT image understanding.
CALL DBMS_AI_SERVICE.DROP_AI_MODEL ('ob_vl_complete');
CALL DBMS_AI_SERVICE.DROP_AI_MODEL_ENDPOINT ('ob_vl_complete_endpoint');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL(
'ob_vl_complete', '{
"type": "completion",
"model_name": "qwen3.5-plus"
}');
CALL DBMS_AI_SERVICE.CREATE_AI_MODEL_ENDPOINT (
'ob_vl_complete_endpoint', '{
"ai_model_name": "ob_vl_complete",
"url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
-- To be replaced with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
Example calls are as follows:
-- Understand a single image from an image URL.
SELECT AI_COMPLETE(
'ob_vl_complete',
AI_PROMPT('Please describe this image {img_0}', @img_url)
);
-- Understand a single image from Base64-encoded data.
SELECT AI_COMPLETE(
'ob_vl_complete',
AI_PROMPT('Please describe this image {img_0}', FROM_BASE64(@img_base64))
);
References
- Quick start with AI function service: Steps to run the first example after registration.
- Use AI function service and examples: Syntax and more examples for each AI function.
- DBMS_AI_SERVICE package: Complete parameter description for AI models and endpoints.
