Pairwise Cosine Similarity Matrix
Difficulty: Medium · Concept: Word Embeddings — The Distributional Hypothesis
Cosine Similarity From Scratch compared exactly two vectors. A real embedding search or clustering step needs every pair at once: given vectors, produce the full matrix where entry is the cosine similarity between vector and vector — exactly the computation underneath comparing a batch of query embeddings against a batch of candidates, or building the similarity graph a vector database index is organized around.
The genuine edge case: a vector with zero magnitude (all-zero) makes cosine similarity undefined for every pair it's involved in — has no answer, so the whole computation has to fail loudly rather than silently produce a nan-filled row.
Your task: implement cosine_similarity_matrix(vectors), returning a list of lists (the matrix). Raise ValueError if any vector has zero magnitude.