Class Similarity
- All Implemented Interfaces:
Serializable
ScoringFunction.
Similarity values are constrained to the range [0.0, 1.0], where 0.0 denotes the least similarity and
1.0 the maximum similarity. This normalization allows for consistent comparison of similarity scores across
different scoring models and systems.
Primarily used in vector search and approximate nearest neighbor arrangements where results are ranked based on normalized relevance. Vector searches typically return a collection of results ordered by their similarity to the query vector.
This class is designed for use in information retrieval contexts, recommendation systems, and other applications requiring normalized comparison of results.
A Similarity instance includes both the similarity value and information about the
ScoringFunction used to generate it, providing context for proper interpretation of the score.
Instances are immutable and support range-based comparisons, making them suitable for filtering and ranking
operations. The class extends Score to inherit common scoring functionality while adding similarity-specific
semantics.
- Since:
- 4.0
- Author:
- Mark Paluch
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Range<Similarity>between(double minValue, double maxValue) Creates a newRangeby creating minimum and maximumSimilarityfrom the given valueswithout specifyinga specific scoring function.static Range<Similarity>between(double minValue, double maxValue, ScoringFunction function) Creates aRangeofSimilarityvalues using raw values and a specified scoring function.static Range<Similarity>between(Similarity min, Similarity max) Creates aRangebetween the givenSimilarity.booleanstatic Similarityof(double similarity) static Similarityof(double similarity, ScoringFunction function) Creates a newSimilarityfrom a raw value and the associatedScoringFunction.static Similarityraw(double similarity, ScoringFunction function) Create a rawSimilarityvalue without validation.
-
Method Details
-
of
- Parameters:
similarity- the similarity value without a specificScoringFunction, ranging between0and1.- Returns:
- the new
Similarity.
-
of
Creates a newSimilarityfrom a raw value and the associatedScoringFunction.- Parameters:
similarity- the similarity value in the[0.0, 1.0]range.function- the scoring function that produced this similarity.- Returns:
- a new
Similarityinstance. - Throws:
IllegalArgumentException- if the value is outside the allowed range.
-
raw
Create a rawSimilarityvalue without validation.Intended for use when accepting similarity values from trusted sources such as search engines or databases.
- Parameters:
similarity- the similarity value in the[0.0, 1.0]range.function- the scoring function that produced this similarity.- Returns:
- a new
Similarityinstance.
-
between
Creates aRangebetween the givenSimilarity.- Parameters:
min- lower value.max- upper value.- Returns:
- the
Rangebetween the given values.
-
between
Creates a newRangeby creating minimum and maximumSimilarityfrom the given valueswithout specifyinga specific scoring function.- Parameters:
minValue- lower value, ranging between0and1.maxValue- upper value, ranging between0and1.- Returns:
- the
Rangebetween the given values.
-
between
Creates aRangeofSimilarityvalues using raw values and a specified scoring function.- Parameters:
minValue- the lower similarity value.maxValue- the upper similarity value.function- the scoring function to associate with the values.- Returns:
- a
RangeofSimilarityvalues.
-
equals
-