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 newRange
by creating minimum and maximumSimilarity
from the given valueswithout specifying
a specific scoring function.static Range<Similarity>
between
(double minValue, double maxValue, ScoringFunction function) Creates aRange
ofSimilarity
values using raw values and a specified scoring function.static Range<Similarity>
between
(Similarity min, Similarity max) Creates aRange
between the givenSimilarity
.boolean
static Similarity
of
(double similarity) static Similarity
of
(double similarity, ScoringFunction function) Creates a newSimilarity
from a raw value and the associatedScoringFunction
.static Similarity
raw
(double similarity, ScoringFunction function) Create a rawSimilarity
value without validation.
-
Method Details
-
of
- Parameters:
similarity
- the similarity value without a specificScoringFunction
, ranging between0
and1
.- Returns:
- the new
Similarity
.
-
of
Creates a newSimilarity
from 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
Similarity
instance. - Throws:
IllegalArgumentException
- if the value is outside the allowed range.
-
raw
Create a rawSimilarity
value 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
Similarity
instance.
-
between
Creates aRange
between the givenSimilarity
.- Parameters:
min
- lower value.max
- upper value.- Returns:
- the
Range
between the given values.
-
between
Creates a newRange
by creating minimum and maximumSimilarity
from the given valueswithout specifying
a specific scoring function.- Parameters:
minValue
- lower value, ranging between0
and1
.maxValue
- upper value, ranging between0
and1
.- Returns:
- the
Range
between the given values.
-
between
Creates aRange
ofSimilarity
values 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
Range
ofSimilarity
values.
-
equals
-