'Returns the similarity between two documents in the model as a number between 0.0-1.0,
based on the document feature weight (e.g., tf * idf of words in the text).
cos = dot(v1, v2) / (norm(v1) * norm(v2))'

def cosine_similarity(self, document1, document2):

    id1 = document1.id
    id2 = document2.id
    if ((id1, id2) in self._cos):
        return self._cos[(id1, id2)]
    if ((id2, id1) in self._cos):
        return self._cos[(id2, id1)]
    if (not getattr(self, 'lsa', None)):
        v1 = document1.vector
        v2 = document2.vector
        s = cosine_similarity(v1, v2)
    else:
        v1 = (((id1 in self.lsa) and self.lsa[id1]) or self._lsa.transform(document1))
        v2 = (((id2 in self.lsa) and self.lsa[id2]) or self._lsa.transform(document2))
        s = cosine_similarity(v1, v2)
    if ((document1.model == self) and (document2.model == self)):
        self._cos[(id1, id2)] = s
    return s
