嵌入(Embeddings)
将文本转换为向量,可用于语义搜索、知识库检索、文本聚类和相似度计算。
请求接口
http
POST https://api.nexusmodels.cn/v1/embeddings请求头
http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: application/json请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 嵌入模型名称 |
input | string 或 array | 是 | 需要转换为向量的文本 |
encoding_format | string | 否 | 向量编码格式,例如 float |
dimensions | integer | 否 | 输出向量维度,仅部分模型支持 |
user | string | 否 | 最终用户标识 |
单条文本请求
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/embeddings' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "YOUR_EMBEDDING_MODEL",
"input": "NexusModels 提供统一的大模型 API。",
"encoding_format": "float"
}'批量文本请求
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/embeddings' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "YOUR_EMBEDDING_MODEL",
"input": [
"第一段需要向量化的文本",
"第二段需要向量化的文本"
],
"encoding_format": "float"
}'响应示例
json
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0.0123,
-0.0456,
0.0789
]
}
],
"model": "YOUR_EMBEDDING_MODEL",
"usage": {
"prompt_tokens": 12,
"total_tokens": 12
}
}