Skip to main content

Overview

This guide covers best practices for getting the most out of Perplexity’s Embeddings API, including dimension reduction, batch processing, RAG patterns, and error handling.

Matryoshka Dimension Reduction

Perplexity embeddings support Matryoshka representation learning, allowing you to reduce embedding dimensions while maintaining quality. This enables faster similarity search and reduced storage costs.
Trade-off: Lower dimensions = faster search + less storage, but slightly lower quality. Start with full dimensions and reduce if needed.

Encoding Formats

Control precision and size of embedding outputs:
base64_int8 produces the same quality as bfloat16 with significantly reduced storage. Use base64_binary for extreme compression in large-scale systems.

Similarity Metrics

Perplexity embedding models produce unnormalized embeddings. Choosing the correct similarity metric is critical for accurate retrieval.
pplx-embed-v1 and pplx-embed-context-v1 natively produce unnormalized int8-quantized embeddings. You must compare them via cosine similarity. Using inner product or L2 distance directly will produce incorrect results because most embedding models are pre-normalized, but Perplexity embeddings are not.

int8 Embeddings (base64_int8)

Compare using cosine similarity. If your vector database does not support cosine similarity natively, convert the embeddings to float32 and L2-normalize them before storing:

Binary Embeddings (base64_binary)

Compare using Hamming distance. Binary embeddings encode each dimension as a single bit, so the natural distance metric is the number of differing bits between two vectors.
Most vector databases (Pinecone, Weaviate, Qdrant, Milvus) support cosine similarity as a distance metric. Verify your database’s configuration before indexing embeddings.

RAG Pattern

Combine embeddings with Perplexity’s Agentic Research API for retrieval-augmented generation:

Batch Processing

Process large datasets efficiently with async batching:

Error Handling

Tips

1

Batch requests

Send up to 512 texts per request to maximize throughput and reduce API calls.
2

Match models

Always use the same embedding model for both queries and documents to ensure consistent similarity scores.
3

Use cosine similarity

Perplexity embeddings are unnormalized. Always use cosine similarity for base64_int8 and Hamming distance for base64_binary. If your vector DB only supports inner product, L2-normalize the embeddings before storing.
4

Cache embeddings

Store computed embeddings in a vector database. Never recompute embeddings for the same text.
5

Use Matryoshka wisely

Start with full dimensions for best quality. Reduce dimensions only if you need faster search or smaller storage.
6

Binary for scale

Use base64_binary encoding format for large-scale retrieval systems where storage and speed are critical.

Quickstart

Get started with basic embeddings functionality.

Contextualized Embeddings

Document-aware embeddings for chunks with shared context.

API Reference

Complete Embeddings API documentation.

SDK Guide

Perplexity SDK features and best practices.