Skip to main content
Version: V1.2.0

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:

OperationDescription
CREATE_AI_MODELCreates an AI model object.
DROP_AI_MODELDrops an AI model object.
CREATE_AI_MODEL_ENDPOINTCreates an AI model endpoint object.
ALTER_AI_MODEL_ENDPOINTModifies an AI model endpoint object.
DROP_AI_MODEL_ENDPOINTDrops 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.

tip

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.

info

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.

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"
}');

Register a text generation model and an endpoint​

Used for AI_COMPLETE and AI_PROMPT.

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"
}');

Register the reranking model and endpoints​

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"
}');

View information about AI models and endpoints​

seekdb allows you to view information about AI models and endpoints by using views:

ViewDescription
CDB/DBA_OB_AI_MODELSViews information about AI models.
CDB/DBA_OB_AI_MODEL_ENDPOINTSViews information about AI model endpoints.