Skip to content
Hướng dẫn

Embeddings & Rerank ​

Kết hợp vector embeddings dày đặc (/v1/embeddings) với bước sắp xếp lại (reranking) giai đoạn hai bằng cross-encoder (/v1/rerank) để nâng cao độ chính xác cho Retrieval-Augmented Generation (RAG) mà vẫn giữ độ trễ thấp.

Dense Vector Embeddings ​

POSThttps://api.vanix.io/v1/embeddings
bash
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))

Sắp xếp lại giai đoạn hai (Second-Stage Reranking) ​

POSThttps://api.vanix.io/v1/rerank

Truy xuất 30–50 đoạn ứng viên hàng đầu từ kho vector của bạn (pgvector, Qdrant, Pinecone, OpenSearch), sau đó chạy rerank để giữ lại 5–8 đoạn có tín hiệu liên quan cao nhất trước khi gửi vào 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."
    ]
  }'

Nguyên tắc đảm bảo độ chính xác cho RAG

Luôn sử dụng cùng một mô hình embedding và cùng giá trị dimensions cho cả khâu lập chỉ mục tài liệu lẫn khâu nhúng truy vấn. Trộn lẫn số chiều hoặc mô hình sẽ làm sai lệch điểm tương đồng cosine (cosine similarity).

Vanix AI Cổng API Hợp Nhất · https://api.vanix.io