# Embeddings 與 Rerank

> 透過 LLMoxy 生成向量並對文件重排序。

## Embeddings

OpenAI 相容向量請求使用 `POST /v1/embeddings`。

```bash
curl https://llmoxy.com/v1/embeddings \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": ["first document", "second document"],
    "encoding_format": "float"
  }'
```

常用欄位：

| 欄位 | 說明 |
| --- | --- |
| `model` | 必填，Embedding 模型 ID。 |
| `input` | 字串或字串陣列。 |
| `encoding_format` | 上游支援時可為 `float` 或 `base64`。 |
| `dimensions` | 支援的模型可指定輸出維度。 |
| `user` | 可選追蹤標識。 |

Gemini 風格 Embedding 請求可使用：

```txt
POST /v1/engines/{model}/embeddings
```

## Rerank

使用 `POST /v1/rerank` 呼叫 Jina、Cohere 等 Rerank 模型。

```bash
curl https://llmoxy.com/v1/rerank \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "jina-reranker-v2-base-multilingual",
    "query": "What is LLMoxy?",
    "documents": [
      "LLMoxy is an LLM gateway.",
      "A database stores rows."
    ],
    "top_n": 1,
    "return_documents": true
  }'
```

常用欄位：

| 欄位 | 說明 |
| --- | --- |
| `model` | 必填，Rerank 模型 ID。 |
| `query` | 查詢文本。 |
| `documents` | 字串或文件物件陣列。 |
| `top_n` | 最多返回的排序結果數。 |
| `return_documents` | 是否在響應中包含原始文件。 |

本文是 https://tw.llmoxy.com/docs/api-reference/embeddings-rerank 的 markdown 版本。
