Skip to content

Commit

Permalink
[DOCS Vectors with cosine automatically normalized (#110071)
Browse files Browse the repository at this point in the history
PR #99445 introduced automatic normalization of dense vectors with
cosine similarity. This adds a note about this in the documentation.

Relates to #99445
  • Loading branch information
mayya-sharipova committed Jun 22, 2024
1 parent d97cb68 commit 5c87eef
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 5c87eef

Please sign in to comment.