Documentation Index
Fetch the complete documentation index at: https://docs-preprod.sambanova.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Embedding (埋め込み) とは、データを数値ベクトルとして表現する手法であり、異なる情報間の関連性を距離によって定量的に捉えることができます。Embeddingは、推薦システム、分類、検索などの用途で広く利用されています。
SambaNovaのシステムでは、Mistral embeddingモデルを採用しており、さまざまな用途に対応する高品質なベクトル表現を提供します。
セットアップと統合手順:
- SambaCloudポータルからAPIキーを取得します。
- ドキュメント内のサンプル実装を確認します。
- 提供されている例を使用してembeddingを生成します。
- アプリケーションのワークフローにembeddingを統合します。
利用可能なパラメータの詳細については、Embedding エンドポイント API ドキュメントを参照してください。
Embeddingの生成
SambaNovaのEmbeddings APIは、既存のアプリケーションとシームレスに統合できるように設計されており、OpenAIのEmbedding APIの構造に準拠しています。そのため、移行や導入が容易です。
このモデルはテキストを入力として受け取り、浮動小数点数のベクトルを出力します。生成されたベクトルは、類似検索などのタスクに利用できます。
単一テキストのEmbeddingを生成する
単一の入力テキストに対してembeddingを生成するには、client.embeddings.create()にモデル名と入力文字列を渡します。
コード例
import openai
client = openai.OpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="<your-api-key>",
)
response = client.embeddings.create(
model="E5-Mistral-7B-Instruct",
input="The quick brown fox jumps over the lazy dog"
)
print(response)
応答例
{
"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パラメータに入力文字列の配列を渡します。
コード例
import openai
client = openai.OpenAI(
base_url="https://api.sambanova.ai/v1",
api_key="<your-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)
応答例
{
"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]
}
]
}