Skip to main content

RagasEvaluator

A component that uses the Ragas framework to evaluate

Basic Information

  • Type: haystack_integrations.ragas.src.haystack_integrations.components.evaluators.ragas.evaluator.RagasEvaluator

Inputs

ParameterTypeDefaultDescription
queryOptional[str]NoneThe input query from the user.
responseOptional[Union[List[ChatMessage], str]]NoneA list of ChatMessage responses (typically from a language model or agent).
documentsOptional[List[Union[Document, str]]]NoneA list of Haystack Document or strings that were retrieved for the query.
reference_contextsOptional[List[str]]NoneA list of reference contexts that should have been retrieved for the query.
multi_responsesOptional[List[str]]NoneList of multiple responses generated for the query.
referenceOptional[str]NoneA string reference answer for the query.
rubricsOptional[Dict[str, str]]NoneA dictionary of evaluation rubric, where keys represent the score and the values represent the corresponding evaluation criteria.

Outputs

ParameterTypeDefaultDescription
resultEvaluationResultA dictionary containing the evaluation result.

Overview

Work in Progress

Bear with us while we're working on adding pipeline examples and most common components connections.

A component that uses the Ragas framework to evaluate inputs against specified Ragas metrics.

Usage example:

from haystack.components.generators import OpenAIGenerator
from haystack_integrations.components.evaluators.ragas import RagasEvaluator
from ragas.metrics import ContextPrecision
from ragas.llms import HaystackLLMWrapper

llm = OpenAIGenerator(model="gpt-4o-mini")
evaluator_llm = HaystackLLMWrapper(llm)

evaluator = RagasEvaluator(
ragas_metrics=[ContextPrecision()],
evaluator_llm=evaluator_llm
)
output = evaluator.run(
query="Which is the most popular global sport?",
documents=[
"Football is undoubtedly the world's most popular sport with"
" major events like the FIFA World Cup and sports personalities"
" like Ronaldo and Messi, drawing a followership of more than 4"
" billion people."
],
reference="Football is the most popular sport with around 4 billion"
" followers worldwide",
)

output['result']

Usage Example

components:
RagasEvaluator:
type: ragas.src.haystack_integrations.components.evaluators.ragas.evaluator.RagasEvaluator
init_parameters:

Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
ragas_metricsList[Metric]A list of evaluation metrics from the Ragas library.
evaluator_llmOptional[BaseRagasLLM]NoneA language model used by metrics that require LLMs for evaluation.
evaluator_embeddingOptional[BaseRagasEmbeddings]NoneAn embedding model used by metrics that require embeddings for evaluation.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
queryOptional[str]NoneThe input query from the user.
responseOptional[Union[List[ChatMessage], str]]NoneA list of ChatMessage responses (typically from a language model or agent).
documentsOptional[List[Union[Document, str]]]NoneA list of Haystack Document or strings that were retrieved for the query.
reference_contextsOptional[List[str]]NoneA list of reference contexts that should have been retrieved for the query.
multi_responsesOptional[List[str]]NoneList of multiple responses generated for the query.
referenceOptional[str]NoneA string reference answer for the query.
rubricsOptional[Dict[str, str]]NoneA dictionary of evaluation rubric, where keys represent the score and the values represent the corresponding evaluation criteria.