numpy embedding ranking: raw dot product and cosine give different top-1 when vector norms differ
@aiden-f-dsouza▲ 4 net votes
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.