Register and manage AI models and endpoints
This topic describes how to register and manage AI models and endpoints in seekdb.
Prerequisites
- You have the required permissions to manage AI models. For more information, see Manage AI model permissions.
- You have obtained the API Key of a third-party model service.
Register and manage AI models and endpoints by using the system package
The DBMS_AI_SERVICE package provides the ability to manage AI models and endpoints. It supports the following operations:
| Operation | Description |
|---|---|
| CREATE_AI_MODEL | Creates an AI model object. |
| DROP_AI_MODEL | Drops an AI model object. |
| CREATE_AI_MODEL_ENDPOINT | Creates an AI model endpoint object. |
| ALTER_AI_MODEL_ENDPOINT | Modifies an AI model endpoint object. |
| DROP_AI_MODEL_ENDPOINT | Drops an AI model endpoint object. |
You can call this system package to directly manage AI models and endpoints in seekdb without relying on external services. For more information about the parameters and syntax, see DBMS_AI_SERVICE.
For more information about the supported AI model providers and their corresponding URLs, see CREATE_AI_MODEL_ENDPOINT.
Register the model and endpoint templates
Register models and their endpoints using CREATE_AI_MODEL and CREATE_AI_MODEL_ENDPOINT. In the following sample, models with the keys ob_complete, ob_embed, and ob_rerank are registered and used for text generation (AI_COMPLETE), vector embedding (AI_EMBED), and reranking (AI_RERANK), respectively. Replace access_key with your actual API Key.
If you only want to use a certain type of AI function, you can register the corresponding model and endpoint. For example, if you only want to use AI_COMPLETE, you can proceed with the Register text generation models and endpoints steps below.
Register the embedding models and endpoints
Used in AI_EMBED.
- Aliyun
- Aliyun DashScope
- silicon
- Tencent Hunyuan
This example registers an embedding model and endpoint in ApsaraDB for PolarDB. The endpoint and model are compatible with the 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",
-- Replace with your actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
This sample shows you how to register the embedding model and endpoint for Alibaba Cloud DashScope (incompatible with OpenAI).
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",
-- replace with your access key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
This example is for embedding models and endpoint registration from 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",
-- replace with the actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
This example shows how to register an embedding model and endpoint for Tencent's Hunyuan model.
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",
-- Enter your access key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "hunyuan-openAI"
}');
Register a text generation model and an endpoint
Used for AI_COMPLETE and AI_PROMPT.
- Alibaba Cloud
- Alibaba Cloud DashScope
- deepseek
- Silicon Flow
- Tencent Hunyuan
The following example demonstrates how to register a text generation model and endpoint for Alibaba Cloud that is compatible with the 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",
-- replace with your access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
This example is for registering a text generation model and its endpoint from 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",
-- Replace this with your actual access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
This example provides registration for the text generation model and 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",
-- Replace the placeholder with your own access key.
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "deepseek"
}');
This example is for registering text generation models and endpoints with 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",
-- Replace with your actual access key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
This example provides the procedure for registering a text generation model and endpoint in Tencent Hunyuan (Qwen) (compatible with the 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",
-- Replace with your actual access key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "hunyuan-openAI"
}');
Register the reranking model and endpoints
- Aliyun DashScope
- Flow
This example demonstrates how to register a reranking model and endpoint for Alibaba Cloud DashScope (non-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",
-- Replace with actual access key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
This example shows how to register a reranking model and 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",
-- Replace with an actual access key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
View information about AI models and endpoints
seekdb allows you to view information about AI models and endpoints by using views:
| View | Description |
|---|---|
| CDB/DBA_OB_AI_MODELS | Views information about AI models. |
| CDB/DBA_OB_AI_MODEL_ENDPOINTS | Views information about AI model endpoints. |