Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Explodinggradients Ragas OpenAIEmbeddings Provider

From Leeroopedia


Knowledge Sources
Domains Embeddings, OpenAI
Last Updated 2026-02-10 00:00 GMT

Overview

OpenAI embeddings provider with batch optimization and automatic sync/async client detection.

Description

OpenAIEmbeddings extends BaseRagasEmbedding to provide text embeddings using the OpenAI Python client. It supports both sync and async clients with automatic detection, tracks usage analytics, and defaults to the text-embedding-3-small model.

Usage

Use this provider when working directly with OpenAI's embedding API. Requires a pre-configured OpenAI client.

Code Reference

Source Location

Signature

class OpenAIEmbeddings(BaseRagasEmbedding):
    PROVIDER_NAME = "openai"
    REQUIRES_CLIENT = True
    DEFAULT_MODEL = "text-embedding-3-small"

    def __init__(
        self,
        client: Any,
        model: str = "text-embedding-3-small",
        cache: Optional[CacheInterface] = None,
    ) -> None:
        ...

Import

from ragas.embeddings.openai_provider import OpenAIEmbeddings

I/O Contract

Inputs

Name Type Required Description
client Any Yes Pre-configured OpenAI client (sync or async)
model str No Embedding model name (default "text-embedding-3-small")

Outputs

Name Type Description
embed_text returns List[float] Embedding vector
embed_texts returns List[List[float]] Batch embedding vectors

Usage Examples

from openai import OpenAI
from ragas.embeddings.openai_provider import OpenAIEmbeddings

client = OpenAI()
embeddings = OpenAIEmbeddings(client=client, model="text-embedding-3-small")
vector = embeddings.embed_text("What is machine learning?")
print(len(vector))

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment