class_docstr: Wrapper object for a BlockData which similarity search via FAISS under the hood
class_docstr_tok: ["Wrapper","object","for","a","BlockData","which","similarity","search","via","FAISS","under","the","hood"]
docstr: Create a Faiss Flat index with inner product as the metric
  to search against
docstr_tok: ["Create","a","Faiss","Flat","index","with","inner","product","as","the","metric","to","search","against"]
code: def _set_mips_index(self):
      """
      Create a Faiss Flat index with inner product as the metric
      to search against
      """
      try:
          import faiss
      except ImportError:
          raise Exception(
              "Error: Please install faiss to use FaissMIPSIndex"
          )
  
      if (
          not mpu.model_parallel_is_initialized()
          or mpu.get_data_parallel_rank() == 0
      ):
          print("\n> Building index", flush=True)
  
      cpu_index = faiss.IndexFlatIP(self.embed_size)
  
      if self.use_gpu:
          # create resources and config for GpuIndex
          config = faiss.GpuMultipleClonerOptions()
          config.shard = True
          config.useFloat16 = True
          gpu_index = faiss.index_cpu_to_all_gpus(cpu_index, co=config)
          self.mips_index = faiss.IndexIDMap(gpu_index)
          if (
              not mpu.model_parallel_is_initialized()
              or mpu.get_data_parallel_rank() == 0
          ):
              print(">> Initialized index on GPU", flush=True)
      else:
          # CPU index supports IDs so wrap with IDMap
          self.mips_index = faiss.IndexIDMap(cpu_index)
          if (
              not mpu.model_parallel_is_initialized()
              or mpu.get_data_parallel_rank() == 0
          ):
              print(">> Initialized index on CPU", flush=True)
  
      # if we were constructed with a BlockData, then automatically load it
      # when the FAISS structure is built
      if self.embed_data is not None:
          self.add_embed_data(self.embed_data)
  
imports: import itertools
  import os
  import pickle
  import shutil
  import numpy
  import torch
  from megatron import get_args
  from megatron.core import mpu
label_desc: Use image node_id 2 for calling the FaissMIPSIndex obj's underlying member method code with example usage: obj._set_mips_index() without return types