from typing import List
from typing import Union
from typing import Set


def get_reciprocal_rank(retrieved_docs: List, relevant_docs: Union[Set, List]) -> float:
    """
    The mean reciprocal rank is a statistic measure for evaluating any process that produces a list of possible
    responses to a sample of queries, ordered by probability of correctness.

    rank_i: The reciprocal rank of a query response is the multiplicative inverse of the rank of the first correct answer-

    :param retrieved_docs: List of queries and their retrieved documents (from evaluated system)
    :param relevant_docs:  List of queries and their relevant documents (from gold standard)
    :return:
    """

    for rank, retrieved_doc in enumerate(retrieved_docs, start=1):
        if retrieved_doc in relevant_docs:
            return 1. / rank

    return 0.