class_docstr: This class allows the use of `Annoy <https://github.com/spotify/annoy>`_ for fast (approximate)
  vector retrieval in `most_similar()` calls of
  :class:`~gensim.models.word2vec.Word2Vec`, :class:`~gensim.models.doc2vec.Doc2Vec`,
  :class:`~gensim.models.fasttext.FastText` and :class:`~gensim.models.keyedvectors.Word2VecKeyedVectors` models.
class_docstr_tok: ["This","class","allows","the","use","of","`","Annoy","<","https",":","\/\/github.com\/spotify\/annoy",">","`","_","for","fast","(","approximate",")","vector","retrieval","in","`","most_similar","(",")","`","calls","of",":","class",":","`","~gensim.models.word2vec.Word2Vec","`",",",":","class",":","`","~gensim.models.doc2vec.Doc2Vec","`",",",":","class",":","`","~gensim.models.fasttext.FastText","`","and",":","class",":","`","~gensim.models.keyedvectors.Word2VecKeyedVectors","`","models","."]
docstr: Parameters
  ----------
  model : trained model, optional
      Use vectors from this model as the source for the index.
  num_trees : int, optional
      Number of trees for Annoy indexer.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.similarities.annoy import AnnoyIndexer
      >>> from gensim.models import Word2Vec
      >>>
      >>> sentences = [['cute', 'cat', 'say', 'meow'], ['cute', 'dog', 'say', 'woof']]
      >>> model = Word2Vec(sentences, min_count=1, seed=1)
      >>>
      >>> indexer = AnnoyIndexer(model, 2)
      >>> model.most_similar("cat", topn=2, indexer=indexer)
      [('cat', 1.0), ('dog', 0.32011348009109497)]
docstr_tok: ["Parameters","--","--","--","--","--","model",":","trained","model",",","optional","Use","vectors","from","this","model","as","the","source","for","the","index",".","num_trees",":","int",",","optional","Number","of","trees","for","Annoy","indexer",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.similarities.annoy","import","AnnoyIndexer",">",">",">","from","gensim.models","import","Word2Vec",">",">",">",">",">",">","sentences","=","[","[","'cute","'",",","'cat","'",",","'say","'",",","'meow","'","]",",","[","'cute","'",",","'dog","'",",","'say","'",",","'woof","'","]","]",">",">",">","model","=","Word2Vec","(","sentences",",","min_count=1",",","seed=1",")",">",">",">",">",">",">","indexer","=","AnnoyIndexer","(","model",",","2",")",">",">",">","model.most_similar","(","``","cat","''",",","topn=2",",","indexer=indexer",")","[","(","'cat","'",",","1.0",")",",","(","'dog","'",",","0.32011348009109497",")","]"]
code: def __init__(self, model=None, num_trees=None):
      """
      Parameters
      ----------
      model : trained model, optional
          Use vectors from this model as the source for the index.
      num_trees : int, optional
          Number of trees for Annoy indexer.
  
      Examples
      --------
      .. sourcecode:: pycon
  
          >>> from gensim.similarities.annoy import AnnoyIndexer
          >>> from gensim.models import Word2Vec
          >>>
          >>> sentences = [['cute', 'cat', 'say', 'meow'], ['cute', 'dog', 'say', 'woof']]
          >>> model = Word2Vec(sentences, min_count=1, seed=1)
          >>>
          >>> indexer = AnnoyIndexer(model, 2)
          >>> model.most_similar("cat", topn=2, indexer=indexer)
          [('cat', 1.0), ('dog', 0.32011348009109497)]
  
      """
      self.index = None
      self.labels = None
      self.model = model
      self.num_trees = num_trees
  
      if model and num_trees:
          # Extract the KeyedVectors object from whatever model we were given.
          if isinstance(self.model, Doc2Vec):
              kv = self.model.dv
          elif isinstance(self.model, (Word2Vec, FastText)):
              kv = self.model.wv
          elif isinstance(self.model, (KeyedVectors,)):
              kv = self.model
          else:
              raise ValueError(
                  "Only a Word2Vec, Doc2Vec, FastText or KeyedVectors instance can be used"
              )
          self._build_from_model(
              kv.get_normed_vectors(), kv.index_to_key, kv.vector_size
          )
  
file_path: gensim/gensim/similarities/annoy.py
imports: from __future__ import absolute_import
  import os
  from gensim import utils
  from gensim.models.doc2vec import Doc2Vec
  from gensim.models.word2vec import Word2Vec
  from gensim.models.fasttext import FastText
  from gensim.models import KeyedVectors
label_desc: Use image node_id 1 to create a new AnnoyIndexer object  with example: obj = AnnoyIndexer(model, num_trees)