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: Randomly sample `sample_size` keys as training sample.
docstr_tok: ["Randomly","sample","`","sample_size","`","keys","as","training","sample","."]
code: def build_train_sample(keys: np.ndarray, sample_size: int):
      """Randomly sample `sample_size` keys as training sample."""
      item_count, _ = keys.shape
      assert 0 < sample_size <= item_count
  
      if sample_size < item_count:
          train_sample_idx = np.random.choice(
              np.arange(item_count), size=[sample_size], replace=False
          )
          train_sample = keys[train_sample_idx]
      else:
          train_sample = keys
  
      return train_sample
  
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 5 for calling the FaissIndexBuilder obj's underlying member method code with example usage: obj.build_train_sample(keys, sample_size) and returns: train_sample