fix indexing and cosine similarity calculation