跳转到内容
exoticrouter.com ↗

向量嵌入

把文本变成向量,用于搜索、聚类和检索。格式是 OpenAI 的,请求会原样传给模型。

POST https://api.exoticrouter.com/v1/embeddings

cURL
curl https://api.exoticrouter.com/v1/embeddings \
-H "Authorization: Bearer $EXOTIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/text-embedding-3-small",
"input": ["The sky is blue.", "Glass is a liquid, some say."]
}'
Python
result = client.embeddings.create(
model="openai/text-embedding-3-small",
input=["The sky is blue.", "Glass is a liquid, some say."],
)
print(len(result.data), "vectors of", len(result.data[0].embedding), "numbers")
TypeScript
const result = await client.embeddings.create({
model: "openai/text-embedding-3-small",
input: ["The sky is blue.", "Glass is a liquid, some say."],
});
console.log(result.data.length, "vectors of", result.data[0].embedding.length, "numbers");
  • model 必须是向量嵌入模型,也就是模型列表里 formats 包含 embeddings 的模型。对话模型在这里不可用。
  • 请求体的其余部分会原样传给模型,包括 dimensions 和 encoding_format。
{
"object": "list",
"model": "openai/text-embedding-3-small",
"data": [
{ "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, 0.0789] },
{ "object": "embedding", "index": 1, "embedding": [-0.0312, 0.0654, 0.0098] }
],
"usage": { "prompt_tokens": 14, "total_tokens": 14 }
}

每个输入对应一个向量,顺序与发送时一致(上面的向量做了截断)。model 是模型的完整 ID。

向量嵌入请求按输入 token 数和模型的 input_per_mtok 计费,如果模型有 per_request 费用也会加上。没有输出费用。见计费。

  • 模型与 ID:在列表里找到向量嵌入模型。
  • 错误:每个状态码的含义,以及怎么处理。