code: def build_index(embedding):
      n = embedding.shape[0]
      d = embedding.shape[1]
  
      index_type = "ivfflat"
      if FLAGS.index_type:
          index_type = FLAGS.index_type
  
      if index_type == "ivfflat":
          ncent = int(4 * np.sqrt(n))
          quantizer = faiss.IndexFlatL2(d)
          index = faiss.IndexIVFFlat(
              quantizer, d, ncent, faiss.METRIC_L2
          )
          index.cp.min_points_per_centroid = 4
          index.nprobe = 10
          index.train(embedding)
          index.add(embedding)
  
      return index
  
file_path: euler/knn/knn.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import pickle
  import faiss
  import numpy
  from absl import app
  from absl import flags
label_desc: Use image node_id 1 for calling a global function with example usage: build_index(embedding) and returns: index