[docs]defevaluate_retrieval(metric_inputs:List[MetricInput],metrics:Union[List[str],List[Dict]],):defdecorator_evaluate_retrieval(func:Callable[[Any],Tuple[List[List[str]],List[List[str]],List[List[float]]]],):""" Decorator for evaluating retrieval results. You can use this decorator to any method that returns (contents, scores, ids), which is the output of conventional retrieval modules. :param func: Must return (contents, scores, ids) :return: wrapper function that returns pd.DataFrame, which is the evaluation result. """@functools.wraps(func)defwrapper(*args,**kwargs)->pd.DataFrame:contents,pred_ids,scores=func(*args,**kwargs)formetric_input,pred_idinzip(metric_inputs,pred_ids):metric_input.retrieved_ids=pred_idmetric_scores={}metric_names,metric_params=cast_metrics(metrics)formetric_name,metric_paraminzip(metric_names,metric_params):ifmetric_nameinRETRIEVAL_METRIC_FUNC_DICT:metric_func=RETRIEVAL_METRIC_FUNC_DICT[metric_name]metric_scores[metric_name]=metric_func(metric_inputs=metric_inputs,**metric_param)else:warnings.warn(f"metric {metric_name} is not in supported metrics: {RETRIEVAL_METRIC_FUNC_DICT.keys()}"f"{metric_name} will be ignored.")metric_result_df=pd.DataFrame(metric_scores)execution_result_df=pd.DataFrame({"retrieved_contents":contents,"retrieved_ids":pred_ids,"retrieve_scores":scores,})result_df=pd.concat([execution_result_df,metric_result_df],axis=1)returnresult_dfreturnwrapperreturndecorator_evaluate_retrieval