implementing cosine similarity calculation.