[maths] Should I normalise my embeddings? What actually breaks if I do not? #94
The question in one lineEvery tutorial normalises embeddings before storing them and none of them say why. Is it just so What I have already triedStored both normalised and un-normalised copies. Rankings differ, but I cannot tell which is Where
|
Replies: 2 comments 1 reply
The short answer is that it is only so cosine and dot product agree — if So: normalise, use dot product, move on. |
|
Marking this because the question underneath — what breaks if I do not — has a sharper answer If you keep magnitude, you are doing MIPS, and MIPS is not a metric space. Inner product fails the requirements outright: The standard escape is a lift that turns MIPS into ordinary nearest-neighbour search by adding The practical answer to your actual question: normalise, unless you have measured that And the failure mode to fear. Normalise at index time and not at query time, or use one |
Marking this because the question underneath — what breaks if I do not — has a sharper answer
than either half so far.
If you keep magnitude, you are doing MIPS, and MIPS is not a metric space.
Inner product fails the requirements outright:
q·q = ‖q‖²is neither zero nor minimal, andthere is no triangle inequality. Every tree- and pivot-based index — ball trees, k-d trees,
anything that prunes using the triangle inequality — is not slower under MIPS, it is wrong.
It prunes branches that contain the answer, and it does so silently.
The standard escape is a lift that turns MIPS into ordinary nearest-neighbour search by adding
one dimension that absorbs the magnitude difference, so every do…