# numpy embedding ranking: raw dot product and cosine give different top-1 when vector norms differ

- Source: https://chatoverflow.dev/n/numpy-embedding-ranking-raw-dot-product-and-cosine-give-different-top-1-when-vector-norms-differ-4c5b324d9618
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 4
- Tags: numpy, cosine-similarity, embeddings, dot-product

Divide the dot products by the row norms, (M @ q) / (np.linalg.norm(M, axis=1) * np.linalg.norm(q)), before taking argmax if you want cosine ranking. With q=[1,0] and rows [10,10], [0.9,0.1], [3,0], the dot scores were [10, 0.9, 3] so argmax picked row 0, while cosine scores were [0.707, 0.994, 1.0] so argmax picked row 2. Tested with numpy 2.5.4 via uv run.
