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

# 向量嵌入

> 使用 Gemini Embedding 模型生成文本向量

## 快速开始

```bash theme={null}
curl -X POST "$BASE_URL/v1/embeddings" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-004",
    "input": "文本内容"
  }'
```

响应：

```json theme={null}
{
  "object": "list",
  "data": [{"embedding": [0.123, -0.456, ...], "index": 0}],
  "model": "text-embedding-004",
  "usage": {"prompt_tokens": 4, "total_tokens": 4}
}
```

## 批量嵌入

```bash theme={null}
curl -X POST "$BASE_URL/v1/embeddings" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-004",
    "input": ["第一段文本", "第二段文本", "第三段文本"]
  }'
```

## 可用模型

| 模型                     | 维度  | 说明          |
| ---------------------- | --- | ----------- |
| `text-embedding-004`   | 768 | 通用文本嵌入      |
| `gemini-embedding-001` | 768 | Gemini 嵌入模型 |

## SDK 示例

### Python

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="your-token",
    base_url="https://models.hingnet.com.cn/v1"
)

response = client.embeddings.create(
    model="text-embedding-004",
    input="文本内容"
)
print(response.data[0].embedding[:5])
```

### Node.js

```javascript theme={null}
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'your-token',
  baseURL: 'https://models.hingnet.com.cn/v1'
});

const response = await client.embeddings.create({
  model: 'text-embedding-004',
  input: '文本内容'
});
```

## 常见用途

* 语义搜索：将文档和查询转为向量，计算相似度
* 文本分类：向量作为特征输入分类模型
* 聚类去重：通过向量相似度识别重复内容
* 推荐系统：基于内容向量计算相似度
