Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Embeddings API: Contextualized Vectors, Similarity Metrics, RAG and Batch

How to choose standard vs contextualized embeddings, compare vectors correctly, size indexes, and run retrieval-augmented generation with Perplexity’s API.

This page summarizes Perplexity’s documentation on the Embeddings API: generating vectors for semantic search and retrieval-augmented generation (RAG), choosing between standard and contextualized models, and avoiding the similarity-metric mistakes that break retrieval.

Generate high-quality text embeddings for semantic search, RAG, and machine learning applications.

— Perplexity, Embeddings API quickstart

Embeddings API models: which vector size and price

Section titled “Embeddings API models: which vector size and price”

Perplexity offers four embedding models. All use mean pooling, require no instruction prefix, support Matryoshka dimension reduction (MRL), and return INT8 or binary-quantized vectors by default.

Model Dimensions Context Price ($/1M tokens) Typical use
pplx-embed-v1-0.6b 1024 32K $0.004 Queries, short texts, lowest cost
pplx-embed-v1-4b 2560 32K $0.03 Higher-quality general retrieval
pplx-embed-context-v1-0.6b 1024 32K $0.008 Document chunks with shared context
pplx-embed-context-v1-4b 2560 32K $0.05 Long-document chunk retrieval

See Embeddings API pricing for current rates. Cost follows: tokens ÷ 1,000,000 × the model’s rate (for example, 40M tokens on pplx-embed-context-v1-4b is 40 × $0.05 = $2.00).

Standard embeddings vs contextualized embeddings: when to use which

Section titled “Standard embeddings vs contextualized embeddings: when to use which”

Standard embeddings treat each input independently. Use them for search queries, FAQ lines, product blurbs, or any text that stands alone.

Use standard embeddings for independent text embedding (queries, documents, and semantic search) where each text is self-contained.

— Perplexity, Standard Embeddings

Contextualized embeddings know that chunks belong to one document and encode cross-chunk context. Use them when you split articles, PDFs, reports, or code files into paragraphs or sections whose meaning depends on neighbors.

Contextualized embeddings generate embeddings for document chunks that share context awareness. Unlike standard embeddings where each text is embedded independently, contextualized embeddings understand that chunks belong to the same document and incorporate that relationship.

— Perplexity, Contextualized Embeddings

Use case Recommendation
Independent sentences, FAQs, general retrieval Standard (pplx-embed-v1-*)
Document paragraphs, PDF sections, article chunks Contextualized (pplx-embed-context-v1-*)

Call POST /v1/embeddings with a string or array of strings. Limits: up to 512 texts per request, 32K tokens per text, 120,000 tokens combined per request; empty strings are rejected.

Contextualized embeddings: nested input by document

Section titled “Contextualized embeddings: nested input by document”

Call POST /v1/contextualizedembeddings with input as an array of arrays—each inner array is one document’s chunks in original reading order. Shuffling chunks degrades quality.

Chunk ordering: Chunks within each document must be sent in the order they appear in the source document. The model uses sequential context to generate document-aware embeddings, so maintaining the original order is essential for optimal results.

— Perplexity, Contextualized Embeddings

Contextualized limits (structural ceiling): up to 512 documents, 16,000 total chunks per request, 32K tokens per document, 120,000 tokens combined; no empty strings. Rate limits count chunks per second, not only request count (rate limits).

For queries with the contextualized model, wrap each query as a one-chunk document, e.g. [[your question]], and use the same contextualized model as for the index.

Similarity metrics: cosine for int8, Hamming for binary

Section titled “Similarity metrics: cosine for int8, Hamming for binary”

Perplexity vectors are unnormalized. That differs from many embedding APIs that return unit-length vectors.

Perplexity embedding models produce unnormalized embeddings. Choosing the correct similarity metric is critical for accurate retrieval.

— Perplexity, Best Practices

encoding_format Compare with Wrong choice
base64_int8 (default) Cosine similarity Raw inner product or L2 distance
base64_binary Hamming distance Cosine on packed bits

If your vector database only supports inner product, decode int8 to float32, L2-normalize stored vectors and the query vector, then inner product equals cosine (Best Practices).

Most hosted indexes (Pinecone, Weaviate, Qdrant, Milvus) expose cosine similarity—confirm the index metric before bulk insert (Best Practices).

Matryoshka representation learning lets you request fewer dimensions without retraining the model—smaller storage and faster search at slightly lower quality.

Perplexity embeddings support Matryoshka representation learning, allowing you to reduce embedding dimensions while maintaining quality. This enables faster similarity search and reduced storage costs.

— Perplexity, Best Practices

Use the API dimensions parameter (128–1024 for 0.6b, 128–2560 for 4b); do not truncate full vectors manually. Start at full width; reduce only when latency or storage forces it.

