Skip to content

Commit adfb0d7

Browse files
authored
serverless: Inference service support customizing OpenAI API Base (#22320)
1 parent 29599f2 commit adfb0d7

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

tidb-cloud/vector-search-auto-embedding-jina-ai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ SET @@GLOBAL.TIDB_EXP_EMBED_JINA_AI_API_KEY = 'your-jina-ai-api-key-here';
5151
CREATE TABLE sample (
5252
`id` INT,
5353
`content` TEXT,
54-
`embedding` VECTOR(1024) GENERATED ALWAYS AS (EMBED_TEXT(
54+
`embedding` VECTOR(2048) GENERATED ALWAYS AS (EMBED_TEXT(
5555
"jina_ai/jina-embeddings-v4",
5656
`content`
5757
)) STORED

tidb-cloud/vector-search-auto-embedding-openai.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ SET @@GLOBAL.TIDB_EXP_EMBED_OPENAI_API_KEY = 'your-openai-api-key-here';
4949
CREATE TABLE sample (
5050
`id` INT,
5151
`content` TEXT,
52-
`embedding` VECTOR(1536) GENERATED ALWAYS AS (EMBED_TEXT(
53-
"openai/text-embedding-3-small",
52+
`embedding` VECTOR(3072) GENERATED ALWAYS AS (EMBED_TEXT(
53+
"openai/text-embedding-3-large",
5454
`content`
5555
)) STORED
5656
);
@@ -85,6 +85,54 @@ Result:
8585
+------+----------------------------------------------------------------+
8686
```
8787

88+
## Use Azure OpenAI
89+
90+
To use OpenAI embedding models on Azure, set the global variable `TIDB_EXP_EMBED_OPENAI_API_BASE` to the URL of your Azure resource. For example:
91+
92+
```sql
93+
SET @@GLOBAL.TIDB_EXP_EMBED_OPENAI_API_KEY = 'your-openai-api-key-here';
94+
SET @@GLOBAL.TIDB_EXP_EMBED_OPENAI_API_BASE = 'https://<your-resource-name>.openai.azure.com/openai/v1';
95+
96+
CREATE TABLE sample (
97+
`id` INT,
98+
`content` TEXT,
99+
`embedding` VECTOR(3072) GENERATED ALWAYS AS (EMBED_TEXT(
100+
"openai/text-embedding-3-large",
101+
`content`
102+
)) STORED
103+
);
104+
105+
INSERT INTO sample
106+
(`id`, `content`)
107+
VALUES
108+
(1, "Java: Object-oriented language for cross-platform development."),
109+
(2, "Java coffee: Bold Indonesian beans with low acidity."),
110+
(3, "Java island: Densely populated, home to Jakarta."),
111+
(4, "Java's syntax is used in Android apps."),
112+
(5, "Dark roast Java beans enhance espresso blends.");
113+
114+
SELECT `id`, `content` FROM sample
115+
ORDER BY
116+
VEC_EMBED_COSINE_DISTANCE(
117+
embedding,
118+
"How to start learning Java programming?"
119+
)
120+
LIMIT 2;
121+
```
122+
123+
Note that even if your resource URL appears as `https://<your-resource-name>.cognitiveservices.azure.com/`, you must use `https://<your-resource-name>.openai.azure.com/openai/v1` as the API base to ensure OpenAI-compatible request and response formats.
124+
125+
To switch from Azure OpenAI to OpenAI directly, set `TIDB_EXP_EMBED_OPENAI_API_BASE` to an empty string:
126+
127+
```sql
128+
SET @@GLOBAL.TIDB_EXP_EMBED_OPENAI_API_BASE = '';
129+
```
130+
131+
> **Note:**
132+
>
133+
> - For security reasons, you can only set the API base to an Azure OpenAI URL or the OpenAI URL. Arbitrary base URLs are not allowed.
134+
> - To use another OpenAI-compatible embedding service, contact [TiDB Cloud Support](/tidb-cloud/tidb-cloud-support.md).
135+
88136
## Options
89137

90138
All [OpenAI embedding options](https://platform.openai.com/docs/api-reference/embeddings/create) are supported via the `additional_json_options` parameter of the `EMBED_TEXT()` function.

0 commit comments

Comments
 (0)