code: def refine_distances_knn(
      xq: np.ndarray,
      xb: np.ndarray,
      I: np.ndarray,
      metric,
  ):
      """Recompute distances between xq[i] and xb[I[i, :]]"""
      nq, k = I.shape
      xq = np.ascontiguousarray(xq, dtype="float32")
      nq2, d = xq.shape
      xb = np.ascontiguousarray(xb, dtype="float32")
      nb, d2 = xb.shape
      I = np.ascontiguousarray(I, dtype="int64")
      assert nq2 == nq
      assert d2 == d
      D = np.empty(I.shape, dtype="float32")
      D[:] = np.inf
      if metric == faiss.METRIC_L2:
          faiss.fvec_L2sqr_by_idx(
              faiss.swig_ptr(D),
              faiss.swig_ptr(xq),
              faiss.swig_ptr(xb),
              faiss.swig_ptr(I),
              d,
              nq,
              k,
          )
      else:
          faiss.fvec_inner_products_by_idx(
              faiss.swig_ptr(D),
              faiss.swig_ptr(xq),
              faiss.swig_ptr(xb),
              faiss.swig_ptr(I),
              d,
              nq,
              k,
          )
      return D
  
file_path: faiss/benchs/bench_fw/utils.py
imports: from time import perf_counter
  import logging
  from multiprocessing.pool import ThreadPool
  import numpy
  import faiss
  import functools
label_desc: Use image node_id 2 for calling a global function with example usage: refine_distances_knn(xq, xb, I, metric) and returns: D