---
title: "AI 模型注册 - OceanBase 数据库 V4.5.0 | OceanBase 文档中心"
description: AI 模型注册 本文介绍如何通过 DBMS_AI_SERVICE 包注册 AI 模型及其访问端点，以便在 OceanBase 数据库内使用 AI_COMPLETE 、 AI_PROMPT 、 AI_EMBED 、 AI_RERANK 等 AI 函数。 前提条件 已具备 AI 模型相关权限，具体请参见 AI 函数服务权…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 4.5.0

# AI 模型注册

更新时间：2026-02-13 14:29:57

[编辑](https://github.com/oceanbase/oceanbase-doc/edit/V4.5.0/zh-CN/640.ob-vector-search/370.ob-vector-search-ai-function/200.ob-vector-search-ai-function-register-model.md)  

本文介绍如何通过 `DBMS_AI_SERVICE` 包注册 AI 模型及其访问端点，以便在 OceanBase 数据库内使用 `AI_COMPLETE`、`AI_PROMPT`、`AI_EMBED`、`AI_RERANK` 等 AI 函数。

## 前提条件

- 已具备 AI 模型相关权限，具体请参见 [AI 函数服务权限](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004476157)。
 - 已获取第三方模型服务的 API Key。

## 注册模型与端点模版

使用 `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`。

    阿里云   阿里云 DashScope   硅基流动   腾讯混元

此示例为阿里云（兼容 OpenAI 格式）的嵌入模型和端点注册示例。

```sql
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.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.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.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`。

    阿里云   阿里云 DashScope   deepseek   硅基流动   腾讯混元

此示例为阿里云（兼容 OpenAI 格式）的文本生成模型和端点注册示例。

```sql
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.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.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.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.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   硅基流动

此示例为阿里云 DashScope（非兼容 OpenAI 格式）的重排序模型和端点注册示例。

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

```

## 相关文档

- [AI 函数服务快速上手](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000005363997)：注册完成后运行第一个示例的步骤。
 - [AI 函数服务使用及示例](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004476158)：各 AI 函数的语法与更多示例。
 - [DBMS_AI_SERVICE 包](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004479802)：AI 模型与端点的完整参数说明。

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
