Class ReRankingContentAggregator
java.lang.Object
dev.langchain4j.rag.content.aggregator.ReRankingContentAggregator
- All Implemented Interfaces:
ContentAggregator
A
The
Before the use of a
Configurable parameters (optional):
-
ContentAggregator
that performs re-ranking using a ScoringModel
, such as Cohere.
The
ScoringModel
scores Content
s against a (single) Query
.
If multiple Query
s are input to this aggregator
(for example, when using ExpandingQueryTransformer
),
a querySelector
must be provided to select a Query
for ranking all Content
s.
Alternatively, a custom implementation can be created to score Content
s against the Query
s
that were used for their retrieval (instead of a single Query
), and then re-rank based on those scores.
Although potentially more costly, this method may yield better results
when the Query
s are significantly different.
Before the use of a
ScoringModel
, all Content
s are fused in the same way
as by the DefaultContentAggregator
. For detailed information, please refer to its Javadoc.
Configurable parameters (optional):
-
minScore
: the minimum score for Content
s to be returned.
Content
s scoring below this threshold (as determined by the ScoringModel
)
are excluded from the results.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
-
Field Summary
Modifier and TypeFieldDescription -
Constructor Summary
ConstructorDescriptionReRankingContentAggregator
(ScoringModel scoringModel) ReRankingContentAggregator
(ScoringModel scoringModel, Function<Map<Query, Collection<List<Content>>>, Query> querySelector, Double minScore) ReRankingContentAggregator
(ScoringModel scoringModel, Function<Map<Query, Collection<List<Content>>>, Query> querySelector, Double minScore, Integer maxResults) -
Method Summary
-
Field Details
-
DEFAULT_QUERY_SELECTOR
-
-
Constructor Details
-
ReRankingContentAggregator
-
ReRankingContentAggregator
public ReRankingContentAggregator(ScoringModel scoringModel, Function<Map<Query, Collection<List<Content>>>, Query> querySelector, Double minScore) -
ReRankingContentAggregator
public ReRankingContentAggregator(ScoringModel scoringModel, Function<Map<Query, Collection<List<Content>>>, Query> querySelector, Double minScore, Integer maxResults)
-
-
Method Details
-
builder
-
aggregate
Description copied from interface:ContentAggregator
Aggregates allContent
s retrieved by allContentRetriever
s using allQuery
s. TheContent
s, both on input and output, are sorted by relevance, with the most relevantContent
s appearing at the beginning ofList<Content>
.- Specified by:
aggregate
in interfaceContentAggregator
- Parameters:
queryToContents
- A map from aQuery
to allList<Content>
retrieved with thatQuery
. Given that eachQuery
can be routed to multipleContentRetriever
s, the value of this map is aCollection<List<Content>>
rather than a simpleList<Content>
.- Returns:
- A list of aggregated
Content
s.
-
fuse
-
reRankAndFilter
-