Format Storage (per vector, order of magnitude) Metric
base64_int8 ~1 byte × dimensions Cosine
base64_binary dimensions ÷ 8 bytes Hamming

base64_int8 is the default balance of quality and size; base64_binary suits very large indexes where extreme compression matters (Best Practices).

When inserting into a vector database, create the collection with the same dimension count you request from the API (for example, 2560 for full pplx-embed-v1-4b, or your chosen Matryoshka size). Index dimension is fixed at creation (Cloudflare Vectorize dimensions).

RAG pipeline: chunk, embed, retrieve, generate

Section titled “RAG pipeline: chunk, embed, retrieve, generate”

A typical RAG flow grounded in Perplexity’s guides:

  1. Split source documents into overlapping chunks.
  2. Embed chunks (contextualized when chunks share a document).
  3. Store vectors; cache them—do not re-embed unchanged text.
  4. Embed the user question with the same model and endpoint family.
  5. Rank by cosine (or Hamming for binary).
  6. Pass top chunks to the Agent API for a grounded answer.

A self-contained retrieval-augmented generation (RAG) system that ingests documents, generates contextualized embeddings for semantic search, and produces grounded answers using the Agent API.

— Perplexity, Document Q&A with Embeddings

The RAG with Perplexity Embeddings article walks the full pipeline; Document Q&A with Embeddings is a runnable example. For production, replace in-memory numpy search with a vector database; embedding and ranking logic stay the same (Document Q&A with Embeddings).

Chunking: size, overlap, and natural boundaries

Section titled “Chunking: size, overlap, and natural boundaries”

Chunking changes what gets retrieved and how much context the generator sees. Perplexity examples often use roughly 300–500 characters (or words) with 50–100 overlap; shorter chunks improve precision, longer chunks preserve context (RAG with Perplexity Embeddings, Document Q&A with Embeddings).

Cloudflare AI Search chunking describes recursive chunking: split at paragraphs, then sentences, then subdivide until each piece fits the token budget—so you do not cut mid-thought. Tune size and overlap for your corpus; there is no single universal setting.

Retrieval tuning from the RAG guide: start with top_k=3 and min_score≈0.3; raise top_k for broad questions, raise min_score if noise appears (RAG with Perplexity Embeddings).

Batching: Send up to 512 texts per embeddings.create call; for large corpora, loop in batches (for example, 100) with short delays to avoid throttling (Best Practices, RAG with Perplexity Embeddings).

Embeddings API rate limits (queries per second by tier): Tier 0 85 QPS; Tiers 1–3 170; Tiers 4–5 335 (Rate Limits & Usage Tiers). Contextualized calls use separate chunks per second limits (Tier 0 415 chunks/s, scaling up on higher tiers).

Handle BadRequestError, RateLimitError, and other API status errors in client code (Best Practices).

Integrations such as Haystack and n8n expose the same models (pplx-embed-v1-4b / 0.6b) and contextualized POST /v1/contextualizedembeddings.

Hosted embedding models outside Perplexity (index sizing only)

Section titled “Hosted embedding models outside Perplexity (index sizing only)”

If you embed on Cloudflare Workers AI instead of Perplexity, pick a model once and match Vectorize (or any index) to its output dimensions—indexes cannot change dimension after creation (create indexes). Examples from the catalog: @cf/baai/bge-small-en-v1.5 (384), @cf/baai/bge-base-en-v1.5 (768), @cf/baai/bge-large-en-v1.5 (1024), @cf/baai/bge-m3 (1024). A separate reranker (@cf/baai/bge-reranker-base) scores query–passage pairs directly rather than producing document vectors (bge-reranker-base). Do not mix Perplexity-indexed vectors with Workers AI query vectors in one index.

  • Using inner product or L2 on raw Perplexity int8 vectors without normalization.
  • Indexing with contextualized embeddings but querying with standard (or the reverse).
  • Reordering or shuffling contextualized document chunks.
  • Creating a vector index with the wrong dimension (especially after Matryoshka reduction).
  • Re-embedding identical text on every request instead of caching in storage.
  • Ignoring combined token caps (120K per request) on large batches.
  1. Call POST /v1/embeddings or POST /v1/contextualizedembeddings with a known short string and confirm you receive a base64 payload and expected usage fields.

  2. Decode two related and two unrelated texts, compute cosine similarity per Best Practices, and confirm related pairs score higher than unrelated pairs with the same model.

  3. Verify your vector index was created with the same dimension count and metric (cosine for base64_int8) as your API settings (Vectorize dimensions).

  4. Run a end-to-end question against a small chunked document using the same model for index and query (see Document Q&A with Embeddings) and confirm retrieved chunks match the question topic.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.