Skip to content

Commit

Permalink
Mark COSINE VectorSimilarity function as deprecated (#13473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulkitg64 authored and benwtrent committed Jun 11, 2024
1 parent c6e604f commit c45616a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ http://s.apache.org/luceneversions

API Changes
---------------------
(No changes)

* GITHUB#13281: Mark COSINE VectorSimilarityFunction as deprecated. (Pulkit Gupta)

New Features
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public float compare(byte[] v1, byte[] v2) {
* vectors to unit length, and instead use {@link VectorSimilarityFunction#DOT_PRODUCT}. You
* should only use this function if you need to preserve the original vectors and cannot normalize
* them in advance. The similarity score is normalised to assure it is positive.
*
* @deprecated Use MAXIMUM_INNER_PRODUCT or DOT_PRODUCT instead
*/
@Deprecated
COSINE {
@Override
public float compare(float[] v1, float[] v2) {
Expand Down
9 changes: 8 additions & 1 deletion lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public static float dotProduct(float[] a, float[] b) {
* Returns the cosine similarity between the two vectors.
*
* @throws IllegalArgumentException if the vectors' dimensions differ.
* @deprecated use dot-product instead using normalized vectors
*/
@Deprecated
public static float cosine(float[] a, float[] b) {
if (a.length != b.length) {
throw new IllegalArgumentException("vector dimensions differ: " + a.length + "!=" + b.length);
Expand All @@ -80,7 +82,12 @@ public static float cosine(float[] a, float[] b) {
return r;
}

/** Returns the cosine similarity between the two vectors. */
/**
* Returns the cosine similarity between the two vectors.
*
* @deprecated use dot-product instead using normalized vectors
*/
@Deprecated
public static float cosine(byte[] a, byte[] b) {
if (a.length != b.length) {
throw new IllegalArgumentException("vector dimensions differ: " + a.length + "!=" + b.length);
Expand Down

0 comments on commit c45616a

Please sign in to comment.