code: def consistency_check(self):
      logging.info("consistency-check")
  
      logging.info("index template...")
  
      assert os.path.exists(self.index_template_file)
      index = faiss.read_index(self.index_template_file)
  
      offset = 0  # 2**24
      assert self.shard_size > offset + SMALL_DATA_SAMPLE
  
      logging.info("index shards...")
      for i in range(self.nshards):
          r = i * self.shard_size + offset
          xb = next(
              self.xb_ds.iterate(r, SMALL_DATA_SAMPLE, np.float32)
          )
          fn = f"{self.index_shard_prefix}{i}"
          assert os.path.exists(
              fn
          ), f"There is no index shard file {fn}"
          index = self._open_index_shard(fn)
          index_ivf = faiss.downcast_index(
              faiss.extract_index_ivf(index)
          )
          index_ivf.nprobe = 1
          _, I = index.search(xb, 100)
          for j in range(SMALL_DATA_SAMPLE):
              assert np.where(I[j] == j + r)[0].size > 0, (
                  f"I[j]: {I[j]}, j: {j}, i: {i}, shard_size:"
                  f" {self.shard_size}"
              )
  
      logging.info("merged index...")
      index = self._open_sharded_index()
      index_ivf = faiss.downcast_index(faiss.extract_index_ivf(index))
      index_ivf.nprobe = 1
      for i in range(self.nshards):
          r = i * self.shard_size + offset
          xb = next(
              self.xb_ds.iterate(r, SMALL_DATA_SAMPLE, np.float32)
          )
          _, I = index.search(xb, 100)
          for j in range(SMALL_DATA_SAMPLE):
              assert np.where(I[j] == j + r)[0].size > 0, (
                  f"I[j]: {I[j]}, j: {j}, i: {i}, shard_size:"
                  f" {self.shard_size}"
              )
  
      logging.info("search results...")
      index_ivf.nprobe = self.nprobe
      for i in range(0, self.xq_ds.size, self.xq_bs):
          Ifn = f"{self.knn_dir}/I{i:010}_{self.index_factory_fn}_np{self.nprobe}.npy"
          assert os.path.exists(Ifn)
          assert os.path.getsize(Ifn) > 0, f"The file {Ifn} is empty."
          logging.info(Ifn)
          I = np.load(Ifn, mmap_mode="r")
  
          assert I.shape[1] == self.k
          assert I.shape[0] == min(self.xq_bs, self.xq_ds.size - i)
          assert np.all(I[:, 1] >= 0)
  
          Dfn = f"{self.knn_dir}/D_approx{i:010}_{self.index_factory_fn}_np{self.nprobe}.npy"
          assert os.path.exists(Dfn)
          assert os.path.getsize(Dfn) > 0, f"The file {Dfn} is empty."
          logging.info(Dfn)
          D = np.load(Dfn, mmap_mode="r")
          assert D.shape == I.shape
  
          xq = next(
              self.xq_ds.iterate(i, SMALL_DATA_SAMPLE, np.float32)
          )
          D_online, I_online = index.search(xq, self.k)
          assert (
              np.where(I[:SMALL_DATA_SAMPLE] == I_online)[0].size
              / (self.k * SMALL_DATA_SAMPLE)
              > 0.95
          ), (
              "the ratio is"
              f" {np.where(I[:SMALL_DATA_SAMPLE] == I_online)[0].size / (self.k * SMALL_DATA_SAMPLE)}"
          )
          assert np.allclose(
              D[:SMALL_DATA_SAMPLE].sum(axis=1),
              D_online.sum(axis=1),
              rtol=0.01,
          ), (
              "the difference is"
              f" {D[:SMALL_DATA_SAMPLE].sum(axis=1), D_online.sum(axis=1)}"
          )
  
      logging.info("done")
  
imports: import faiss
  import numpy
  import os
  from tqdm import tqdm, trange
  import sys
  import logging
  from faiss.contrib.ondisk import merge_ondisk
  from faiss.contrib.big_batch_search import big_batch_search
  from faiss.contrib.exhaustive_search import knn_ground_truth
  from faiss.contrib.evaluation import knn_intersection_measure
  from utils import get_intersection_cardinality_frequencies, margin, is_pretransform_index
  from dataset import create_dataset_from_oivf_config
label_desc: Use image node_id 22 for calling the OfflineIVF obj's underlying member method code with example usage: obj.consistency_check() without return types