Skip to content

Commit ae85fa8

Browse files
💬Generate LLM translations (#2208)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c7fd000 commit ae85fa8

File tree

4 files changed

+147
-83
lines changed

4 files changed

+147
-83
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---
2-
title: 访问 Data Lake
2+
title: 面向 Data Lakehouse 的 Databend
33
---
44

5-
Databend 与三种强大的 Data Lake 技术——[Apache Hive](https://hive.apache.org/)[Apache Iceberg](https://iceberg.apache.org/)[Delta Lake](https://delta.io/) 实现了无缝集成。这种集成通过支持 Data Lake 功能的多个方面带来了独特的优势。Databend 提供了一个通用且全面的平台,使用户能够在 Data Lake 环境中更灵活、更高效地处理各种数据集
5+
Databend 与流行的 Data Lake 技术集成,提供统一的 lakehouse 架构,将 Data Lake 的灵活性与数仓的性能相结合
66

7-
此外,这三种技术在 Databend 中的集成具有不同的方法。有些(如 Apache Hive)在 catalog 级别集成,而另一些(如 Delta Lake)则在表引擎级别运行。基于 catalog 的集成建立了与 Data Lake 的集中连接,从而简化了跨多个表的访问和管理。另一方面,表引擎级别的集成提供了更精细的控制,允许在单个表级别进行定制优化和微调。
7+
| 技术 | 集成类型 | 主要特性 | 文档 |
8+
|------------|-----------------|--------------|---------------|
9+
| Apache Hive | Catalog 级别 | 支持传统 Data Lake,模式注册 | [Apache Hive Catalog](01-hive.md) |
10+
| Apache Iceberg™ | Catalog 级别 | ACID 事务,模式演化,时间回溯 | [Apache Iceberg™ Catalog](02-iceberg.md) |
11+
| Delta Lake | Table Engine 级别 | ACID 事务,数据版本控制,模式强制 | [Delta Lake Table Engine](03-delta.md) |
812

9-
- [Apache Hive Catalog](01-hive.md)
10-
- [Apache Iceberg Catalog](02-iceberg.md)
11-
- [Delta Lake Table Engine](03-delta.md)
13+
这些集成使 Databend 用户能够高效地查询、分析和管理 Data Lake 和数仓环境中的各种数据集,而无需重复数据。
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# 用于自定义 AI/ML 的外部函数
2+
3+
对于高级 AI/ML 场景,Databend 支持外部函数,可以将您的数据与使用 Python 等语言编写的自定义 AI/ML 基础设施连接起来。
4+
5+
| 功能 | 描述 | 优势 |
6+
|---------|-------------|----------|
7+
| **模型灵活性** | 使用开源模型或您内部的 AI/ML 基础设施 | • 自由选择任何模型<br/>• 利用现有的 ML 投资<br/>• 随时掌握最新的 AI 进展 |
8+
| **GPU 加速** | 在配备 GPU 的机器上部署外部函数服务器 | • 更快地进行深度学习模型推理<br/>• 处理更大的批量大小<br/>• 支持计算密集型工作负载 |
9+
| **自定义 ML 模型** | 部署和使用您自己的机器学习模型 | • 专有算法<br/>• 领域特定模型<br/>• 针对您的数据进行微调 |
10+
| **高级 AI 管道** | 使用专用库构建复杂的 AI 工作流程 | • 多步骤处理<br/>• 自定义转换<br/>• 与 ML 框架集成 |
11+
| **可扩展性** | 在 Databend 之外处理资源密集型 AI 操作 | • 独立扩展<br/>• 优化资源分配<br/>• 高吞吐量处理 |
12+
13+
## 实现概述
14+
15+
1. 使用您的 AI/ML 代码(带有 [databend-udf](https://pypi.org/project/databend-udf) 的 Python)创建一个外部服务器
16+
2. 使用 `CREATE FUNCTION` 向 Databend 注册服务器
17+
3. 直接在 SQL 查询中调用您的 AI/ML 函数
18+
19+
## 示例:自定义 AI 模型集成
20+
21+
```python
22+
# Simple embedding UDF server demo
23+
from databend_udf import udf, UDFServer
24+
from sentence_transformers import SentenceTransformer
25+
26+
# Load pre-trained model
27+
model = SentenceTransformer('all-mpnet-base-v2') # 768-dimensional vectors
28+
29+
@udf(
30+
input_types=["STRING"],
31+
result_type="ARRAY(FLOAT)",
32+
)
33+
def ai_embed_768(inputs: list[str], headers) -> list[list[float]]:
34+
"""Generate 768-dimensional embeddings for input texts"""
35+
try:
36+
# Process inputs in a single batch
37+
embeddings = model.encode(inputs)
38+
# Convert to list format
39+
return [embedding.tolist() for embedding in embeddings]
40+
except Exception as e:
41+
print(f"Error generating embeddings: {e}")
42+
# Return empty lists in case of error
43+
return [[] for _ in inputs]
44+
45+
if __name__ == '__main__':
46+
print("Starting embedding UDF server on port 8815...")
47+
server = UDFServer("0.0.0.0:8815")
48+
server.add_function(ai_embed_768)
49+
server.serve()
50+
```
51+
52+
```sql
53+
-- Register the external function in Databend
54+
CREATE OR REPLACE FUNCTION ai_embed_768 (STRING)
55+
RETURNS ARRAY(FLOAT)
56+
LANGUAGE PYTHON
57+
HANDLER = 'ai_embed_768'
58+
ADDRESS = 'https://your-ml-server.example.com';
59+
60+
-- Use the custom embedding in queries
61+
SELECT
62+
id,
63+
title,
64+
cosine_distance(
65+
ai_embed_768(content),
66+
ai_embed_768('machine learning techniques')
67+
) AS similarity
68+
FROM articles
69+
ORDER BY similarity ASC
70+
LIMIT 5;
71+
```
72+
73+
有关设置外部函数的详细说明,请参阅 [外部函数](/guides/query/external-function)
74+
75+
## 开始使用
76+
77+
[Databend Cloud](https://databend.com) 上通过免费试用体验这些 AI 功能。
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 内置 AI 函数
2+
3+
Databend 提供了由 Azure OpenAI Service 驱动的内置 AI 函数,可将 AI 功能无缝集成到您的 SQL 工作流程中。
4+
5+
:::warning
6+
**数据隐私声明**:使用内置 AI 函数时,您的数据将被发送到 Azure OpenAI Service。 通过使用这些函数,您确认此数据传输并同意 [Azure OpenAI 数据隐私](https://learn.microsoft.com/zh-cn/legal/cognitive-services/openai/data-privacy) 条款。
7+
:::
8+
9+
| 函数 | 描述 | 使用场景 |
10+
|----------|-------------|-----------|
11+
| [ai_text_completion](/sql/sql-functions/ai-functions/ai-text-completion) | 根据提示生成文本 | • 内容生成<br/>• 问题解答<br/>• 摘要 |
12+
| [ai_embedding_vector](/sql/sql-functions/ai-functions/ai-embedding-vector) | 将文本转换为向量表示 | • 语义搜索<br/>• 文档相似度<br/>• 内容推荐 |
13+
| [cosine_distance](/sql/sql-functions/vector-distance-functions/vector-cosine-distance) | 计算向量之间的相似度 | • 查找相似文档<br/>• 对搜索结果进行排序 |
14+
15+
## Databend 中的 Vector 存储
16+
17+
Databend 使用 `ARRAY(FLOAT NOT NULL)` 数据类型存储 embedding vector,从而可以使用 SQL 中的 `cosine_distance` 函数直接进行相似度计算。
18+
19+
## 示例:使用 Embeddings 进行语义搜索
20+
21+
```sql
22+
-- 创建一个包含 embeddings 的文档表
23+
CREATE TABLE articles (
24+
id INT,
25+
title VARCHAR,
26+
content VARCHAR,
27+
embedding ARRAY(FLOAT NOT NULL)
28+
);
29+
30+
-- 存储包含 vector embeddings 的文档
31+
INSERT INTO articles (id, title, content, embedding)
32+
VALUES
33+
(1, 'Python for Data Science', 'Python 是一种通用的编程语言...',
34+
ai_embedding_vector('Python 是一种通用的编程语言...')),
35+
(2, 'Introduction to R', 'R 是一种流行的统计编程语言...',
36+
ai_embedding_vector('R 是一种流行的统计编程语言...'));
37+
38+
-- 查找语义相似的文档
39+
SELECT
40+
id, title,
41+
cosine_distance(embedding, ai_embedding_vector('如何在数据分析中使用 Python?')) AS similarity
42+
FROM articles
43+
ORDER BY similarity ASC
44+
LIMIT 3;
45+
```
46+
47+
## 示例:文本生成
48+
49+
```sql
50+
-- 根据提示生成文本
51+
SELECT ai_text_completion('用三点解释云数仓的优势:') AS completion;
52+
```
53+
54+
## 开始使用
55+
56+
[Databend Cloud](https://databend.com) 上通过免费试用体验这些 AI 功能。
Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,8 @@
1-
# Databend AI 功能
1+
# Databend AI 和 ML
22

3-
本指南介绍了 Databend 的内置 AI 函数,这些函数通过 SQL 查询实现自然语言处理任务,包括文本理解、生成等。
3+
Databend 提供了两种 AI 和 ML 集成方法:
44

5-
:::warning
6-
数据隐私和安全
7-
8-
Databend 使用 Azure OpenAI Service 进行嵌入和文本补全。当您使用这些函数时,您的数据将被发送到 Azure OpenAI。这些功能在 Databend Cloud 上默认可用。
9-
10-
**通过使用这些函数,您承认您的数据将被发送到 Azure OpenAI Service** 并同意 [Azure OpenAI 数据隐私](https://learn.microsoft.com/en-us/legal/cognitive-services/openai/data-privacy) 条款。
11-
:::
12-
13-
## 关键 AI 函数
14-
15-
| 函数 | 描述 | 何时使用 |
16-
|----------|-------------|------------|
17-
| [ai_text_completion](/sql/sql-functions/ai-functions/ai-text-completion) | 根据提示生成文本 | • 内容生成<br/>• 问题解答<br/>• 摘要<br/>• 文本扩展 |
18-
| [ai_embedding_vector](/sql/sql-functions/ai-functions/ai-embedding-vector) | 将文本转换为向量表示 | • 语义搜索<br/>• 文档相似度<br/>• 内容推荐<br/>• 文本分类 |
19-
| [cosine_distance](/sql/sql-functions/vector-distance-functions/vector-cosine-distance) | 计算向量之间的相似度 | • 查找相似文档<br/>• 对搜索结果进行排序<br/>• 衡量文本相似度 |
20-
21-
## 什么是嵌入 (Embeddings)?
22-
23-
嵌入是文本的向量表示,可以捕获语义。相似的文本在嵌入空间中具有更接近的向量,从而可以进行比较和分析,以执行诸如文档相似性和聚类之类的任务。
24-
25-
## Databend 中的向量存储
26-
27-
Databend 可以使用 `ARRAY(FLOAT NOT NULL)` 数据类型存储嵌入向量,并直接在 SQL 中使用 cosine_distance 函数执行相似度计算。
28-
29-
## 示例:文档相似度搜索
30-
31-
```sql
32-
-- 创建一个用于存储文档的表
33-
CREATE TABLE articles (
34-
id INT,
35-
title VARCHAR,
36-
content VARCHAR,
37-
embedding ARRAY(FLOAT NOT NULL)
38-
);
39-
40-
-- 插入带有嵌入的文档
41-
INSERT INTO articles (id, title, content, embedding)
42-
VALUES
43-
(1, 'Python for Data Science', 'Python 是一种通用的编程语言...',
44-
ai_embedding_vector('Python 是一种通用的编程语言...')),
45-
(2, 'Introduction to R', 'R 是一种流行的统计编程语言...',
46-
ai_embedding_vector('R 是一种流行的统计编程语言...'));
47-
48-
-- 查找与查询相似的文档
49-
SELECT
50-
id, title, content,
51-
cosine_distance(embedding, ai_embedding_vector('如何在数据分析中使用 Python?')) AS similarity
52-
FROM articles
53-
ORDER BY similarity ASC
54-
LIMIT 3;
55-
```
56-
57-
## 示例:文本补全
58-
59-
```sql
60-
-- 为提示生成补全
61-
SELECT ai_text_completion('用三点解释云数仓的优势:') AS completion;
62-
63-
-- 结果可能是:
64-
-- 1. 可扩展性:云数仓可以根据需求轻松地向上或向下扩展,
65-
-- 无需预先进行容量规划。
66-
-- 2. 成本效益:按需付费的定价模式降低了资本支出,
67-
-- 并允许企业仅为其使用的资源付费。
68-
-- 3. 可访问性:云数仓使团队可以从任何地方访问数据,
69-
-- 从而促进远程工作和全球协作。
70-
```
71-
72-
## 构建 AI 问答系统
73-
74-
您可以使用 Databend 创建一个简单的问答系统,方法是:
75-
1. 存储带有嵌入的文档
76-
2. 查找与问题相关的文档
77-
3. 使用文本补全生成答案
78-
79-
[Databend Cloud](https://databend.com) 上通过免费试用体验这些 AI 功能。
5+
| 方法 | 特性 | 使用场景 |
6+
|----------|----------|-----------|
7+
| **[外部函数](01-external-functions.md)***推荐* | • 自定义模型<br/>• GPU 部署<br/>• 自定义管道<br/>• 数据隐私 | • 专业领域<br/>• 高性能<br/>• 隐私要求 |
8+
| **[内置函数](02-built-in-functions.md)** | • 文本补全<br/>• 嵌入<br/>• Vector 操作<br/>• 零设置 | • 快速原型设计<br/>• 通用 NLP<br/>• 简单实现 |

0 commit comments

Comments
 (0)