Skip to content

Commit 48035c2

Browse files
💬Generate LLM translations (#2177)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2e77814 commit 48035c2

File tree

4 files changed

+192
-12
lines changed

4 files changed

+192
-12
lines changed

docs/cn/guides/51-ai-functions/index.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Databend 依赖 [Azure OpenAI Service](https://azure.microsoft.com/en-us/product
1313

1414
## 什么是嵌入 (Embeddings)?
1515

16-
嵌入是文本数据的向量表示,它捕获了原始文本的语义和上下文含义。它们可用于比较和分析各种自然语言处理任务中的文本,例如文档相似性、聚类和推荐系统。
16+
嵌入是文本数据的向量表示,它捕获原始文本的语义和上下文含义。它们可用于比较和分析各种自然语言处理任务中的文本,例如文档相似性、聚类和推荐系统。
1717

1818
为了说明嵌入的工作原理,让我们考虑一个简单的例子。假设我们有以下句子:
1919
1. `"The cat sat on the mat."`
@@ -30,7 +30,7 @@ Databend 依赖 [Azure OpenAI Service](https://azure.microsoft.com/en-us/product
3030
2. `[0.25, 0.29, 0.11, 0.71, 0.38]`
3131
3. `[-0.1, 0.5, 0.6, -0.3, 0.8]`
3232

33-
在这个简化的例子中,您可以看到句子 1 和句子 2 的嵌入在向量空间中彼此更接近,而句子 3 的嵌入则更远。这说明了嵌入如何捕获语义关系并用于比较和分析文本数据
33+
在这个简化的例子中,您可以看到句子 1 和句子 2 的嵌入在向量空间中彼此更接近,而句子 3 的嵌入则更远。这说明了嵌入如何捕获语义关系,并可用于比较和分析文本数据
3434

3535
## 什么是向量数据库?
3636

@@ -42,7 +42,7 @@ Databend 提供了内置的 AI 函数,用于各种自然语言处理任务。
4242

4343
- [ai_embedding_vector](/sql/sql-functions/ai-functions/ai-embedding-vector): 为文本文档生成嵌入。
4444
- [ai_text_completion](/sql/sql-functions/ai-functions/ai-text-completion): 根据给定的提示生成文本补全。
45-
- [cosine_distance](/sql/sql-functions/ai-functions/ai-cosine-distance): 计算两个嵌入之间的余弦距离。
45+
- [cosine_distance](/sql/sql-functions/vector-distance-functions/vector-cosine-distance): 计算两个嵌入之间的余弦距离。
4646

4747
## 生成嵌入
4848

@@ -67,7 +67,7 @@ VALUES
6767

6868
## 计算余弦距离
6969

70-
现在,让我们使用 [cosine_distance](/sql/sql-functions/ai-functions/ai-cosine-distance) 函数找到与给定查询最相似的文档:
70+
现在,让我们使用 [cosine_distance](/sql/sql-functions/vector-distance-functions/vector-cosine-distance) 函数找到与给定查询最相似的文档:
7171
```sql
7272
SELECT
7373
id,
@@ -112,11 +112,11 @@ completion: and machine learning. It is known for its simplicity, readability, a
112112

113113
您可以在我们的 [Databend Cloud](https://databend.com) 上体验这些功能,您可以在这里注册免费试用版并立即开始使用这些 AI 功能。
114114

115-
Databend 的 AI 函数设计为易于使用,即使对于不熟悉机器学习或自然语言处理的用户也是如此。借助 Databend,您可以快速轻松地将强大的 AI 功能添加到您的 SQL 查询中,并将您的数据分析提升到一个新的水平。
115+
Databend 的 AI 功能旨在易于使用,即使对于不熟悉机器学习或自然语言处理的用户也是如此。借助 Databend,您可以快速轻松地将强大的 AI 功能添加到您的 SQL 查询中,并将您的数据分析提升到一个新的水平。
116116

117117
## 使用 Databend 构建 AI 问答系统
118118

119-
我们已经利用 [Databend Cloud](https://databend.com) 和 AI 函数为我们的文档构建了一个 AI 问答系统。
119+
我们利用 [Databend Cloud](https://databend.com) 和 AI 函数为我们的文档构建了一个 AI 问答系统。
120120

121121
以下是构建它的分步指南:
122122

@@ -151,28 +151,28 @@ WHERE LENGTH(embedding) = 0;
151151
### 步骤 4:提问并检索相关答案
152152

153153
```sql
154-
-- Define the question as a CTE (Common Table Expression)
154+
-- 将问题定义为 CTE(公共表表达式)
155155
WITH question AS (
156156
SELECT 'Tell me the ai functions' AS q
157157
),
158-
-- Calculate the question's embedding vector
158+
-- 计算问题的嵌入向量
159159
question_embedding AS (
160160
SELECT ai_embedding_vector((SELECT q FROM question)) AS q_vector
161161
),
162-
-- Retrieve the top 3 most relevant documents
162+
-- 检索前 3 个最相关的文档
163163
top_3_docs AS (
164164
SELECT content,
165165
cosine_distance((SELECT q_vector FROM question_embedding), embedding) AS dist
166166
FROM doc
167167
ORDER BY dist ASC
168168
LIMIT 3
169169
),
170-
-- Combine the content of the top 3 documents
170+
-- 合并前 3 个文档的内容
171171
combined_content AS (
172172
SELECT string_agg(content, ' ') AS aggregated_content
173173
FROM top_3_docs
174174
),
175-
-- Concatenate a custom prompt, the combined content, and the original question
175+
-- 连接自定义提示、合并的内容和原始问题
176176
prompt AS (
177177
SELECT CONCAT(
178178
'Utilizing the sections provided from the Databend documentation, answer the questions to the best of your ability. ',
@@ -182,7 +182,7 @@ prompt AS (
182182
(SELECT q FROM question)
183183
) as p
184184
)
185-
-- Pass the concatenated text to the ai_text_completion function to generate a coherent and relevant response
185+
-- 将连接的文本传递给 ai_text_completion 函数以生成连贯且相关的响应
186186
SELECT ai_text_completion((SELECT p FROM prompt)) AS answer;
187187
```
188188

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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`: 第一个向量 (ARRAY(FLOAT32 NOT NULL))
17+
- `vector2`: 第二个向量 (ARRAY(FLOAT32 NOT NULL))
18+
19+
## 返回值
20+
21+
返回一个介于 0 和 1 之间的 FLOAT 值:
22+
- 0:相同的向量(完全相似)
23+
- 1:正交向量(完全不相似)
24+
25+
## 描述
26+
27+
余弦距离测量两个向量之间基于它们之间角度的相异度,而不管它们的大小。该函数:
28+
29+
1. 验证两个输入向量是否具有相同的长度
30+
2. 计算两个向量的元素乘积之和(点积)
31+
3. 计算每个向量的平方和的平方根(向量大小)
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 ARRAY(FLOAT32 NOT NULL)
55+
);
56+
57+
INSERT INTO vectors VALUES
58+
(1, [1.0000, 2.0000, 3.0000]),
59+
(2, [1.0000, 2.2000, 3.0000]),
60+
(3, [4.0000, 5.0000, 6.0000]);
61+
```
62+
63+
找到与 [1, 2, 3] 最相似的向量:
64+
65+
```sql
66+
SELECT
67+
vec,
68+
COSINE_DISTANCE(vec, [1.0000, 2.0000, 3.0000]) AS distance
69+
FROM
70+
vectors
71+
ORDER BY
72+
distance ASC
73+
LIMIT 1;
74+
```
75+
76+
```
77+
+-------------------------+----------+
78+
| vec | distance |
79+
+-------------------------+----------+
80+
| [1.0000,2.2000,3.0000] | 0.0 |
81+
+-------------------------+----------+
82+
```
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: 'L2_DISTANCE'
3+
description: '在 Databend 中测量向量之间的欧几里得距离'
4+
---
5+
6+
计算两个向量之间的欧几里得(L2)距离,测量它们在向量空间中的直线距离。
7+
8+
## 语法
9+
10+
```sql
11+
L2_DISTANCE(vector1, vector2)
12+
```
13+
14+
## 参数
15+
16+
- `vector1`: 第一个向量 (ARRAY(FLOAT32 NOT NULL))
17+
- `vector2`: 第二个向量 (ARRAY(FLOAT32 NOT NULL))
18+
19+
## 返回值
20+
21+
返回一个 FLOAT 值,表示两个向量之间的欧几里得(L2)距离。该值始终为非负数:
22+
- 0:相同的向量
23+
- 较大的值:距离较远的向量
24+
25+
## 描述
26+
27+
L2 距离,也称为欧几里得距离,测量欧几里得空间中两点之间的直线距离。它是向量相似性搜索和机器学习应用中最常用的指标之一。
28+
29+
该函数:
30+
31+
1. 验证两个输入向量是否具有相同的长度
32+
2. 计算对应元素之间平方差的总和
33+
3. 返回该总和的平方根
34+
35+
实现的数学公式为:
36+
37+
```
38+
L2_distance(v1, v2) = √(Σ(v1ᵢ - v2ᵢ)²)
39+
```
40+
41+
其中 v1ᵢ 和 v2ᵢ 是输入向量的元素。
42+
43+
:::info
44+
- 此函数在 Databend 中执行向量计算,不依赖于外部 API。
45+
:::
46+
47+
## 示例
48+
49+
创建一个包含向量数据的表:
50+
51+
```sql
52+
CREATE OR REPLACE TABLE vectors (
53+
id INT,
54+
vec ARRAY(FLOAT32 NOT NULL)
55+
);
56+
57+
INSERT INTO vectors VALUES
58+
(1, [1.0000, 2.0000, 3.0000]),
59+
(2, [1.0000, 2.2000, 3.0000]),
60+
(3, [4.0000, 5.0000, 6.0000]);
61+
```
62+
63+
使用 L2 距离查找最接近 [1, 2, 3] 的向量:
64+
65+
```sql
66+
SELECT
67+
id,
68+
vec,
69+
L2_DISTANCE(vec, [1.0000, 2.0000, 3.0000]) AS distance
70+
FROM
71+
vectors
72+
ORDER BY
73+
distance ASC;
74+
```
75+
76+
```
77+
+----+-------------------------+----------+
78+
| id | vec | distance |
79+
+----+-------------------------+----------+
80+
| 1 | [1.0000,2.0000,3.0000] | 0.0 |
81+
| 2 | [1.0000,2.2000,3.0000] | 0.2 |
82+
| 3 | [4.0000,5.0000,6.0000] | 5.196152 |
83+
+----+-------------------------+----------+
84+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: '向量距离函数'
3+
description: 'Databend 中用于相似性度量的向量距离函数'
4+
---
5+
6+
# 向量距离函数
7+
8+
Databend 提供了用于测量向量之间距离或相似度的函数,这对于向量搜索和机器学习应用至关重要。
9+
10+
## 函数比较
11+
| 函数 | 描述 | 范围 | 最适合 | 使用场景 |
12+
|----------|-------------|-------|----------|-----------|
13+
| [L2_DISTANCE](01-vector-l2-distance.md) | 欧几里得(直线)距离 | [0, ∞) | 当大小很重要时 | • 图像相似性<br/>• 地理数据<br/>• 异常检测<br/>• 基于特征的聚类 |
14+
| [COSINE_DISTANCE](00-vector-cosine-distance.md) | 向量之间的角度距离 | [0, 1] | 当方向比大小更重要时 | • 文档相似性<br/>• 语义搜索<br/>• 推荐系统<br/>• 文本分析 |

0 commit comments

Comments
 (0)