Skip to content

Docs: Vectors with cosine automatically normalized #110071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/reference/mapping/types/dense-vector.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,11 @@ The document `_score` is computed as
where `dims` is the number of dimensions per vector.

`cosine`:::
Computes the cosine similarity. Note that the most efficient way to perform
cosine similarity is to normalize all vectors to unit length, and instead use
`dot_product`. You should only use `cosine` if you need to preserve the
original vectors and cannot normalize them in advance. The document `_score`
Computes the cosine similarity. During indexing {es} automatically
normalizes vectors with `cosine` similarity to unit length. This allows
to internally use `dot_product` for computing similarity, which is more efficient.
Original un-normalized vectors can be still accessed
through scripts. The document `_score`
is computed as `(1 + cosine(query, vector)) / 2`. The `cosine` similarity does
not allow vectors with zero magnitude, since cosine is not defined in this
case.
Expand Down
Loading