Adding function for pairwise comparisons when computing cosine similarity