relevanceai.utils.distances.cosine_similarity#

Cosine similarity operations

Module Contents#

relevanceai.utils.distances.cosine_similarity.cosine_similarity_matrix(a, b, decimal=None)#
relevanceai.utils.distances.cosine_similarity.cosine_similarity(a, b)#

Cosine similarity utility

relevanceai.utils.distances.cosine_similarity.get_cosine_similarity_scores(self, documents: List[Dict[str, Any]], anchor_document: Dict[str, Any], vector_field: str) List[float]#

Compare scores based on cosine similarity

Parameters
  • other_documents – List of documents (Python Dictionaries)

  • anchor_document – Document to compare all the other documents with.

  • vector_field – The field in the documents to compare

Example

>>> documents = [{...}]
>>> ViClient.get_cosine_similarity_scores(documents[1:10], documents[0])
relevanceai.utils.distances.cosine_similarity.largest_indices(ary, n)#

Returns the n largest indices from a numpy array.

Code from: https://stackoverflow.com/questions/6910641/how-do-i-get-indices-of-n-maximum-values-in-a-numpy-array