class_docstr: Builds a faiss index from a data store containing stored keys (i.e., decoder hidden states for k-NN-based MT).
  
  :param config: a KNNConfig object containing the index configuration information
  :param use_gpu: build index on a gpu
  :param device_id: device id if building index on gpu
docstr: Initialize the Faiss index to be built and conduct training if needed.
docstr_tok: ["Initialize","the","Faiss","index","to","be","built","and","conduct","training","if","needed","."]
code: def init_faiss_index(self, train_sample: Optional[np.memmap] = None):
      """Initialize the Faiss index to be built and conduct training if needed."""
      index = faiss.index_factory(
          self.config.dimension, self.config.index_type
      )
      # pylint is disabled for members that only exists in faiss-gpu
      if self.use_gpu:
          res = (
              faiss.StandardGpuResources()
          )  # pylint: disable=no-member
          co = faiss.GpuClonerOptions()  # pylint: disable=no-member
          index = faiss.index_cpu_to_gpu(
              res, self.device_id, index, co
          )  # pylint: disable=no-member
  
      if not index.is_trained and train_sample is not None:
          index.train(
              train_sample.astype(np.float32)
          )  # unfortunately, faiss index only supports float32
      elif not index.is_trained:
          logger.error(
              "Index needs training but no training sample is passed."
          )
  
      return index
  
imports: from dataclasses import dataclass
  import logging
  import numpy
  import os
  import shutil
  from typing import Optional
  from .None import arguments
  from sockeye import config, utils, constants
  from sockeye.log import setup_main_logger
label_desc: Use image node_id 2 for calling the FaissIndexBuilder obj's underlying member method code with example usage: obj.init_faiss_index(train_sample) and returns: index