Implementation:Explodinggradients Ragas LiteLLMEmbeddings Class
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Embeddings, LiteLLM |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Universal embedding interface using LiteLLM to support 100+ embedding models with intelligent batching and provider-specific optimizations.
Description
LiteLLMEmbeddings extends BaseRagasEmbedding to provide text embeddings via the LiteLLM library, which acts as a universal proxy supporting OpenAI, Azure, Cohere, HuggingFace, and 100+ other providers through a single API.
Usage
Use this provider when you need a single interface to switch between multiple embedding providers without code changes.
Code Reference
Source Location
- Repository: Explodinggradients_Ragas
- File: src/ragas/embeddings/litellm_provider.py
- Lines: 11-143
Signature
class LiteLLMEmbeddings(BaseRagasEmbedding):
PROVIDER_NAME = "litellm"
def __init__(
self,
model: str,
api_key: Optional[str] = None,
api_base: Optional[str] = None,
api_version: Optional[str] = None,
timeout: int = 600,
max_retries: int = 3,
batch_size: Optional[int] = None,
cache: Optional[CacheInterface] = None,
**litellm_params: Any,
) -> None:
...
Import
from ragas.embeddings.litellm_provider import LiteLLMEmbeddings
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | str | Yes | Model identifier (e.g., "openai/text-embedding-3-small") |
| api_key | Optional[str] | No | Provider API key |
| timeout | int | No | Request timeout in seconds (default 600) |
| batch_size | Optional[int] | No | Override automatic batch size |
Outputs
| Name | Type | Description |
|---|---|---|
| embed_text returns | List[float] | Embedding vector |
| embed_texts returns | List[List[float]] | Batch embedding vectors |
Usage Examples
from ragas.embeddings.litellm_provider import LiteLLMEmbeddings
# Use with any provider via LiteLLM
embeddings = LiteLLMEmbeddings(model="openai/text-embedding-3-small")
vector = embeddings.embed_text("What is AI?")
# Use with Azure
azure_embeddings = LiteLLMEmbeddings(
model="azure/my-deployment",
api_base="https://my-resource.openai.azure.com",
api_key="...",
)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment