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 Contents against a (single) Query.
If multiple Querys are input to this aggregator
(for example, when using ExpandingQueryTransformer),
a querySelector must be provided to select a Query for ranking all Contents.
Alternatively, a custom implementation can be created to score Contents against the Querys
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 Querys are significantly different.
Before the use of a
ScoringModel, all Contents 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 Contents to be returned.
Contents scoring below this threshold (as determined by the ScoringModel)
are excluded from the results.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionReRankingContentAggregator(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:ContentAggregatorAggregates allContents retrieved by allContentRetrievers using allQuerys. TheContents, both on input and output, are sorted by relevance, with the most relevantContents appearing at the beginning ofList<Content>.- Specified by:
aggregatein interfaceContentAggregator- Parameters:
queryToContents- A map from aQueryto allList<Content>retrieved with thatQuery. Given that eachQuerycan be routed to multipleContentRetrievers, the value of this map is aCollection<List<Content>>rather than a simpleList<Content>.- Returns:
- A list of aggregated
Contents.
-
fuse
-
reRankAndFilter
-