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