class_docstr: Compute cosine similarity of a dynamic query against a corpus of documents ('the index').
  
  The index supports adding new documents dynamically.
  
  Notes
  -----
  Scalability is achieved by sharding the index into smaller pieces, each of which fits into core memory
  The shards themselves are simply stored as files to disk and mmap'ed back as needed.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.corpora.textcorpus import TextCorpus
      >>> from gensim.test.utils import datapath, get_tmpfile
      >>> from gensim.similarities import Similarity
      >>>
      >>> corpus = TextCorpus(datapath('testcorpus.mm'))
      >>> index_temp = get_tmpfile("index")
      >>> index = Similarity(index_temp, corpus, num_features=400)  # create index
      >>>
      >>> query = next(iter(corpus))
      >>> result = index[query]  # search similar to `query` in index
      >>>
      >>> for sims in index[corpus]:  # if you have more query documents, you can submit them all at once, in a batch
      ...     pass
      >>>
      >>> # There is also a special syntax for when you need similarity of documents in the index
      >>> # to the index itself (i.e. queries=indexed documents themselves). This special syntax
      >>> # uses the faster, batch queries internally and **is ideal for all-vs-all pairwise similarities**:
      >>> for similarities in index:  # yield similarities of the 1st indexed document, then 2nd...
      ...     pass
  
  See Also
  --------
  :class:`~gensim.similarities.docsim.MatrixSimilarity`
      Index similarity (dense with cosine distance).
  :class:`~gensim.similarities.docsim.SparseMatrixSimilarity`
      Index similarity (sparse with cosine distance).
  :class:`~gensim.similarities.docsim.WmdSimilarity`
      Index similarity (with word-mover distance).
