Ragas
The Opik SDK provides a simple way to integrate with Ragas, a framework for evaluating RAG systems.
There are two main ways to use Ragas with Opik:
- Using Ragas to score traces or spans.
- Using Ragas to evaluate a RAG pipeline.
Getting started
You will first need to install the opik
and ragas
packages:
In addition, you can configure Opik using the opik configure
command which will prompt you for the correct local server address or if you are using the Cloud platform your API key:
Using Ragas to score traces or spans
Ragas provides a set of metrics that can be used to evaluate the quality of a RAG pipeline, a full list of the supported metrics can be found in the Ragas documentation.
You can use the RagasMetricWrapper
to easily integrate Ragas metrics with Opik tracking:
Once the metric wrapper is set up, you can use it to score traces or spans:
In the Opik UI, you will be able to see the full trace including the score calculation:

Using Ragas metrics to evaluate a RAG pipeline
The RagasMetricWrapper
can also be used directly within the Opik evaluation platform. This approach is much simpler than creating custom wrappers:
1. Define the Ragas metric
We will start by defining the Ragas metric, in this example we will use AnswerRelevancy
:
2. Create the metric wrapper
Simply wrap the Ragas metric with RagasMetricWrapper
:
If you are running within a Jupyter notebook, you will need to add the following line to the top of your notebook:
3. Use the metric wrapper within the Opik evaluation platform
You can now use the metric wrapper directly within the Opik evaluation platform:
The RagasMetricWrapper
automatically handles:
- Field mapping between Opik and Ragas (e.g.,
input
→user_input
,output
→response
) - Async execution of Ragas metrics
- Integration with Opik’s tracing system when
track=True
- Proper error handling for missing required fields