Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion FlagEmbedding/evaluation/mkqa/utils/compute_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def evaluate_qa_recall(ctxs, answers, k_values: Union[int, List[int]]=100):

scores = map(get_score_partial, data)

n_docs = len(data[0]['ctxs'])
# Retrieval depth can vary by query, so size the buckets to the deepest result list.
n_docs = max(len(example['ctxs']) for example in data)
top_k_hits = [0] * n_docs
for question_hits in scores:
best_hit = next((i for i, x in enumerate(question_hits) if x), None)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_mkqa_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from FlagEmbedding.evaluation.mkqa.utils.compute_metrics import evaluate_qa_recall


def test_evaluate_qa_recall_supports_variable_retrieval_depths():
contexts = [
["no answer here"],
["still no answer", "the target answer is here"],
]
answers = [["target answer"], ["target answer"]]

recall = evaluate_qa_recall(contexts, answers, k_values=[1, 2])

assert recall == [0.0, 0.5]