Embeddings & Rerank
Combine dense vector embeddings (/v1/embeddings) with second-stage cross-encoder reranking (/v1/rerank) to improve Retrieval-Augmented Generation (RAG) precision while keeping latency low.
Dense Vector Embeddings
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))Second-Stage Reranking
POST
https://api.vanix.io/v1/rerankRetrieve top 30–50 candidate chunks from your vector store (pgvector, Qdrant, Pinecone, OpenSearch), then rerank them to keep the top 5–8 highest-signal chunks before calling your 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 Accuracy Rule
Keep the exact same embedding model and dimensions for both document indexing and query embedding. Mixing dimensions or models degrades cosine similarity scores.