class_docstr: Approximate Nearest Neighbor Search with Faiss (https://github.com/facebookresearch/faiss).
  Faiss provides both CPU and GPU implementation. More on the algorithms:
  https://github.com/facebookresearch/faiss/wiki
  
  Parameters
  ----------------
  model: object: :obj:`cornac.models.Recommender`, required
      Trained recommender model which to get user/item vectors from.
  
  nlist: int, default: 100
      The number of cells used for building the index.
  
  nprobe: int, default: 50
      The number of cells (out of nlist) that are visited to perform a search.
  
  use_gpu : bool, optional
      Whether or not to run Faiss on GPU. Requires faiss-gpu to be installed
      instead of faiss-cpu.
  
  num_threads: int, optional, default: -1
      Default number of threads used for building index. If num_threads = -1,
      all cores will be used.
  
  seed: int, optional, default: None
      Random seed for reproducibility.
  
  name: str, required
      Name of the recommender model.
  
  verbose: boolean, optional, default: False
      When True, running logs are displayed.
class_docstr_tok: ["Approximate","Nearest","Neighbor","Search","with","Faiss","(","https",":","\/\/github.com\/facebookresearch\/faiss",")",".","Faiss","provides","both","CPU","and","GPU","implementation",".","More","on","the","algorithms",":","https",":","\/\/github.com\/facebookresearch\/faiss\/wiki","Parameters","--","--","--","--","--","--","--","--","model",":","object",":",":","obj",":","`","cornac.models.Recommender","`",",","required","Trained","recommender","model","which","to","get","user\/item","vectors","from",".","nlist",":","int",",","default",":","100","The","number","of","cells","used","for","building","the","index",".","nprobe",":","int",",","default",":","50","The","number","of","cells","(","out","of","nlist",")","that","are","visited","to","perform","a","search",".","use_gpu",":","bool",",","optional","Whether","or","not","to","run","Faiss","on","GPU",".","Requires","faiss-gpu","to","be","installed","instead","of","faiss-cpu",".","num_threads",":","int",",","optional",",","default",":","-1","Default","number","of","threads","used","for","building","index",".","If","num_threads","=","-1",",","all","cores","will","be","used",".","seed",":","int",",","optional",",","default",":","None","Random","seed","for","reproducibility",".","name",":","str",",","required","Name","of","the","recommender","model",".","verbose",":","boolean",",","optional",",","default",":","False","When","True",",","running","logs","are","displayed","."]
docstr: Building index from the base recommender model.
docstr_tok: ["Building","index","from","the","base","recommender","model","."]
code: def build_index(self):
      """Building index from the base recommender model."""
      super().build_index()
  
      import faiss
  
      faiss.omp_set_num_threads(self.num_threads)
  
      SUPPORTED_MEASURES = {
          MEASURE_L2: faiss.METRIC_L2,
          MEASURE_DOT: faiss.METRIC_INNER_PRODUCT,
          MEASURE_COSINE: faiss.METRIC_INNER_PRODUCT,
      }
  
      assert self.measure in SUPPORTED_MEASURES
  
      if self.measure == MEASURE_COSINE:
          self.item_vectors /= np.linalg.norm(
              self.item_vectors, axis=1
          )[:, np.newaxis]
  
      self.item_vectors = self.item_vectors.astype("float32")
  
      self.index = faiss.IndexIVFFlat(
          faiss.IndexFlat(self.item_vectors.shape[1]),
          self.item_vectors.shape[1],
          self.nlist,
          SUPPORTED_MEASURES[self.measure],
      )
  
      if self.use_gpu:
          self.index = faiss.index_cpu_to_all_gpus(self.index)
  
      self.index.train(self.item_vectors)
      self.index.add(self.item_vectors)
      self.index.nprobe = self.nprobe
  
file_path: cornac/cornac/models/ann/recom_ann_faiss.py
imports: import multiprocessing
  import numpy
  from ..recommender import MEASURE_L2, MEASURE_DOT, MEASURE_COSINE
  from .recom_ann_base import BaseANN
label_desc: Use image node_id 2 for calling the FaissANN obj's underlying member method code with example usage: obj.build_index() without return types