Skip to content

Commit 2b7838a

Browse files
AI Translate 51-ai-functions to Simplified-Chinese (#2534)
* [INIT] Start translation to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese * 🌐 Translate 02-built-in-functions.md to Simplified-Chinese --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 79eeb03 commit 2b7838a

File tree

11 files changed

+565
-35
lines changed

11 files changed

+565
-35
lines changed

.translation-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Translation initialization: 2025-07-25T00:42:45.652413
1+
Translation initialization: 2025-07-27T08:27:20.794958

docs/cn/guides/51-ai-functions/02-built-in-functions.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ title: 内置 AI 函数
44

55
import FunctionDescription from '@site/src/components/FunctionDescription';
66

7-
<FunctionDescription description="Introduced or updated: v1.2.777"/>
7+
<FunctionDescription description="引入或更新于:v1.2.777"/>
88

99
# 内置 AI 函数
1010

11-
Databend 提供了由 Azure OpenAI Service 支持的内置 AI 函数 (Built-in AI Functions),可将 AI 功能无缝集成到您的 SQL 工作流中。
11+
Databend 提供由 Azure OpenAI Service 支持的内置 AI 函数,可将 AI 能力无缝集成到 SQL 工作流中。
1212

1313
:::warning
14-
**数据隐私声明**当使用内置 AI 函数 (Built-in AI Functions) 时,您的数据将被发送到 Azure OpenAI Service。使用这些函数即表示您承认此数据传输,并同意 [Azure OpenAI 数据隐私](https://learn.microsoft.com/en-us/legal/cognitive-services/openai/data-privacy) 条款。
14+
**数据隐私声明**使用内置 AI 函数时,您的数据将被发送到 Azure OpenAI Service。使用这些函数即表示您知晓此数据传输,并同意 [Azure OpenAI 数据隐私](https://learn.microsoft.com/en-us/legal/cognitive-services/openai/data-privacy) 条款。
1515
:::
1616

1717
| 函数 | 描述 | 使用场景 |
1818
|----------|-------------|-----------|
1919
| [ai_text_completion](/sql/sql-functions/ai-functions/ai-text-completion) | 根据提示生成文本 | • 内容生成<br/>• 问题解答<br/>• 文本摘要 |
2020
| [ai_embedding_vector](/sql/sql-functions/ai-functions/ai-embedding-vector) | 将文本转换为向量表示 | • 语义搜索<br/>• 文档相似度<br/>• 内容推荐 |
21-
| [cosine_distance](/sql/sql-functions/vector-distance-functions/vector-cosine-distance) | 计算向量之间的相似度 | • 查找相似文档<br/>• 搜索结果排序 |
21+
| [cosine_distance](/sql/sql-functions/vector-functions/vector-cosine-distance) | 计算向量间相似度 | • 查找相似文档<br/>• 搜索结果排序 |
2222

2323
## Databend 中的向量存储
2424

25-
Databend 使用 `VECTOR(1536)` 数据类型存储嵌入向量 (embedding vectors),从而可以在 SQL 中直接使用 `cosine_distance` 函数进行相似度计算。
25+
Databend 使用 `VECTOR(1536)` 数据类型存储嵌入向量,支持在 SQL 中直接通过 `cosine_distance` 函数进行相似度计算。
2626

2727
## 示例:使用嵌入向量进行语义搜索
2828

2929
```sql
30-
-- 创建一个包含嵌入向量的文档表
30+
-- 创建带嵌入向量的文档表
3131
CREATE TABLE articles (
3232
id INT,
3333
title VARCHAR,
@@ -60,6 +60,6 @@ LIMIT 3;
6060
SELECT ai_text_completion('Explain the benefits of cloud data warehouses in three points:') AS completion;
6161
```
6262

63-
## 开始使用
63+
## 快速入门
6464

65-
欢迎在 [Databend Cloud](https://databend.cn) 上免费试用这些 AI 功能。
65+
[Databend Cloud](https://databend.cn) 免费试用这些 AI 功能。

docs/cn/sql-reference/00-sql-reference/10-data-types/vector.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 向量(Vector
2+
title: Vector
33
---
44

55
import FunctionDescription from '@site/src/components/FunctionDescription';
@@ -10,8 +10,7 @@ import EEFeature from '@site/src/components/EEFeature';
1010

1111
<EEFeature featureName='VECTOR INDEX'/>
1212

13-
14-
向量(VECTOR)数据类型用于存储 32 位浮点数的多维数组,专为机器学习、人工智能应用和相似性搜索操作而设计。每个向量在创建时都具有指定的固定维度(长度)。
13+
VECTOR 数据类型用于存储由 32 位浮点数组成的多维数组,专为机器学习、人工智能(AI)应用和相似性搜索操作而设计。每个向量在创建时都指定了固定的维度(dimension,即长度)。
1514

1615
## 语法
1716

@@ -20,12 +19,12 @@ column_name VECTOR(<dimension>)
2019
```
2120

2221
其中:
23-
- `dimension`: 向量的维度(长度)。必须是正整数,最大值为 4096。
24-
- 元素是 32 位浮点数。
22+
- `dimension`向量的维度(dimension,即长度)。必须是正整数,最大值为 4096。
23+
- 元素为 32 位浮点数。
2524

2625
## 向量索引
2726

28-
Databend 支持使用 HNSW 算法创建向量索引,以实现快速的近似最近邻搜索,查询性能提升 **23 倍**
27+
Databend 支持使用 HNSW(Hierarchical Navigable Small World)算法创建向量索引(Vector Index),以实现快速的近似最近邻搜索,可将查询(Query)性能提升 **23 倍**
2928

3029
### 索引语法
3130

@@ -34,22 +33,22 @@ VECTOR INDEX index_name(column_name) distance='cosine,l1,l2'
3433
```
3534

3635
其中:
37-
- `index_name`: 向量索引的名称
38-
- `column_name`: 需要索引向量(VECTOR列的名称
39-
- `distance`: 支持的距离函数。可以是 `'cosine'``'l1'``'l2'`,或组合形式如 `'cosine,l1,l2'`
36+
- `index_name`:向量索引(Vector Index)的名称。
37+
- `column_name`:要索引的 VECTOR 列的名称
38+
- `distance`:要支持的距离函数。可以是 `'cosine'``'l1'``'l2'`,或组合形式如 `'cosine,l1,l2'`
4039

4140

4241
### 支持的距离函数
4342

4443
| 函数 | 描述 | 使用场景 |
4544
|----------|-------------|----------|
46-
| **[cosine_distance](/sql/sql-functions/vector-distance-functions/vector-cosine-distance)** | 计算向量之间的余弦距离 | 语义相似性、文本嵌入 |
47-
| **[l1_distance](/sql/sql-functions/vector-distance-functions/vector-l1-distance)** | 计算 L1 距离(曼哈顿距离) | 特征比较、稀疏数据 |
48-
| **[l2_distance](/sql/sql-functions/vector-distance-functions/vector-l2-distance)** | 计算 L2 距离(欧几里得距离) | 几何相似性、图像特征 |
45+
| **[cosine_distance](/sql/sql-functions/vector-functions/vector-cosine-distance)** | 计算向量之间的余弦距离 | 语义相似性、文本嵌入 |
46+
| **[l1_distance](/sql/sql-functions/vector-functions/vector-l1-distance)** | 计算 L1 距离(曼哈顿距离) | 特征比较、稀疏数据 |
47+
| **[l2_distance](/sql/sql-functions/vector-functions/vector-l2-distance)** | 计算 L2 距离(欧几里得距离) | 几何相似性、图像特征 |
4948

5049
## 基本用法
5150

52-
### 第 1 步:创建带向量的表
51+
### 步骤 1:创建带有向量的表
5352

5453
```sql
5554
-- 创建带有向量索引的表,以实现高效的相似性搜索
@@ -61,9 +60,9 @@ CREATE OR REPLACE TABLE products (
6160
);
6261
```
6362

64-
**注意**向量索引会在数据插入时自动构建
63+
**注意**当数据插入表中时,向量索引(Vector Index)会自动构建
6564

66-
### 第 2 步:插入向量数据
65+
### 步骤 2:插入向量数据
6766

6867
```sql
6968
-- 插入产品特征向量
@@ -74,7 +73,7 @@ INSERT INTO products VALUES
7473
(4, 'Product D', [3.0, 1.0, 1.0]::VECTOR(3));
7574
```
7675

77-
### 第 3 步:执行相似性搜索
76+
### 步骤 3:执行相似性搜索
7877

7978
```sql
8079
-- 查找与查询向量 [1.2, 2.1, 2.8] 相似的产品
@@ -99,14 +98,14 @@ LIMIT 3;
9998
└─────┴───────────┴───────────────┴──────────────────┘
10099
```
101100

102-
**解释**该查询找到了与搜索向量 `[1.2, 2.1, 2.8]` 最相似的 3 个产品。余弦距离值越低,表示相似度越高。
101+
**说明**该查询(Query)找到了与搜索向量 `[1.2, 2.1, 2.8]` 最相似的 3 个产品。余弦距离值越小,表示相似度越高。
103102

104103
## 卸载和加载向量数据
105104

106105
### 卸载向量数据
107106

108107
```sql
109-
-- 将向量数据导出到暂存区(Stage)
108+
-- 将向量数据导出到暂存区
110109
COPY INTO @mystage/unload/
111110
FROM (
112111
SELECT
@@ -139,4 +138,4 @@ FROM (
139138
FROM @mystage/unload/
140139
)
141140
FILE_FORMAT = (TYPE = 'PARQUET');
142-
```
141+
```
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: 'COSINE_DISTANCE'
3+
description: '在 Databend 中使用 cosine_distance 函数衡量相似性'
4+
---
5+
6+
计算两个向量之间的余弦距离,用于衡量它们的不相似程度。
7+
8+
## 语法
9+
10+
```sql
11+
COSINE_DISTANCE(vector1, vector2)
12+
```
13+
14+
## 参数
15+
16+
- `vector1`: 第一个向量(VECTOR 数据类型)
17+
- `vector2`: 第二个向量(VECTOR 数据类型)
18+
19+
## 返回值
20+
21+
返回一个介于 0 和 1 之间的 FLOAT 值:
22+
- 0:向量相同(完全相似)
23+
- 1:向量正交(完全不相似)
24+
25+
## 描述
26+
27+
余弦距离根据两个向量之间的夹角来衡量它们的不相似性,而不考虑它们的模长。该函数执行以下操作:
28+
29+
1. 验证两个输入向量具有相同的长度
30+
2. 计算两个向量的元素级乘积之和(点积 (Dot Product))
31+
3. 计算每个向量的平方和的平方根(向量模长 (magnitude))
32+
4. 返回 `1 - (dot_product / (magnitude1 * magnitude2))`
33+
34+
其实现的数学公式为:
35+
36+
```
37+
cosine_distance(v1, v2) = 1 - (Σ(v1ᵢ * v2ᵢ) / (√Σ(v1ᵢ²) * √Σ(v2ᵢ²)))
38+
```
39+
40+
其中 v1ᵢ 和 v2ᵢ 是输入向量的元素。
41+
42+
:::info
43+
此函数在 Databend 内部执行向量计算,不依赖于外部 API。
44+
:::
45+
46+
47+
## 示例
48+
49+
创建一个包含向量数据的表:
50+
51+
```sql
52+
CREATE OR REPLACE TABLE vectors (
53+
id INT,
54+
vec VECTOR(3),
55+
VECTOR INDEX idx_vec(vec) distance='cosine'
56+
);
57+
58+
INSERT INTO vectors VALUES
59+
(1, [1.0000, 2.0000, 3.0000]),
60+
(2, [1.0000, 2.2000, 3.0000]),
61+
(3, [4.0000, 5.0000, 6.0000]);
62+
```
63+
64+
查找与 [1, 2, 3] 最相似的向量:
65+
66+
```sql
67+
SELECT
68+
vec,
69+
COSINE_DISTANCE(vec, [1.0000, 2.0000, 3.0000]::VECTOR(3)) AS distance
70+
FROM
71+
vectors
72+
ORDER BY
73+
distance ASC
74+
LIMIT 1;
75+
```
76+
77+
```
78+
+-------------------------+----------+
79+
| vec | distance |
80+
+-------------------------+----------+
81+
| [1.0000,2.2000,3.0000] | 0.0 |
82+
+-------------------------+----------+
83+
```
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: 'L2_DISTANCE'
3+
---
4+
5+
import FunctionDescription from '@site/src/components/FunctionDescription';
6+
7+
<FunctionDescription description="引入或更新于:v1.2.777"/>
8+
9+
计算两个向量之间的欧几里得距离(L2),即衡量它们在向量空间中的直线距离。
10+
11+
## 语法
12+
13+
```sql
14+
L2_DISTANCE(vector1, vector2)
15+
```
16+
17+
## 参数
18+
19+
- `vector1`: 第一个向量(VECTOR 数据类型)
20+
- `vector2`: 第二个向量(VECTOR 数据类型)
21+
22+
## 返回值
23+
24+
返回一个 FLOAT 值,表示两个向量之间的欧几里得距离(L2)。该值始终为非负数:
25+
- 0:向量相同
26+
- 值越大:向量相距越远
27+
28+
## 描述
29+
30+
L2 距离,也称为欧几里得距离(Euclidean distance),用于衡量欧几里得空间中两点之间的直线距离。它是向量相似性搜索 (Vector Similarity Search) 和机器学习应用中最常用的度量标准之一。
31+
32+
该函数会:
33+
34+
1. 验证两个输入向量的长度是否相同
35+
2. 计算对应元素之间差值的平方和
36+
3. 返回该和的平方根
37+
38+
其实现的数学公式为:
39+
40+
```
41+
L2_distance(v1, v2) = √(Σ(v1ᵢ - v2ᵢ)²)
42+
```
43+
44+
其中 v1ᵢ 和 v2ᵢ 是输入向量的元素。
45+
46+
:::info
47+
- 此函数在 Databend 内部执行向量计算,不依赖于外部 API。
48+
:::
49+
50+
## 示例
51+
52+
创建一个包含向量数据的表:
53+
54+
```sql
55+
CREATE OR REPLACE TABLE vectors (
56+
id INT,
57+
vec VECTOR(3),
58+
VECTOR INDEX idx_vec(vec) distance='l2'
59+
);
60+
61+
INSERT INTO vectors VALUES
62+
(1, [1.0000, 2.0000, 3.0000]),
63+
(2, [1.0000, 2.2000, 3.0000]),
64+
(3, [4.0000, 5.0000, 6.0000]);
65+
```
66+
67+
使用 L2 距离查找最接近 [1, 2, 3] 的向量:
68+
69+
```sql
70+
SELECT
71+
id,
72+
vec,
73+
L2_DISTANCE(vec, [1.0000, 2.0000, 3.0000]::VECTOR(3)) AS distance
74+
FROM
75+
vectors
76+
ORDER BY
77+
distance ASC;
78+
```
79+
80+
```
81+
+----+-------------------------+----------+
82+
| id | vec | distance |
83+
+----+-------------------------+----------+
84+
| 1 | [1.0000,2.0000,3.0000] | 0.0 |
85+
| 2 | [1.0000,2.2000,3.0000] | 0.2 |
86+
| 3 | [4.0000,5.0000,6.0000] | 5.196152 |
87+
+----+-------------------------+----------+
88+
```

0 commit comments

Comments
 (0)