compute_mrr:v0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import weave
from typing import List
from typing import Dict
from typing import Any
@weave.op()
def compute_mrr(
model_output: List[Dict[str, Any]], contexts: List[Dict[str, Any]]
) -> float:
"""
Calculate the Mean Reciprocal Rank (MRR) for a single query.
Args:
model_output (List[Dict[str, Any]]): The list of retrieved documents from the model.
Each dictionary contains:
- 'source': A unique identifier for the document.
- 'score': The relevance score of the document.
contexts (List[Dict[str, Any]]): A list of dictionaries representing the relevant contexts.
Each dictionary contains:
- 'source': A unique identifier for the relevant document.
Returns:
float: The MRR score for the given query.
MRR measures the rank of the first relevant document in the result list.
If no relevant document is found, MRR is 0.