임베딩 및 리랭크
밀집 벡터 임베딩(/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개의 후보 청크를 먼저 검색한 뒤, LLM을 호출하기 전에 리랭킹하여 신호 강도가 가장 높은 상위 5–8개 청크만 추려내세요:
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**를 사용하세요. 차원 수나 모델을 혼용하면 코사인 유사도 점수가 저하됩니다.