# Embedding 模型

## 什麼是 Embedding？

在 RAG (Retrieval-Augmented Generation) 處理過程中，**Embedding** 的核心任務是將經由 Parser 處理後的大量文本資料，例如文檔、知識庫內容，轉換成電腦能夠理解和比較的數值形式——即向量（vectors）。

這個轉換過程使得 RAG 系統能夠：

### 1. **理解語義**

Embedding 模型捕捉文字的深層語義含義，而不僅僅是表面詞彙。這意味著即使查詢和文檔中的措辭不同，只要語義相近，系統也能識別它們的關聯性。

### 2. **高效檢索**

將文本轉換為向量後，系統可以利用高效的向量相似度搜索算法，快速從龐大的資料庫中找到與用戶查詢最相關的文本片段。

### 3. **提升生成質量**

檢索到的相關文本片段會被提供給大型語言模型（LLM）作為上下文參考，從而幫助 LLM 生成更準確的回答。

## Embedding 在 MaiAgent 的 RAG 技術中發揮兩項關鍵作用

### 1. **將知識庫資料內容轉換為向量** ，並儲存在向量資料庫中

### 2. **將使用者的問題向量化**，與資料庫中向量進行相似度比對，找出最相關內容

<figure><img src="/files/Ris446FUAngQrS4rubh3" alt=""><figcaption><p>RAG 流程</p></figcaption></figure>

簡單來說，Embedding 是 RAG 系統的基石，它將非結構化的文本資料轉化為可計算、可比較的向量，是實現精準資訊檢索和高質量內容生成的關鍵前置步驟。

## Embedding 對 RAG 系統的影響

### 1. 檢索質量

* **語義理解深度**：高質量的 Embedding 模型能夠更準確地捕捉文本的語義內涵，提升檢索的相關性
* **上下文感知**：優秀的 Embedding 能夠理解文本的上下文關係，確保檢索結果的連貫性
* **多語言支援**：強大的多語言 Embedding 模型能夠處理跨語言的知識檢索需求

### 2. 系統性能

* **檢索速度**：Embedding 模型的向量維度和計算效率直接影響檢索響應時間
* **資源消耗**：不同 Embedding 模型對計算資源的需求不同，影響系統的擴展性
* **並行處理**：高效的 Embedding 模型能夠支援大規模並行檢索

## MaiAgent 支援的 Embedding 模型

| 模型名稱                                     | 模型開發商         | 產地  | 特性                                                  | 開源 | 部署方式              | MTEB 平均成績             |
| ---------------------------------------- | ------------- | --- | --------------------------------------------------- | -- | ----------------- | --------------------- |
| Cohere Embed v4.0                        | Cohere        | 加拿大 | 支援多語言、性能最高                                          | 否  | 需使用雲端 API 推論服務    | 尚未公開，可參考 v3.0 為 64.47 |
| Cohere Embed Multilingual v3.0 (Bedrock) | Cohere        | 加拿大 | 支援多語言、性能高                                           | 否  | 需使用雲端 API 推論服務    | 64.47                 |
| OpenAI text-embedding-3-Large            | OpenAI        | 美國  | 多語言（尤其在英語語境下表現強大）、性能中等                              | 否  | 需使用雲端 API 推論服務    | 64.68                 |
| EmbeddingGemma                           | Google        | 美國  | <mark style="color:red;">開源</mark>、支援多語言、輕量         | 是  | 可針對需求部署於雲端或地端 GPU | 61.15                 |
| Mxbai-embed-large                        | Mixedbread AI | 美國  | <mark style="color:red;">開源</mark>、效能與資源平衡佳；長上下文表現強 | 是  | 可針對需求部署於雲端或地端 GPU | 64.68                 |
| BGE-Large                                | BAAI          | 中國  | <mark style="color:red;">開源</mark>、支援多語言、輕量         | 是  | 可針對需求部署於雲端或地端 GPU | 64.23                 |
| Nomic-embed-text                         | Nomic AI      | 美國  | <mark style="color:red;">開源</mark>、輕量               | 是  | 可針對需求部署於雲端或地端 GPU | 62.39                 |
| Qwen3-Embedding 0.6B                     | Alibaba       | 中國  | <mark style="color:red;">開源</mark>、輕量               | 是  | 可針對需求部署於雲端或地端 GPU | 61.82                 |
| Granite-embedding-278m-multilingual      | IBM           | 美國  | <mark style="color:red;">開源</mark>、多語言、輕量           | 是  | 可針對需求部署於雲端或地端 GPU | 56.1                  |

{% hint style="info" %}
為確保語意表示的精確性與檢索準確度，MaiAgent 所提供的 Embedding 模型將依據MTEB（Massive Text Embedding Benchmark）標準進行選型與評估。MTEB為目前主流的語意向量化模型比較基準，涵蓋多種任務類型，包含：

* Retrieval（語意檢索）
* Classification（分類）
* Clustering（聚類）
* Reranking（重排序）
* STS（Semantic Textual Similarity 語意相似度）
* Summarization / QA / Pair Classification 等
  {% endhint %}

## MaiAgent 的 Embedding 技術優勢

### 1. 模型選擇靈活：

提供多種 Embedding 模型選擇，滿足不同需求

### 2. 部署方式多樣：

支援雲端和本地部署，確保數據安全

### 3. 性能優化：

針對 RAG 場景進行特別優化，提供最佳檢索效果

### 4. 成本效益：

根據實際需求選擇合適的模型，平衡性能和成本


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.maiagent.ai/tech/quickstart/embedding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
