Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add docs for new entity based metric #674

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/concepts/metrics/context_entities_recall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Context entities recall

This metric gives the measure of recall of the retrieved context, based on the number of entities present in both `ground_truths` and `contexts` relative to the number of entities present in the `ground_truths` alone. Simply put, it is a measure of what fraction of entities are recalled from `ground_truths`. This metric is useful in fact-based use cases like tourism help desk, historical QA, etc. This metric can help evaluate the retrieval mechanism for entities, based on comparison with entities present in `ground_truths`, because in cases where entities matter, we need the `contexts` which cover them.

To compute this metric, we use two sets, $GE$ and $CE$, as set of entities present in `ground_truths` and set of entities present in `contexts` respectively. We then take the number of elements in intersection of these sets and divide it by the number of elements present in the $GE$, given by the formula:

```{math}
:label: context_entity_recall
\text{context entity recall} = \frac{| CE \cap GE |}{| GE |}
````

```{hint}
**Ground truth**: The Taj Mahal is an ivory-white marble mausoleum on the right bank of the river Yamuna in the Indian city of Agra. It was commissioned in 1631 by the Mughal emperor Shah Jahan to house the tomb of his favorite wife, Mumtaz Mahal.

**High entity recall context**: The Taj Mahal is a symbol of love and architectural marvel located in Agra, India. It was built by the Mughal emperor Shah Jahan in memory of his beloved wife, Mumtaz Mahal. The structure is renowned for its intricate marble work and beautiful gardens surrounding it.

**Low entity recall context**: The Taj Mahal is an iconic monument in India. It is a UNESCO World Heritage Site and attracts millions of visitors annually. The intricate carvings and stunning architecture make it a must-visit destination.

````

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a "How was this calculated" section just like here. Helps non-ML users to understand the metric better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thank you.


## Example

```{code-block} python
from ragas.metrics import ContextEntityRecall
context_entity_recall = ContextEntityRecall()

# Dataset({
# features: ['ground_truths','contexts'],
# num_rows: 25
# })
dataset: Dataset

results = context_entity_recall.score(dataset)
```
2 changes: 2 additions & 0 deletions docs/concepts/metrics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Just like in any machine learning system, the performance of individual componen
- [Context recall](context_recall.md)
- [Context precision](context_precision.md)
- [Context relevancy](context_relevancy.md)
- [Context entity recall](context_entities_recall.md)

## End-to-End Evaluation

Expand All @@ -31,6 +32,7 @@ answer_relevance
context_precision
context_relevancy
context_recall
context_entities_recall
semantic_similarity
answer_correctness
critique
Expand Down
1 change: 1 addition & 0 deletions docs/references/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Metrics
ragas.metrics.answer_correctness
ragas.metrics.context_precision
ragas.metrics.context_recall
ragas.metrics.context_entity_recall

.. automodule:: ragas.metrics
:members:
Loading