code: def handle_IndexBinary(the_class):
      def replacement_add(self, x):
          n, d = x.shape
          x = _check_dtype_uint8(x)
          assert d == self.code_size
          self.add_c(n, swig_ptr(x))
  
      def replacement_add_with_ids(self, x, ids):
          n, d = x.shape
          x = _check_dtype_uint8(x)
          ids = np.ascontiguousarray(ids, dtype="int64")
          assert d == self.code_size
          assert ids.shape == (n,), "not same nb of vectors as ids"
          self.add_with_ids_c(n, swig_ptr(x), swig_ptr(ids))
  
      def replacement_train(self, x):
          n, d = x.shape
          x = _check_dtype_uint8(x)
          assert d == self.code_size
          self.train_c(n, swig_ptr(x))
  
      def replacement_reconstruct(self, key):
          x = np.empty(self.code_size, dtype=np.uint8)
          self.reconstruct_c(key, swig_ptr(x))
          return x
  
      def replacement_reconstruct_n(self, n0=0, ni=-1, x=None):
          if ni == -1:
              ni = self.ntotal - n0
          if x is None:
              x = np.empty((ni, self.code_size), dtype=np.uint8)
          else:
              assert x.shape == (ni, self.code_size)
  
          self.reconstruct_n_c(n0, ni, swig_ptr(x))
          return x
  
      def replacement_search(self, x, k):
          x = _check_dtype_uint8(x)
          n, d = x.shape
          assert d == self.code_size
          assert k > 0
          distances = np.empty((n, k), dtype=np.int32)
          labels = np.empty((n, k), dtype=np.int64)
          self.search_c(
              n, swig_ptr(x), k, swig_ptr(distances), swig_ptr(labels)
          )
          return distances, labels
  
      def replacement_search_preassigned(self, x, k, Iq, Dq):
          n, d = x.shape
          x = _check_dtype_uint8(x)
          assert d == self.code_size
          assert k > 0
  
          D = np.empty((n, k), dtype=np.int32)
          I = np.empty((n, k), dtype=np.int64)
  
          Iq = np.ascontiguousarray(Iq, dtype="int64")
          assert Iq.shape == (n, self.nprobe)
  
          if Dq is not None:
              Dq = np.ascontiguousarray(Dq, dtype="int32")
              assert Dq.shape == Iq.shape
  
          self.search_preassigned_c(
              n,
              swig_ptr(x),
              k,
              swig_ptr(Iq),
              swig_ptr(Dq),
              swig_ptr(D),
              swig_ptr(I),
              False,
          )
          return D, I
  
      def replacement_range_search(self, x, thresh):
          n, d = x.shape
          x = _check_dtype_uint8(x)
          assert d == self.code_size
          res = RangeSearchResult(n)
          self.range_search_c(n, swig_ptr(x), thresh, res)
          # get pointers and copy them
          lims = rev_swig_ptr(res.lims, n + 1).copy()
          nd = int(lims[-1])
          D = rev_swig_ptr(res.distances, nd).copy()
          I = rev_swig_ptr(res.labels, nd).copy()
          return lims, D, I
  
      def replacement_range_search_preassigned(
          self, x, thresh, Iq, Dq, *, params=None
      ):
          n, d = x.shape
          x = _check_dtype_uint8(x)
          assert d == self.code_size
  
          Iq = np.ascontiguousarray(Iq, dtype="int64")
          assert params is None, "params not supported"
          assert Iq.shape == (n, self.nprobe)
  
          if Dq is not None:
              Dq = np.ascontiguousarray(Dq, dtype="int32")
              assert Dq.shape == Iq.shape
  
          thresh = int(thresh)
          res = RangeSearchResult(n)
          self.range_search_preassigned_c(
              n, swig_ptr(x), thresh, swig_ptr(Iq), swig_ptr(Dq), res
          )
          # get pointers and copy them
          lims = rev_swig_ptr(res.lims, n + 1).copy()
          nd = int(lims[-1])
          D = rev_swig_ptr(res.distances, nd).copy()
          I = rev_swig_ptr(res.labels, nd).copy()
          return lims, D, I
  
      def replacement_remove_ids(self, x):
          if isinstance(x, IDSelector):
              sel = x
          else:
              assert x.ndim == 1
              x = np.ascontiguousarray(x, dtype="int64")
              sel = IDSelectorBatch(x.size, swig_ptr(x))
          return self.remove_ids_c(sel)
  
      replace_method(the_class, "add", replacement_add)
      replace_method(
          the_class, "add_with_ids", replacement_add_with_ids
      )
      replace_method(the_class, "train", replacement_train)
      replace_method(the_class, "search", replacement_search)
      replace_method(
          the_class, "range_search", replacement_range_search
      )
      replace_method(the_class, "reconstruct", replacement_reconstruct)
      replace_method(
          the_class, "reconstruct_n", replacement_reconstruct_n
      )
      replace_method(the_class, "remove_ids", replacement_remove_ids)
      replace_method(
          the_class,
          "search_preassigned",
          replacement_search_preassigned,
          ignore_missing=True,
      )
      replace_method(
          the_class,
          "range_search_preassigned",
          replacement_range_search_preassigned,
          ignore_missing=True,
      )
  
imports: import inspect
  import faiss
  import numpy
  from faiss.loader import DirectMap, IDSelector, IDSelectorArray, IDSelectorBatch, OperatingPoints, RangeSearchResult, rev_swig_ptr, swig_ptr, try_extract_index_ivf
label_desc: Use image node_id 8 for calling a global function with example usage: handle_IndexBinary(the_class) and returns: x, x, distances,  labels, D,  I, lims,  D,  I, lims,  D,  I, self