alessandrobenedetti commented on code in PR #926: URL: https://github.com/apache/lucene/pull/926#discussion_r885637733
########## lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java: ########## @@ -47,63 +42,30 @@ public float convertToScore(float similarity) { DOT_PRODUCT { @Override public float compare(float[] v1, float[] v2) { - return dotProduct(v1, v2); - } - - @Override - public float convertToScore(float similarity) { - return (1 + similarity) / 2; + return (1 + dotProduct(v1, v2)) / 2; } }, /** * Cosine similarity. NOTE: the preferred way to perform cosine similarity is to normalize all * 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. + * them in advance. The similarity score is normalised to assure it is positive. */ COSINE { @Override public float compare(float[] v1, float[] v2) { - return cosine(v1, v2); - } - - @Override - public float convertToScore(float similarity) { - return (1 + similarity) / 2; + return (1 + cosine(v1, v2)) / 2; } }; /** - * If true, the scores associated with vector comparisons are nonnegative and in reverse order; - * that is, lower scores represent more similar vectors. Otherwise, if false, higher scores - * represent more similar vectors, and scores may be negative or positive. - */ - public final boolean reversed; - - VectorSimilarityFunction(boolean reversed) { - this.reversed = reversed; - } - - VectorSimilarityFunction() { - reversed = false; - } - - /** - * Calculates a similarity score between the two vectors with a specified function. + * Calculates a similarity score between the two vectors with a specified function. Higher + * similarity scores correspond to closer vectors. * * @param v1 a vector * @param v2 another vector, of the same dimension * @return the value of the similarity function applied to the two vectors */ public abstract float compare(float[] v1, float[] v2); Review Comment: Ok, not renaming that then, resolving the conversation! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org