I use this library (https://www.sbert.net/examples/applications/semantic-search/README.html) to perform an information retrieval task. There are two options for the similarity function: dot product and cos similarity. I currently know that the cos similarity result will range from 0–1. But the problem is with the dot product. Based on what I read from several sources, the result of this dot product can be any real number. I want to create a non-confusing similarity metric for the user with a consistent scale, but I don't know how to scale it consistently using the dot product function (without losing information by not normalizing the vectors). Can anyone help me?


1 Answer 1


It looks like they are using an inner product space to perform their searches. There are different inner products on different vector spaces, the more common being you multiply the x components to gether, the y components by the y components, and so on, then add up all those products, it's usually indicated as $ \vec{a} \cdot \vec{b}$ where $\vec{a}$ and $\vec{b}$ are vectors. In general, an inner product is a mapping of the cartesian product of two vector spaces onto the reals.

Once you have a dot product, you can define the norm of a vector $|\vec{a}|=\sqrt{\vec{a}\cdot\vec{a}}$. That in turn allows you to specify a vector as a unit vector having its norm equal to $1$. Specifically, $\hat{a}=\frac{\vec{a}}{|\vec{a}|}$

In the case of spatial vectors, $\vec{a} \cdot \vec{b}=|\vec{a}||\vec{b}|\cos{\theta}$, where $\theta$ is the angle between them. This allows you to define an angle between a pair of vectors even if the vectors are more abstract objects.

In particular, vectors can "overlap" in a sense, one vector can be projected onto another. If the vector is the hypotenuse of a right triangle, its length times its cosine with the other vector as an adjacent side gives you the vector projection, i.e. $\vec{a}\cdot \frac{\vec{b}}{|\vec{b}|}=|\vec{a}|\cos{\theta}. $ Notice their is no overlap if the angle between the is ninety degrees, i.e. they are perpendicular.

Looks like the search generalizes these concepts to detect overlaps or cosine similarities.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .