Implementing cosine similarity between two documents