This topic describes how to register AI models and their access endpoints by using the DBMS_AI_SERVICE package for AI Function Service in OceanBase Database.
Notice
You do not need to register models or endpoints when using the AI_SPLIT_DOCUMENT function.
Prerequisites
- You have the necessary AI model permissions. For details, see AI Function Service Permissions.
- You have obtained the API key of a third-party model service.
Register providers (new API)
You can use the REGISTER_PROVIDER statement to register a provider and invoke AI functions in the provider/model format. This eliminates the need to create models and endpoints separately or specify complete URL paths.
Note
The new provider registration API is supported starting with V4.6.0 BP1. Permissions related to the legacy API are fully retained, so existing usage can continue. You can use both APIs for registration as long as you avoid duplicate names.
Note
If you need to use only a specific type of AI function, you can register only the corresponding provider. For example, if you use only AI_COMPLETE, you need to complete only the Register a text generation model step below.
Note
Semantic indexes do not support registering providers by using the new API.
Register a provider
You can register built-in providers or custom providers. The details are as follows:
- Built-in providers: You only need to specify
access_key.protocolandbase_urlcan be omitted, as the system will automatically fill in default values. For a complete list, see the table below. - Custom providers: You must specify at least
base_urlandaccess_key. The default value forprotocolisopenai. - If a provider with the same name already exists, use
ALTER_PROVIDERto update its configuration.
The following table lists the supported built-in providers and their corresponding default protocol and base_url values (only effective for first-time registration of a built-in provider and when protocol/base_url are not specified):
provider |
protocol |
base_url |
|---|---|---|
aliyun |
openai |
https://dashscope.aliyuncs.com/compatible-mode/v1 |
aliyun-dashscope |
dashscope |
https://dashscope.aliyuncs.com/api/v1 |
deepseek |
openai |
https://api.deepseek.com |
siliconflow |
openai |
https://api.siliconflow.cn/v1 |
openai |
openai |
https://api.openai.com/v1 |
cohere |
cohere |
https://api.cohere.com/v2 |
tencent |
openai |
https://api.hunyuan.cloud.tencent.com/v1 |
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('aliyun', '{
"access_key": "sk-xxxx"
}');
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('aliyun-dashscope', '{
"access_key": "sk-xxxx"
}');
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('deepseek', '{
"access_key": "sk-xxxx"
}');
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('siliconflow', '{
"access_key": "sk-xxxx"
}');
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('tencent', '{
"access_key": "sk-xxxx"
}');
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('openai', '{
"access_key": "sk-xxxx"
}');
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('cohere', '{
"access_key": "sk-xxxx"
}');
For non-built-in providers, you must at least fill in base_url and access_key. The default value of protocol is openai.
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('ob-mass', '{
"protocol": "openai",
"base_url": "https://example.com/v1",
"access_key": "sk-xxxx"
}');
Call an AI function
After registering a provider using REGISTER_PROVIDER, you can call AI functions in the provider/model format. Taking the Alibaba Cloud DashScope provider as an example:
-- Call the embedding model
SELECT AI_EMBED('aliyun-dashscope/text-embedding-v3', 'hello');
-- Call the text generation model
SELECT AI_COMPLETE('aliyun-dashscope/qwen-plus', 'hello');
-- Call the reranking model
SELECT AI_RERANK('aliyun-dashscope/gte-rerank-v2', 'query', '["doc1", "doc2"]');
(Optional) Configure model parameters
Use ALTER_MODEL_PROFILE to set call parameters for provider/model:
CALL DBMS_AI_SERVICE.ALTER_MODEL_PROFILE('aliyun/qwen-plus', '{
"model_config": {
"max_tokens": 4096,
"temperature": 0,
"enable_thinking": false
},
"run_config": {
"batch_size": 16,
"max_image_size": 4194304,
"min_concurrency": 10,
"max_concurrency": 100
}
}');
Register models and endpoints (legacy API)
Use CREATE_AI_MODEL to register a model, then use CREATE_AI_MODEL_ENDPOINT to register the access endpoint for that model. The following example registers three models: 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 a text generation model and its endpoint step below.
Register an embedding model and its endpoint
For AI_EMBED.
This example shows how to register an embedding model and endpoints for Alibaba Cloud (compatible with OpenAI 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 endpoints for Alibaba Cloud DashScope (not compatible with OpenAI 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 endpoints 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 endpoints for Tencent Hunyuan (Hunyuan) (compatible with OpenAI 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 endpoints for Alibaba Cloud (compatible with OpenAI 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 endpoints for Alibaba Cloud DashScope (not compatible with OpenAI 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 endpoints 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 endpoints 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 endpoints for Tencent Hunyuan (compatible with OpenAI 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 re-ranking model and its endpoints
For AI_RERANK.
This example shows how to register a re-ranking model and its endpoints for Alibaba Cloud DashScope (not compatible with OpenAI 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 re-ranking model and its endpoints 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 multimodal models (images)
Notice
Image embedding and processing are supported starting with V4.6.0 Hotfix1.
Note
Multimodal embedding models currently support only aliyun-dashscope as the provider.
You can select an API based on the scenario:
- AI functions (
AI_EMBEDandAI_COMPLETE): You can use the new API. - Semantic indexes: The new API is not supported. You must use the legacy API in this section to register the model and endpoint, and specify the
model_keyin the indexWITHclause.
Register a multimodal embedding model and endpoint
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('aliyun-dashscope', '{
"access_key": "sk-xxxx"
}');
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/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding",
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
Note
Replace access_key with your actual API key. When you create a semantic index, dim must match the actual output dimension of the selected model.
Call a multimodal embedding model
You can use AI_EMBED to embed images provided as image URLs or binary image data (Base64-encoded).
-- Replace the image URL with an actual image URL
SET @img_url = 'https://example.com/image.jpg';
-- Embed an image URL
SELECT AI_EMBED('aliyun-dashscope/qwen2.5-vl-embedding', @img_url, '{"type":"image"}');
-- Use binary image data (Base64-encoded)
SET @img_base64 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
-- Embed binary image data (Base64)
SELECT AI_EMBED('aliyun-dashscope/qwen2.5-vl-embedding', FROM_BASE64(@img_base64), '{"type":"image"}');
-- Replace the image URL with an 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 binary image data (Base64-encoded)
SET @img_base64 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
-- Embed binary image data (Base64)
SELECT AI_EMBED('ob_vl_embed', FROM_BASE64(@img_base64), '{"type":"image"}');
Register a multimodal text generation model and endpoint
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('aliyun-dashscope', '{
"access_key": "sk-xxxx"
}');
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": "qwen3.5-plus"
}');
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",
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
Call a multimodal text generation model
You can use AI_COMPLETE together with image placeholders in AI_PROMPT to process images provided as image URLs or binary image data (Base64-encoded).
-- Process a single image (image URL)
SELECT AI_COMPLETE(
'aliyun-dashscope/qwen3.5-plus',
AI_PROMPT('Describe this image {img_0}', @img_url)
);
-- Process a single image (Base64)
SELECT AI_COMPLETE(
'aliyun-dashscope/qwen3.5-plus',
AI_PROMPT('Describe this image {img_0}', FROM_BASE64(@img_base64))
);
-- Process a single image (image URL)
SELECT AI_COMPLETE(
'ob_complete',
AI_PROMPT('Describe this image {img_0}', @img_url)
);
-- Process a single image (Base64)
SELECT AI_COMPLETE(
'ob_complete',
AI_PROMPT('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.
