code: def do_test(self, metric):
      d = 32
      xt, xb, xq = get_dataset_2(d, 2000, 1000, 200)
      index1 = faiss.index_factory(d, "PQ4x4np", metric)
      Dref, Iref = faiss.knn(xq, xb, 10, metric)
  
      index1.train(xt)
      index1.add(xb)
  
      D1, I1 = index1.search(xq, 100)
  
      recall1 = (I1 == Iref[:, :1]).sum()
  
      # add refine index on top
      index_flat = faiss.IndexFlat(d, metric)
      index_flat.add(xb)
  
      index2 = faiss.IndexRefine(index1, index_flat)
      index2.k_factor = 10.0
      D2, I2 = index2.search(xq, 10)
  
      # check distance is computed properly
      for i in range(len(xq)):
          x1 = xq[i]
          x2 = xb[I2[i, 5]]
          if metric == faiss.METRIC_L2:
              dref = ((x1 - x2) ** 2).sum()
          else:
              dref = np.dot(x1, x2)
          np.testing.assert_almost_equal(dref, D2[i, 5], decimal=5)
  
      # check that with refinement, the recall@10 is the same as
      # the original recall@100
      recall2 = (I2 == Iref[:, :1]).sum()
      # print("recalls", recall1, recall2)
      self.assertEqual(recall1, recall2)
  
imports: from __future__ import absolute_import, division, print_function
  import unittest
  import faiss
  import numpy
  from common_faiss_tests import Randu10k, get_dataset_2, Randu10kUnbalanced
label_desc: Use image node_id 1 for calling the TestRefine obj's underlying member method code with example usage: obj.do_test(metric) without return types