Embeddings 接口
接口说明
- 方法:
POST - 路径:
/v1/embeddings - 完整地址:
https://anideaai.com/v1/embeddings - 用途:将文本转为向量,用于检索、召回、聚类、相似度匹配。
请求头
| 请求头 | 必填 | 说明 |
|---|---|---|
Authorization | 是 | Bearer sk-xxxxx |
Content-Type | 是 | application/json |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 向量模型名称 |
input | string/array | 是 | 单条文本或文本数组 |
encoding_format | string | 否 | float(默认)或 base64 |
dimensions | integer | 否 | 输出维度(模型支持时生效) |
cURL 示例(单条)
curl https://anideaai.com/v1/embeddings \
-H "Authorization: Bearer sk-xxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "AnideaAI 提供统一的多模型 API 网关"
}'
cURL 示例(批量)
curl https://anideaai.com/v1/embeddings \
-H "Authorization: Bearer sk-xxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": [
"电商客服回复模板",
"售后处理标准流程",
"会员权益说明"
]
}'
响应示例
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0123, -0.0345, 0.0678]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 12,
"total_tokens": 12
}
}
实际使用建议
- 检索库和查询问题必须使用同一个向量模型。
- 大批量写入时建议分批调用,避免单次请求过大。
- 入库前先做文本清洗(去重、去噪、统一语言)。