Skip to content

Commit 8865227

Browse files
[DOCS Vectors with cosine automatically normalized (#110071) (#110074)
PR #99445 introduced automatic normalization of dense vectors with cosine similarity. This adds a note about this in the documentation. Relates to #99445
1 parent 1b6dcf6 commit 8865227

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/reference/mapping/types/dense-vector.asciidoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ The document `_score` is computed as
202202
where `dims` is the number of dimensions per vector.
203203
204204
`cosine`:::
205-
Computes the cosine similarity. Note that the most efficient way to perform
206-
cosine similarity is to normalize all vectors to unit length, and instead use
207-
`dot_product`. You should only use `cosine` if you need to preserve the
208-
original vectors and cannot normalize them in advance. The document `_score`
205+
Computes the cosine similarity. During indexing {es} automatically
206+
normalizes vectors with `cosine` similarity to unit length. This allows
207+
to internally use `dot_product` for computing similarity, which is more efficient.
208+
Original un-normalized vectors can be still accessed
209+
through scripts. The document `_score`
209210
is computed as `(1 + cosine(query, vector)) / 2`. The `cosine` similarity does
210211
not allow vectors with zero magnitude, since cosine is not defined in this
211212
case.

0 commit comments

Comments
 (0)