code: def _bulk_rr(recs, truth, k=None):
      # find everything with truth
      if k is not None:
          recs = recs[recs["rank"] <= k]
      joined = recs.join(truth, on=["LKTruthID", "item"], how="inner")
      # compute min ranks
      ranks = joined.groupby("LKRecID")["rank"].agg("min")
      # reciprocal ranks
      scores = 1.0 / ranks
      _log.debug(
          "have %d scores with MRR %.3f", len(scores), scores.mean()
      )
      # fill with zeros
      rec_ids = recs["LKRecID"].unique()
      scores = scores.reindex(rec_ids, fill_value=0.0)
      _log.debug(
          "filled to get %s scores w/ MRR %.3f",
          len(scores),
          scores.mean(),
      )
      # and we're done
      return scores
  
file_path: lkpy/lenskit/metrics/topn.py
imports: import logging
  import warnings
  import numpy
  import pandas
label_desc: Use image node_id 9 for calling a global function with example usage: _bulk_rr(recs, truth, k) and returns: scores