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

# Embedding (埋め込み) 機能の実装

Embedding (埋め込み) とは、データをベクトル化した数値表現であり、情報同士の関連性を測定可能な距離として捉えることができます。Embedding は、レコメンデーションシステム、分類、検索などのアプリケーションで広く利用されています。

<Warning>
  この機能は SambaStack ユーザーのみ利用できます。E5-Mistral-7B-Instruct は SambaCloud では利用できません。
</Warning>

本システムでは Mistral の Embedding モデルを採用しており、さまざまなアプリケーション向けに高品質なベクトル表現を提供します。

セットアップと連携の手順は以下のとおりです。

1. [API キーと URL](/docs/ja/get-started/api-keys-urls) ページから API キーを取得します。
2. ドキュメント内のサンプル実装を確認します。
3. 提供されている例を使用して Embedding を生成します。
4. アプリケーションのワークフローに Embedding を組み込みます。

利用可能なパラメータの詳細については、[Embedding エンドポイントの API ドキュメント](https://docs.sambanova.ai/docs/api-reference/embeddings/create-embeddings) をご参照ください。

## Embedding の生成

SambaNova の Embeddings API は、既存のアプリケーションとシームレスに連携できるよう設計されており、[OpenAI の Embeddings API](https://platform.openai.com/docs/guides/embeddings) の構造に準拠しているため、移行や導入が容易です。

モデルはテキストを入力として受け取り、浮動小数点数のベクトルを出力します。このベクトルは、類似検索などのタスクに利用できます。

## 単一の Embedding の生成

単一の入力テキストに対して Embedding を生成するには、モデル名と入力文字列を指定して `client.embeddings.create()` を呼び出します。

### 使用例

<CodeGroup>
  ```python Python (SambaNova) theme={}
  from sambanova import SambaNova

  client = SambaNova(
      base_url="your-sambanova-base-url",
      api_key="your-sambanova-api-key",
  )

  response = client.embeddings.create(
      model="E5-Mistral-7B-Instruct",
      input="The quick brown fox jumps over the lazy dog"
  )

  print(response)
  ```

  ```python Python (OpenAI) theme={}
  from openai import OpenAI

  client = OpenAI(
      base_url="your-sambanova-base-url",
      api_key="your-sambanova-api-key",
  )

  response = client.embeddings.create(
      model="E5-Mistral-7B-Instruct",
      input="The quick brown fox jumps over the lazy dog"
  )

  print(response)
  ```
</CodeGroup>

### 応答例

```python theme={}
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [0.002843, -0.017531, ..., 0.012934],
      "index": 0
    }
  ],
  "model": "E5-Mistral-7B-Instruct",
  "usage": {
    "prompt_tokens": 10,
    "total_tokens": 10
  }
}
```

## 複数の Embedding の生成

1 回のリクエストで複数の入力に対する Embedding を生成するには、`input` パラメータに入力文字列の配列を渡します。

### 使用例

<CodeGroup>
  ```python Python (SambaNova) theme={}
  from sambanova import SambaNova

  client = SambaNova(
      base_url="your-sambanova-base-url",
      api_key="your-sambanova-api-key",
  )

  response = client.embeddings.create(
      model="E5-Mistral-7B-Instruct",
      input=[
          "Our solar system orbits the Milky Way galaxy at about 515,000 mph",
          "Jupiter's Great Red Spot is a storm that has been raging for at least 350 years."
      ]
  )

  print(response)
  ```

  ```python theme={}
  from openai import OpenAI

  client = OpenAI(
      base_url="your-sambanova-base-url",
      api_key="your-sambanova-api-key",
  )

  response = client.embeddings.create(
      model="E5-Mistral-7B-Instruct",
      input=[
          "Our solar system orbits the Milky Way galaxy at about 515,000 mph",
          "Jupiter's Great Red Spot is a storm that has been raging for at least 350 years."
      ]
  )

  print(response)
  ```
</CodeGroup>

### 応答例

```python theme={}
{
  "model": "E5-Mistral-7B-Instruct",
  "object": "list",
  "data": [
    {
      "index": 0,
      "object": "embedding",
      "embedding": [0.2633975, 0.13856208, ..., 0.04331574]
    },
    {
      "index": 1,
      "object": "embedding",
      "embedding": [-0.14496337, 0.21044481, ..., -0.16187587]
    }
  ]
}
```