class_docstr_tok: ["Compute","cosine","similarity","of","a","dynamic","query","against","a","corpus","of","documents","(","'the","index","'",")",".","The","index","supports","adding","new","documents","dynamically",".","Notes","--","--","-","Scalability","is","achieved","by","sharding","the","index","into","smaller","pieces",",","each","of","which","fits","into","core","memory","The","shards","themselves","are","simply","stored","as","files","to","disk","and","mmap'ed","back","as","needed",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.corpora.textcorpus","import","TextCorpus",">",">",">","from","gensim.test.utils","import","datapath",",","get_tmpfile",">",">",">","from","gensim.similarities","import","Similarity",">",">",">",">",">",">","corpus","=","TextCorpus","(","datapath","(","'testcorpus.mm","'",")",")",">",">",">","index_temp","=","get_tmpfile","(","``","index","''",")",">",">",">","index","=","Similarity","(","index_temp",",","corpus",",","num_features=400",")","#","create","index",">",">",">",">",">",">","query","=","next","(","iter","(","corpus",")",")",">",">",">","result","=","index","[","query","]","#","search","similar","to","`","query","`","in","index",">",">",">",">",">",">","for","sims","in","index","[","corpus","]",":","#","if","you","have","more","query","documents",",","you","can","submit","them","all","at","once",",","in","a","batch","...","pass",">",">",">",">",">",">","#","There","is","also","a","special","syntax","for","when","you","need","similarity","of","documents","in","the","index",">",">",">","#","to","the","index","itself","(","i.e",".","queries=indexed","documents","themselves",")",".","This","special","syntax",">",">",">","#","uses","the","faster",",","batch","queries","internally","and","*","*","is","ideal","for","all-vs-all","pairwise","similarities","*","*",":",">",">",">","for","similarities","in","index",":","#","yield","similarities","of","the","1st","indexed","document",",","then","2nd","...","...","pass","See","Also","--","--","--","--",":","class",":","`","~gensim.similarities.docsim.MatrixSimilarity","`","Index","similarity","(","dense","with","cosine","distance",")",".",":","class",":","`","~gensim.similarities.docsim.SparseMatrixSimilarity","`","Index","similarity","(","sparse","with","cosine","distance",")",".",":","class",":","`","~gensim.similarities.docsim.WmdSimilarity","`","Index","similarity","(","with","word-mover","distance",")","."]
docstr: Parameters
  ----------
  output_prefix : str
      Prefix for shard filename. If None, a random filename in temp will be used.
  corpus : iterable of list of (int, number)
      Corpus in streamed Gensim bag-of-words format.
  num_features : int
      Size of the dictionary (number of features).
  num_best : int, optional
      If set, return only the `num_best` most similar documents, always leaving out documents with similarity = 0.
      Otherwise, return a full vector with one float for every document in the index.
  chunksize : int, optional
      Size of query chunks. Used internally when the query is an entire corpus.
  shardsize : int, optional
      Maximum shard size, in documents. Choose a value so that a `shardsize x chunksize` matrix of floats fits
      comfortably into your RAM.
  norm : {'l1', 'l2'}, optional
      Normalization to use.
  
  Notes
  -----
  Documents are split (internally, transparently) into shards of `shardsize` documents each, and each shard
  converted to a matrix, for faster BLAS calls. Each shard is stored to disk under `output_prefix.shard_number`.
  
  If you don't specify an output prefix, a random filename in temp will be used.
  
  If your entire index fits in memory (~1 million documents per 1GB of RAM), you can also use the
  :class:`~gensim.similarities.docsim.MatrixSimilarity` or
  :class:`~gensim.similarities.docsim.SparseMatrixSimilarity` classes directly.
  These are more simple but do not scale as well (they keep the entire index in RAM, no sharding).
  They also do not support adding new document dynamically.
code: def __init__(
      self,
      output_prefix,
      corpus,
      num_features,
      num_best=None,
      chunksize=256,
      shardsize=32768,
      norm="l2",
  ):
      """
  
      Parameters
      ----------
      output_prefix : str
          Prefix for shard filename. If None, a random filename in temp will be used.
      corpus : iterable of list of (int, number)
          Corpus in streamed Gensim bag-of-words format.
      num_features : int
          Size of the dictionary (number of features).
      num_best : int, optional
          If set, return only the `num_best` most similar documents, always leaving out documents with similarity = 0.
          Otherwise, return a full vector with one float for every document in the index.
      chunksize : int, optional
          Size of query chunks. Used internally when the query is an entire corpus.
      shardsize : int, optional
          Maximum shard size, in documents. Choose a value so that a `shardsize x chunksize` matrix of floats fits
          comfortably into your RAM.
      norm : {'l1', 'l2'}, optional
          Normalization to use.
  
      Notes
      -----
      Documents are split (internally, transparently) into shards of `shardsize` documents each, and each shard
      converted to a matrix, for faster BLAS calls. Each shard is stored to disk under `output_prefix.shard_number`.
  
      If you don't specify an output prefix, a random filename in temp will be used.
  
      If your entire index fits in memory (~1 million documents per 1GB of RAM), you can also use the
      :class:`~gensim.similarities.docsim.MatrixSimilarity` or
      :class:`~gensim.similarities.docsim.SparseMatrixSimilarity` classes directly.
      These are more simple but do not scale as well (they keep the entire index in RAM, no sharding).
      They also do not support adding new document dynamically.
  
      """
      if output_prefix is None:
          # undocumented feature: set output_prefix=None to create the server in temp
          self.output_prefix = utils.randfname(prefix="simserver")
      else:
          self.output_prefix = output_prefix
      logger.info(
          "starting similarity index under %s", self.output_prefix
      )
      self.num_features = num_features
      self.num_best = num_best
      self.norm = norm
      self.chunksize = int(chunksize)
      self.shardsize = shardsize
      self.shards = []
      self.fresh_docs, self.fresh_nnz = [], 0
  
      if corpus is not None:
          self.add_documents(corpus)
  
imports: import logging
  import itertools
  import os
  import heapq
  import warnings
  import numpy
  import scipy.sparse
  from gensim import interfaces, utils, matutils
label_desc: Use image node_id 1 to create a new Similarity object from inherited base classes: interfaces with example: obj = Similarity(output_prefix, corpus, num_features, num_best, chunksize, shardsize, norm)