Skip to content

Commit b9d1f47

Browse files
committed
docs: update ResponseGroundedness metric documentation to Collections API
- Added new primary example using collections-based API with ResponseGroundedness - Added synchronous usage note with .score() method - Moved legacy SingleTurnSample example to Legacy Metrics API section - Tested new example and verified it produces expected output (score: 1.0)
1 parent 8b4653c commit b9d1f47

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

docs/concepts/metrics/available_metrics/nvidia_metrics.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,28 +248,47 @@ Output:
248248
- **1** → The response is partially grounded.
249249
- **2** → The response is fully grounded (every statement can be found or inferred from the retrieved context).
250250

251+
### Example
251252

252253
```python
253-
from ragas.dataset_schema import SingleTurnSample
254-
from ragas.metrics import ResponseGroundedness
254+
from openai import AsyncOpenAI
255+
from ragas.llms import llm_factory
256+
from ragas.metrics.collections import ResponseGroundedness
255257

256-
sample = SingleTurnSample(
258+
# Setup LLM
259+
client = AsyncOpenAI()
260+
llm = llm_factory("gpt-4o-mini", client=client)
261+
262+
# Create metric
263+
scorer = ResponseGroundedness(llm=llm)
264+
265+
# Evaluate
266+
result = await scorer.ascore(
257267
response="Albert Einstein was born in 1879.",
258268
retrieved_contexts=[
259269
"Albert Einstein was born March 14, 1879.",
260270
"Albert Einstein was born at Ulm, in Württemberg, Germany.",
261271
]
262272
)
263-
264-
scorer = ResponseGroundedness(llm=evaluator_llm)
265-
score = await scorer.single_turn_ascore(sample)
266-
print(score)
273+
print(f"Response Groundedness Score: {result.value}")
267274
```
268-
Output
275+
276+
Output:
277+
269278
```
270-
1.0
279+
Response Groundedness Score: 1.0
271280
```
272281

282+
!!! note "Synchronous Usage"
283+
If you prefer synchronous code, you can use the `.score()` method instead of `.ascore()`:
284+
285+
```python
286+
result = scorer.score(
287+
response="Albert Einstein was born in 1879.",
288+
retrieved_contexts=[...]
289+
)
290+
```
291+
273292
### How It’s Calculated
274293

275294
**Step 1:** The LLM is prompted with two distinct templates to evaluate the grounding of the response with respect to the retrieved contexts. Each prompt returns a grounding rating of **0**, **1**, or **2**.
@@ -299,3 +318,35 @@ In this example, the retrieved contexts provide both the birthdate and location
299318
- **Token Usage:** Faithfulness consumes more tokens, whereas Response Groundedness is more token-efficient.
300319
- **Explainability:** Faithfulness provides transparent, reasoning for each claim, while Response Groundedness provides a raw score.
301320
- **Robust Evaluation:** Faithfulness incorporates user input for a comprehensive assessment, whereas Response Groundedness ensures consistency through dual LLM evaluations.
321+
322+
### Legacy Metrics API
323+
324+
The following examples use the legacy metrics API pattern. For new projects, we recommend using the collections-based API shown above.
325+
326+
!!! warning "Deprecation Timeline"
327+
This API will be deprecated in version 0.4 and removed in version 1.0. Please migrate to the collections-based API shown above.
328+
329+
#### Example with SingleTurnSample
330+
331+
```python
332+
from ragas.dataset_schema import SingleTurnSample
333+
from ragas.metrics import ResponseGroundedness
334+
335+
sample = SingleTurnSample(
336+
response="Albert Einstein was born in 1879.",
337+
retrieved_contexts=[
338+
"Albert Einstein was born March 14, 1879.",
339+
"Albert Einstein was born at Ulm, in Württemberg, Germany.",
340+
]
341+
)
342+
343+
scorer = ResponseGroundedness(llm=evaluator_llm)
344+
score = await scorer.single_turn_ascore(sample)
345+
print(score)
346+
```
347+
348+
Output:
349+
350+
```
351+
1.0
352+
```

0 commit comments

Comments
 (0)