Skip to main content
NVIDIA’s RAG evaluation metrics ship inside Ragas as a dedicated collection: AnswerAccuracy (does the response match a reference), ContextRelevance (does the retrieved context cover the question), and ResponseGroundedness (is the response supported by the context). They follow NVIDIA’s published RAG quality benchmarks and reuse Ragas’s prompting and execution machinery. This guide shows two ways to use them with Phoenix:
  • Flow 1 grades existing Phoenix traces with ResponseGroundedness and logs the scores back as span annotations.
  • Flow 2 uploads a small dataset, runs a Phoenix experiment with the same metric as an evaluator, and records a score for each run.
For the standard Ragas metrics, such as tool call accuracy and agent goal accuracy, see the Ragas evaluation guide. Both flows share the same setup. Run the code blocks below in order in a single Python session, because each block builds on imports and variables from earlier ones.

Prerequisites

  • Python 3.11+
  • An OPENAI_API_KEY from the OpenAI Platform. It’s used for both the model under trace and the judge model for NVIDIA’s metrics.
  • A running Phoenix instance. See Phoenix setup.

Install

Configure credentials

Define the metric

The shared setup creates NVIDIA’s ResponseGroundedness metric (from ragas.metrics.collections) backed by gpt-4.1 through Ragas’s llm_factory, the two-row dataset that both flows score, and a Phoenix client. The judge is pinned to gpt-4.1 because Ragas doesn’t remap max_tokens to max_completion_tokens for GPT-5 reasoning models with dotted version names, so they reject the request. gpt-4.1 is non-reasoning, accepts max_tokens, and is deterministic at temperature=0.

Flow 1: Evaluate existing traces

Trace some LLM calls

Register Phoenix tracing with OpenAI auto-instrumentation, make two calls that each echo a known answer so the trace contains predictable text, then pull the resulting spans back from Phoenix.

Run the metric

The metric exposes ascore(response=..., retrieved_contexts=[...]) directly. It’s async, so wrap each call in asyncio.run(...) from synchronous code. The OpenAI instrumentor records the full response as JSON in attributes.output.value, so the code reads the message text out of it.

Log evaluations to Phoenix

log_span_annotations_dataframe reads a dataframe indexed by span ID with score and label columns, and attaches each row to its span as an annotation.
You should see output like:
Open the nv-ragas-tracing-example-<timestamp> project in Phoenix (the name printed above). Each traced ChatCompletion span now has an nv_response_groundedness annotation with the score and the grounded or ungrounded label.
Ragas calls the judge model through the OpenAI SDK, so the auto-instrumentation also traces the judge calls into the same project as additional ChatCompletion spans. Only the two spans fetched before evaluation are annotated.

Flow 2: Run an experiment

Create a dataset

Define the task

The task returns the stored answer for each example so the experiment grades the same two responses as Flow 1. In a real experiment, the task would call your RAG application.

Wrap the metric as an evaluator

Phoenix binds experiment evaluator arguments by name: output is the task’s result and metadata is the example’s metadata. run_experiment calls evaluators synchronously, so the wrapper uses asyncio.run(...) around the metric’s ascore. Return a dictionary with score and label.

Run the experiment

You should see output like:
Open Datasets in Phoenix and select nv-ragas-experiment-example-ds-<timestamp>. The experiment nv-ragas-experiment-example-<timestamp> lists one run per example, each with its nv_response_groundedness score and label.

Troubleshooting

  • Skipping a sample by assigning it nan score. The judge call failed (rate limit, model error, and so on) and Ragas swallowed the exception. Check the warnings above this message for the actual error.
  • NotImplementedError: Async evaluator must use async_evaluate. run_experiment runs evaluators synchronously. Keep the evaluator a plain def that calls asyncio.run(...), or use async_run_experiment with an async def evaluator.
  • Spans never appear. Confirm PHOENIX_COLLECTOR_ENDPOINT points at your Phoenix instance and, if authentication is enabled, that PHOENIX_API_KEY is set.
  • Using AnswerAccuracy or ContextRelevance instead. Swap ResponseGroundedness for AnswerAccuracy (requires a reference answer) or ContextRelevance (requires the user input and retrieved contexts). The wiring is otherwise identical. See the Ragas NVIDIA metrics docs for each metric’s required fields.

Resources

Ragas NVIDIA metrics documentation

Ragas on GitHub

Ragas evaluation with Phoenix