> ## Documentation Index
> Fetch the complete documentation index at: https://docs.venice.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 嵌入向量

> 使用 Venice 的 /embeddings 端点生成向量嵌入，用于语义搜索、RAG 检索、聚类和推荐。

嵌入向量将文本转换为能够捕获语义信息的向量。可将其用于搜索、检索增强生成（RAG）、聚类、推荐、去重以及相似度评分。

Venice 的嵌入端点与 OpenAI 兼容。向 `/embeddings` 发送一个字符串或字符串数组，然后将返回的向量存入你的数据库或向量索引中。

## 基本用法

<CodeGroup>
  ```python Python theme={"system"}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["VENICE_API_KEY"],
      base_url="https://api.venice.ai/api/v1",
  )

  response = client.embeddings.create(
      model="text-embedding-bge-m3",
      input="Privacy-first AI infrastructure for semantic search",
  )

  vector = response.data[0].embedding
  print(len(vector), vector[:5])
  ```

  ```javascript Node.js theme={"system"}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.VENICE_API_KEY,
    baseURL: "https://api.venice.ai/api/v1",
  });

  const response = await client.embeddings.create({
    model: "text-embedding-bge-m3",
    input: "Privacy-first AI infrastructure for semantic search",
  });

  const vector = response.data[0].embedding;
  console.log(vector.length, vector.slice(0, 5));
  ```

  ```bash cURL theme={"system"}
  curl https://api.venice.ai/api/v1/embeddings \
    -H "Authorization: Bearer $VENICE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "text-embedding-bge-m3",
      "input": "Privacy-first AI infrastructure for semantic search",
      "encoding_format": "float"
    }'
  ```
</CodeGroup>

## 批量输入

传入字符串数组即可在一次请求中嵌入多段文本：

```json theme={"system"}
{
  "model": "text-embedding-bge-m3",
  "input": [
    "Venice supports private chat completions.",
    "Embeddings help retrieve relevant documents.",
    "Vector search powers RAG applications."
  ]
}
```

响应会保留输入的顺序。请将每个向量连同源文本 ID、元数据以及嵌入模型 ID 一起存储。

## 常见工作流

1. 将源文档切分为若干块。
2. 为每个块生成嵌入向量。
3. 将向量和元数据存入向量数据库。
4. 嵌入用户的查询。
5. 检索相邻的文本块。
6. 将检索到的上下文发送给聊天模型。

完整实现请参阅 [构建私有 RAG 机器人](/guides/projects/private-rag-bot)。

## 模型选择

请使用 [嵌入模型](/models/embeddings) 页面比较当前可用的嵌入模型、维度和价格。

<Note>
  索引和查询时请使用相同的嵌入模型。混用模型会导致相似度得分不可靠，因为不同模型的向量空间并不通用。
</Note>

## 相关资源

* [Embeddings API](/api-reference/endpoint/embeddings/generate)
* [嵌入模型](/models/embeddings)
* [私有 RAG 机器人指南](/guides/projects/private-rag-bot)
