Standard library only · runs in your browser
"The bot gets order questions wrong." Someone proposes a bigger embedding model. Someone else wants to rewrite the prompt. Before anyone changes anything, measure where retrieval fails, per kind of question, so the fix goes where the misses are.
You have the ranked documents retrieval returned for seven test questions, and labels saying which documents are relevant.
Write retrieval_report(results, labels, k), returning:
{"overall": {"recall_at_k": 0.75, "mrr": 0.667, "queries": 6},
"by_category": {"order_status": {"recall_at_k": 0.25, "mrr": 0.5, "queries": 2}, ...},
"worst_category": "order_status",
"unlabeled": 1}k distinct documents of each result list. The same id appearing twice counts once.unlabeled.worst_category has the lowest recall@k, ties broken alphabetically. If nothing is labelled, overall and worst_category are None.retrieval_report(results: list[dict], labels: dict, k: int) -> dict