基于湖库一体架构,统一管理结构化、半结构化与非结构化等多模态数据,一个系统承载事务处理、实时分析与 AI 工作负载。
AI 模型注册
更新时间:2026-08-27 17:01:57
本文介绍如何通过 DBMS_AI_SERVICE 包配置 AI 模型访问,以便在 OceanBase 数据库内使用 AI 函数服务。
注意
使用 AI_SPLIT_DOCUMENT 函数不需要注册模型与端点。
前提条件
- 已具备 AI 模型相关权限,具体请参见 AI 函数服务权限。
- 已获取第三方模型服务的 API Key。
注册厂商配置模版(新接口)
支持使用 REGISTER_PROVIDER 注册厂商配置,通过 provider/model 格式调用 AI 函数。无需分别创建模型与端点,也无需填写完整 URL 路径。
说明
厂商配置注册接口从 V4.6.0 BP1 版本开始支持。旧接口相关权限完整保留,存量用法可继续工作。可以同时使用新旧接口进行注册,避免重名即可。
说明
若仅需使用某类 AI 函数,可只注册对应厂商。例如仅使用 AI_COMPLETE 时,完成下文中的注册文本生成模型步骤即可。
说明
语义索引暂不支持使用新接口注册厂商配置。
注册厂商配置
支持注册内置厂商和自定义厂商,具体说明如下:
- 内置厂商:只需填写
access_key,protocol与base_url可省略,系统会自动填充默认值。完整列表见下文表格。 - 自定义厂商:需至少填写
base_url与access_key,protocol默认为openai。 - 若同名厂商已存在,请改用
ALTER_PROVIDER更新配置。
支持的内置厂商列表及其对应的 protocol/base_url 默认值如下(仅在内置厂商 首次注册且未填写 protocol/base_url 时生效):
| 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"
}');
非内置厂商需至少填写 base_url 与 access_key,protocol 默认为 openai:
CALL DBMS_AI_SERVICE.REGISTER_PROVIDER('ob-mass', '{
"protocol": "openai",
"base_url": "https://example.com/v1",
"access_key": "sk-xxxx"
}');
调用 AI 函数
使用 REGISTER_PROVIDER 注册厂商配置后,即可通过 provider/model 格式调用 AI 函数。以阿里云 DashScope 厂商为例:
-- 调用嵌入模型
SELECT AI_EMBED('aliyun-dashscope/text-embedding-v3', 'hello');
-- 调用文本生成模型
SELECT AI_COMPLETE('aliyun-dashscope/qwen-plus', 'hello');
-- 调用重排序模型
SELECT AI_RERANK('aliyun-dashscope/gte-rerank-v2', 'query', '["doc1", "doc2"]');
(可选)配置模型参数
使用 ALTER_MODEL_PROFILE 为 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
}
}');
(可选)配置 Gateway
使用 CREATE_AI_GATEWAY 在多个 endpoint 间按权重路由:
CALL DBMS_AI_SERVICE.CREATE_AI_GATEWAY('prod_gateway', '{
"endpoints": [
{"name":"ep1","model":"aliyun/qwen-plus","weight":70},
{"name":"ep2","model":"deepseek/deepseek-chat","weight":30}
],
"circuit_breaker": {
"failure_rate_threshold": 50,
"window_size_seconds": 60,
"minimum_requests": 10,
"break_duration_seconds": 60,
"probe_requests": 3
}
}');
完整语法与参数说明请参见文末相关文档。
注册模型与端点模版(旧接口)
使用 CREATE_AI_MODEL 注册模型,再使用 CREATE_AI_MODEL_ENDPOINT 注册该模型的访问端点。以下示例注册三个模型键 ob_complete、ob_embed、ob_rerank,分别用于文本生成(AI_COMPLETE)、向量嵌入(AI_EMBED)和重排序(AI_RERANK)。请将 access_key 替换为你的实际 API Key。
说明
若仅需使用某类 AI 函数,可只注册对应模型与端点。例如仅使用 AI_COMPLETE 时,完成下文中的注册文本生成模型及端点步骤即可。
注册嵌入模型及端点
用于 AI_EMBED。
此示例为阿里云(兼容 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/compatible-mode/v1/embeddings",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
此示例为阿里云 DashScope(非兼容 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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
此示例为硅基流动(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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
此示例为腾讯混元(Hunyuan)(兼容 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://api.hunyuan.cloud.tencent.com/v1/embeddings",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "hunyuan-openAI"
}');
注册文本生成模型及端点
用于 AI_COMPLETE 和 AI_PROMPT。
此示例为阿里云(兼容 OpenAI 格式)的文本生成模型和端点注册示例。
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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-openAI"
}');
此示例为阿里云 DashScope(非兼容 OpenAI 格式)的文本生成模型和端点注册示例。
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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
此示例为 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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "deepseek"
}');
此示例为硅基流动(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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
此示例为腾讯混元(Hunyuan)(兼容 OpenAI 格式)的文本生成模型和端点注册示例。
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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "hunyuan-openAI"
}');
注册重排序模型及端点
用于 AI_RERANK。
此示例为阿里云 DashScope(非兼容 OpenAI 格式)的重排序模型和端点注册示例。
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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "aliyun-dashscope"
}');
此示例为硅基流动(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",
-- 需替换为实际的 access_key
"access_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"provider": "siliconflow"
}');
注册多模态模型(图片)
注意
图片嵌入和处理从 V4.6.0 Hotfix1 版本开始支持。
说明
多模态嵌入模型目前仅支持 provider 为 aliyun-dashscope。
多模态能力可按场景选择接口:
- AI 函数(
AI_EMBED/AI_COMPLETE):可使用新接口。 - 语义索引:暂不支持新接口,须使用本节旧接口注册模型与端点,并在索引
WITH子句中填写 model_key。
注册多模态嵌入模型及端点
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"
}');
说明
请将 access_key 替换为您的实际 API Key。创建语义索引时,dim 须与所选模型实际输出维度一致。
调用多模态嵌入模型
用于 AI_EMBED 图片嵌入,可选择图片 URL 或二进制图片数据(BASE64)。
-- 需将图片 URL 信息替换为实际的图片 URL
SET @img_url = 'https://example.com/image.jpg';
-- 图片 URL 嵌入
SELECT AI_EMBED('aliyun-dashscope/qwen2.5-vl-embedding', @img_url, '{"type":"image"}');
-- 使用二进制图片数据(通过 BASE64 编码)
SET @img_base64 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
-- 图片二进制数据嵌入(BASE64)
SELECT AI_EMBED('aliyun-dashscope/qwen2.5-vl-embedding', FROM_BASE64(@img_base64), '{"type":"image"}');
-- 需将图片 URL 信息替换为实际的图片 URL
SET @img_url = 'https://example.com/image.jpg';
-- 图片 URL 嵌入
SELECT AI_EMBED('ob_vl_embed', @img_url, '{"type":"image"}');
-- 使用二进制图片数据(通过 BASE64 编码)
SET @img_base64 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
-- 图片二进制数据嵌入(BASE64)
SELECT AI_EMBED('ob_vl_embed', FROM_BASE64(@img_base64), '{"type":"image"}');
注册多模态文本生成模型及端点
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"
}');
调用多模态文本生成模型
通过 AI_COMPLETE 结合 AI_PROMPT 的图片占位符对图片进行处理,可选择图片 URL 或二进制图片数据(BASE64)。
-- 单图片处理(图片 URL)
SELECT AI_COMPLETE(
'aliyun-dashscope/qwen3.5-plus',
AI_PROMPT('请描述这张图片 {img_0}', @img_url)
);
-- 单图片处理(BASE64)
SELECT AI_COMPLETE(
'aliyun-dashscope/qwen3.5-plus',
AI_PROMPT('请描述这张图片 {img_0}', FROM_BASE64(@img_base64))
);
-- 单图片处理(图片 URL)
SELECT AI_COMPLETE(
'ob_complete',
AI_PROMPT('请描述这张图片 {img_0}', @img_url)
);
-- 单图片处理(BASE64)
SELECT AI_COMPLETE(
'ob_complete',
AI_PROMPT('请描述这张图片 {img_0}', FROM_BASE64(@img_base64))
);
相关文档
- AI 函数服务快速上手:注册完成后运行第一个示例的步骤。
- AI 函数服务使用及示例:各 AI 函数的语法与更多示例。
- DBMS_AI_SERVICE 包:AI 模型与端点的完整参数说明。