/openai/v1/embeddings创建文本嵌入向量。将文本转换为数值向量表示,可用于语义搜索、聚类等场景。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 必填 | 嵌入模型 ID,如 "text-embedding-3-small"。 |
| input | string | string[] | 必填 | 需要嵌入的文本或文本数组。 |
| encoding_format | string | 可选 | 返回格式,可选 "float"(默认)或 "base64"。 |
| dimensions | number | 可选 | 输出向量的维度数。仅部分模型支持。 |
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://llmapi.memene.cn/openai/v1",
apiKey: "gw_memene_<keyId>_<secret>",
})
const res = await client.embeddings.create({
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog.",
"encoding_format": "float"
})
console.log(res.data[0].embedding){
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0.0023,
-0.0094,
0.0156,
-0.0078,
"..."
]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 9,
"total_tokens": 9
}
}