Cosine Similarity From Scratch
Difficulty: Easy · Concept: Word Embeddings — The Distributional Hypothesis
Cosine similarity measures how aligned two vectors are in direction, ignoring magnitude entirely — 1 means pointing the same way, 0 means orthogonal (unrelated), -1 means pointing opposite ways. This is the standard way to compare embeddings — word embeddings, sentence embeddings, and every vector database similarity search on this site all default to it, precisely because magnitude in embedding space usually reflects something irrelevant (like word frequency) while direction reflects meaning.
Your task: implement cosine_similarity(a, b) for two equal-length lists of numbers, without NumPy.
Next: Pairwise Cosine Similarity Matrix (a harder variant), or skip ahead to TF-IDF Weight From Scratch