Measure the **cosine angle** between two vectors โ the core operation behind every vector database and embedding search.
cos(a, b) = dot(a, b) / (||a|| ร ||b||)- 1.0 โ identical direction
- 0.0 โ orthogonal (unrelated)
- -1.0 โ opposite direction
cosine_similarity([1, 0, 0], [0, 1, 0]) โ 0.0 cosine_similarity([1, 1], [1, 1]) โ 1.0
Round to **5 decimal places**.
Similar Problems
Test Cases (3 visible ยท 1 hidden)
Case 1: Orthogonal
Input: cosine_similarity([1,0,0], [0,1,0])
Expected: 0.0
Case 2: Identical
Input: cosine_similarity([1,1], [1,1])
Expected: 1.0
Case 3: General case
Input: cosine_similarity([1,2,3], [4,5,6])
Expected: 0.97463
โโต Run ยท โโงโต Submit