Others
RAGAS
The RAGAS metric is the average of four distinct metrics:
RAGASAnswerRelevancyMetricRAGASFaithfulnessMetricRAGASContextualPrecisionMetricRAGASContextualRecallMetric
It provides a score to holistically evaluate of your RAG pipeline's generator and retriever.
Required Arguments
To use the RagasMetric, you'll have to provide the following arguments when creating an LLMTestCase:
inputactual_outputexpected_outputretrieval_context
Usage
First, install ragas:
pip install ragasThen, use it within deepeval:
from deepeval import evaluate
from deepeval.metrics.ragas import RagasMetric
from deepeval.test_case import LLMTestCase
# Replace this with the actual output from your LLM application
actual_output = "We offer a 30-day full refund at no extra cost."
# Replace this with the expected output from your RAG generator
expected_output = "You are eligible for a 30 day full refund at no extra cost."
# Replace this with the actual retrieved context from your RAG pipeline
retrieval_context = ["All customers are eligible for a 30 day full refund at no extra cost."]
metric = RagasMetric(threshold=0.5, model="gpt-3.5-turbo")
test_case = LLMTestCase(
input="What if these shoes don't fit?",
actual_output=actual_output,
expected_output=expected_output,
retrieval_context=retrieval_context
)
metric.measure(test_case)
print(metric.score)
# or evaluate test cases in bulk
evaluate([test_case], [metric])There are THREE optional parameters when creating a RagasMetric:
- [Optional]
threshold: a float representing the minimum passing threshold, defaulted to 0.5. - [Optional]
model: a string specifying which of OpenAI's GPT models to use, OR any one of langchain's chat models of typeBaseChatModel. Defaulted to 'gpt-3.5-turbo'. - [Optional]
embeddings: any one of langchain's embedding models of typeEmbeddings. Customembeddingsprovided to theRagasMetricwill only be used in theRAGASAnswerRelevancyMetric, since it is the only metric that requires embeddings for calculating cosine similarity.
FAQs
Should I use deepeval's native RAG metrics or the RAGAS metric?
Prefer
deepeval's native RAG metrics: they give reasons, are debuggable, are JSON-confineable (avoiding ragas' NaN scores), and integrate with caching, pytest, and Confident AI. Use RagasMetric only if you're already standardized on ragas.Why am I getting NaN scores from the RAGAS metric?
ragas returns NaN when the model emits invalid JSON, and RagasMetric wraps it directly. deepeval's native RAG metrics let you JSON-confine any custom LLM to avoid this.Can I run just one sub-metric instead of the full averaged score?
Yes. Import and run
RAGASAnswerRelevancyMetric, RAGASFaithfulnessMetric, RAGASContextualRecallMetric, or RAGASContextualPrecisionMetric individually — same arguments as the combined RagasMetric.What do I need to install and provide before it will run?
Run
pip install ragas separately, and provide all four fields per test case: input, actual_output, expected_output, and retrieval_context. See the test case docs.