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

# Embeddings

> 用 OpenAI 兼容的向量模型把文本转成向量

```
POST /openapi/memorylake/router/openai/v1/embeddings
```

OpenAI Embeddings。每条输入返回一个向量。下面未列出的参数会原样传给模型。

<Warning>
  目前还没有可用的向量模型，调用本端点会返回找不到模型。上线后会出现在控制台的**可用模型**中。
</Warning>

### 请求头

<ParamField header="x-memorylake-api-key" type="string">
  使用自带的模型厂商密钥（BYOK）时，在这里放 MemoryLake API Key，模型厂商密钥则放在该厂商原生的鉴权头中。您的模型厂商密钥只会转发给模型厂商，不会被保存。
</ParamField>

<ParamField header="traceparent" type="string">
  W3C 链路上下文。带上后，请求会纳入您的链路，并在 `X-Trace-ID` 中返回同一个 trace id。
</ParamField>

### 请求体

<ParamField body="input" type="string | array" required>
  要向量化的文本，或文本数组
</ParamField>

<ParamField body="model" type="string" required>
  向量模型名称
</ParamField>

<ParamField body="dimensions" type="integer">
  每个向量的维度，仅对支持的模型生效
</ParamField>

<ParamField body="encoding_format" type="string">
  向量格式。可选值：`float`、`base64`。
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.cn/openapi/memorylake/router/openai/v1/embeddings' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Content-Type: application/json' \
    -d '{
      "input": "Lisbon is my favourite city.",
      "model": "text-embedding-3-small"
    }'
  ```
</RequestExample>

### 响应

<ResponseField name="data" type="array">
  每条输入对应一个向量

  <Expandable title="Data 对象">
    <ResponseField name="embedding" type="array">向量</ResponseField>
    <ResponseField name="index" type="integer">对应输入的位置</ResponseField>
    <ResponseField name="object" type="string">固定为 `embedding`</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="model" type="string">生成向量的模型</ResponseField>
<ResponseField name="object" type="string">固定为 `list`</ResponseField>

<ResponseField name="usage" type="object">
  本次用量

  <Expandable title="Usage 对象">
    <ResponseField name="prompt_tokens" type="integer">输入的 token 数</ResponseField>
    <ResponseField name="total_tokens" type="integer">与 `prompt_tokens` 相同</ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "data": [
      {
        "embedding": [
          0.0123,
          -0.0456,
          0.0789
        ],
        "index": 0,
        "object": "embedding"
      }
    ],
    "model": "text-embedding-3-small",
    "object": "list",
    "usage": {
      "prompt_tokens": 7,
      "total_tokens": 7
    }
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.