Skip to main content

Overview

Embeddings convert text into numerical vectors for similarity search, retrieval, and RAG applications. LiteLLM provides a unified interface for embeddings across OpenAI, Cohere, HuggingFace, and more.

Quick Start

Basic Usage

Providers

Latest embedding models with high quality.

Dimensions Control

Some providers allow controlling output dimensions.

Encoding Format

Batch Processing

Process large datasets efficiently.

RAG (Retrieval Augmented Generation)

Async Embeddings

Parallel Processing

Caching

Cache embeddings to reduce API calls.

Usage Tracking

Error Handling

Model Comparison

Best Practices

  • Use text-embedding-3-small for most use cases
  • Use text-embedding-3-large for highest quality
  • Use Cohere for specialized search applications
  • Use Ollama for privacy-sensitive applications
  • Batch texts when possible (up to 100-2000 depending on provider)
  • Use async for concurrent requests
  • Cache embeddings for frequently used texts
  • Consider using smaller dimensions if storage is a concern
  • Use smaller models when quality difference is minimal
  • Reduce dimensions to save storage and compute
  • Cache embeddings to avoid re-computing
  • Batch process to reduce API overhead
  • Normalize text before embedding
  • Keep consistent text format across corpus
  • Use same model for queries and documents
  • Test multiple models for your specific use case

Advanced Patterns

Combine embeddings with keyword search.