code: def recip_rank(recs, truth, k=None):
      """
      Compute the reciprocal rank :cite:p:`Kantor1997-lm` of the first relevant
      item in a list of recommendations. Let :math:`\\kappa` denote the 1-based
      rank of the first relevant item in :math:`L`, with :math:`\\kappa=\\infty`
      if none of the first :math:`k` items in :math:`L` are relevant; then the
      reciprocal rank is :math:`1 / \\kappa`. If no elements are relevant, the
      reciprocal rank is therefore 0.  :cite:t:`Deshpande2004-ht` call this the
      “reciprocal hit rate”.
  
      This metric has a bulk equivalent.
      """
      if k is not None:
          recs = recs.iloc[:k]
  
      good = recs["item"].isin(truth.index)
      (npz,) = np.nonzero(good.to_numpy())
      if len(npz):
          return 1.0 / (npz[0] + 1.0)
      else:
          return 0.0
  
file_path: lkpy/lenskit/metrics/topn.py
imports: import logging
  import warnings
  import numpy
  import pandas
label_desc: Use image node_id 8 for calling a global function with example usage: recip_rank(recs, truth, k) and returns: unknown, int