埋め込み(Embeddings)とリランク
高密度ベクトル埋め込み(/v1/embeddings)と第 2 段階のクロスエンコーダーリランク(/v1/rerank)を組み合わせることで、低レイテンシを維持しながら検索拡張生成(RAG)の精度を向上できます。
高密度ベクトル埋め込み
POST
https://api.vanix.io/v1/embeddingsbash
curl https://api.vanix.io/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VANIX_API_KEY" \
-d '{
"model": "text-embedding-3-small",
"input": [
"Vanix AI supports multi-AZ auto-scaling on AWS ECS Fargate.",
"Prompt caching cuts repeated system prompt costs by up to 90%."
]
}'python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["VANIX_API_KEY"],
base_url="https://api.vanix.io/v1",
)
resp = client.embeddings.create(
model="text-embedding-3-small",
input=["Vanix AI gateway", "Unified LLM billing"],
dimensions=1024,
)
print("Vector length:", len(resp.data[0].embedding))第 2 段階のリランク
POST
https://api.vanix.io/v1/rerankベクトルストア(pgvector、Qdrant、Pinecone、OpenSearch など)から上位 30〜50 件の候補チャンクを取得した後、リランクを実行して最も関連性の高い上位 5〜8 件のチャンクに絞り込んでから LLM を呼び出します。
bash
curl https://api.vanix.io/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VANIX_API_KEY" \
-d '{
"model": "rerank-v3.5",
"query": "How do I enable prompt caching for Claude?",
"top_n": 3,
"documents": [
"Add cache_control ephemeral breakpoints to Anthropic Messages system blocks.",
"Configure ECS Fargate tasks with ARM64 Graviton images.",
"Use GET /v1/models to list enabled models for your API token."
]
}'RAG 精度の鉄則
ドキュメントのインデックス作成とクエリの埋め込みには、まったく同じ埋め込みモデルと dimensions を使用してください。モデルや次元数が混在すると、コサイン類似度スコアが劣化します。