class_docstr: Speeds up inference calls to MatrixFactorization models by using an
  `Annoy <https://github.com/spotify/annoy>`_ index to calculate similar items and
  recommend items.
  
  Parameters
  ----------
  model : MatrixFactorizationBase
      A matrix factorization model to use for the factors
  n_trees : int, optional
      The number of trees to use when building the Annoy index. More trees gives higher precision
      when querying.
  search_k : int, optional
      Provides a way to search more trees at runtime, giving the ability to have more accurate
      results at the cost of taking more time.
  approximate_similar_items : bool, optional
      whether or not to build an Annoy index for computing similar_items
  approximate_recommend : bool, optional
      whether or not to build an Annoy index for the recommend call
  
  Attributes
  ----------
  similar_items_index : annoy.AnnoyIndex
      Annoy index for looking up similar items in the cosine space formed by the latent
      item_factors
  
  recommend_index : annoy.AnnoyIndex
      Annoy index for looking up similar items in the inner product space formed by the latent
      item_factors
class_docstr_tok: ["Speeds","up","inference","calls","to","MatrixFactorization","models","by","using","an","`","Annoy","<","https",":","\/\/github.com\/spotify\/annoy",">","`","_","index","to","calculate","similar","items","and","recommend","items",".","Parameters","--","--","--","--","--","model",":","MatrixFactorizationBase","A","matrix","factorization","model","to","use","for","the","factors","n_trees",":","int",",","optional","The","number","of","trees","to","use","when","building","the","Annoy","index",".","More","trees","gives","higher","precision","when","querying",".","search_k",":","int",",","optional","Provides","a","way","to","search","more","trees","at","runtime",",","giving","the","ability","to","have","more","accurate","results","at","the","cost","of","taking","more","time",".","approximate_similar_items",":","bool",",","optional","whether","or","not","to","build","an","Annoy","index","for","computing","similar_items","approximate_recommend",":","bool",",","optional","whether","or","not","to","build","an","Annoy","index","for","the","recommend","call","Attributes","--","--","--","--","--","similar_items_index",":","annoy.AnnoyIndex","Annoy","index","for","looking","up","similar","items","in","the","cosine","space","formed","by","the","latent","item_factors","recommend_index",":","annoy.AnnoyIndex","Annoy","index","for","looking","up","similar","items","in","the","inner","product","space","formed","by","the","latent","item_factors"]
code: def fit(self, Cui, show_progress=True, callback=None):
      # train the model
      self.model.fit(Cui, show_progress, callback)
  
      item_factors = self.model.item_factors
      if implicit.gpu.HAS_CUDA and isinstance(
          item_factors, implicit.gpu.Matrix
      ):
          item_factors = item_factors.to_numpy()
      item_factors = item_factors.astype("float32")
  
      # build up an Annoy Index with all the item_factors (for calculating
      # similar items)
      if self.approximate_similar_items:
          log.debug("Building annoy similar items index")
  
          self.similar_items_index = annoy.AnnoyIndex(
              item_factors.shape[1], "angular"
          )
          for i, row in enumerate(item_factors):
              self.similar_items_index.add_item(i, row)
          self.similar_items_index.build(self.n_trees)
  
      # build up a separate index for the inner product (for recommend
      # methods)
      if self.approximate_recommend:
          log.debug("Building annoy recommendation index")
          self.max_norm, extra = augment_inner_product_matrix(
              item_factors
          )
          self.recommend_index = annoy.AnnoyIndex(
              extra.shape[1], "angular"
          )
          for i, row in enumerate(extra):
              self.recommend_index.add_item(i, row)
          self.recommend_index.build(self.n_trees)
  
file_path: implicit/implicit/ann/annoy.py
imports: import logging
  import annoy
  import numpy
  from scipy.sparse import csr_matrix
  import implicit.gpu
  from implicit.recommender_base import RecommenderBase
  from implicit.utils import _batch_call, _filter_items_from_results, augment_inner_product_matrix
label_desc: Use image node_id 2 for calling the AnnoyModel obj's underlying member method code with example usage: obj.fit(Cui, show_progress, callback) without return types