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 HaystackEmbeddingsWrapper Class

From Leeroopedia


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

Overview

Wrapper class adapting Haystack text embedder components to the Ragas embedding interface with sync/async support.

Description

HaystackEmbeddingsWrapper adapts Haystack embedder components (AzureOpenAITextEmbedder, HuggingFaceAPITextEmbedder, OpenAITextEmbedder, SentenceTransformersTextEmbedder) to work within the Ragas embedding system by implementing the BaseRagasEmbeddings interface.

Usage

Use this wrapper when you have existing Haystack embedder components and want to use them with Ragas evaluation metrics.

Code Reference

Source Location

Signature

class HaystackEmbeddingsWrapper(BaseRagasEmbeddings):
    def __init__(
        self,
        embedder: Union[AzureOpenAITextEmbedder, HuggingFaceAPITextEmbedder, OpenAITextEmbedder, SentenceTransformersTextEmbedder],
        run_config: Optional[RunConfig] = None,
        cache: Optional[CacheInterface] = None,
    ) -> None:
        ...
    def embed_query(self, text: str) -> List[float]:
        ...
    def embed_documents(self, texts: List[str]) -> List[List[float]]:
        ...
    async def aembed_query(self, text: str) -> List[float]:
        ...
    async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
        ...

Import

from ragas.embeddings.haystack_wrapper import HaystackEmbeddingsWrapper

I/O Contract

Inputs

Name Type Required Description
embedder Haystack TextEmbedder Yes Haystack embedder component
text str Yes Text to embed

Outputs

Name Type Description
embed_query returns List[float] Embedding vector
embed_documents returns List[List[float]] Batch embedding vectors

Usage Examples

from haystack.components.embedders import OpenAITextEmbedder
from ragas.embeddings.haystack_wrapper import HaystackEmbeddingsWrapper

haystack_embedder = OpenAITextEmbedder(model="text-embedding-3-small")
ragas_embeddings = HaystackEmbeddingsWrapper(embedder=haystack_embedder)
vector = ragas_embeddings.embed_query("What is AI?")

Related Pages

Page Connections

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