Class ReRankingContentAggregator
-
- All Implemented Interfaces:
-
dev.langchain4j.rag.content.aggregator.ContentAggregator
public class ReRankingContentAggregator implements ContentAggregator
A 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classReRankingContentAggregator.ReRankingContentAggregatorBuilder
-
Field Summary
Fields Modifier and Type Field Description public final static Function<Map<Query, Collection<List<Content>>>, Query>DEFAULT_QUERY_SELECTOR
-
Constructor Summary
Constructors Constructor Description ReRankingContentAggregator(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
Modifier and Type Method Description static ReRankingContentAggregator.ReRankingContentAggregatorBuilderbuilder()List<Content>aggregate(Map<Query, Collection<List<Content>>> queryToContents)Aggregates all Contents retrieved by all ContentRetrievers using all Querys. -
-
Constructor Detail
-
ReRankingContentAggregator
ReRankingContentAggregator(ScoringModel scoringModel)
-
ReRankingContentAggregator
ReRankingContentAggregator(ScoringModel scoringModel, Function<Map<Query, Collection<List<Content>>>, Query> querySelector, Double minScore)
-
ReRankingContentAggregator
ReRankingContentAggregator(ScoringModel scoringModel, Function<Map<Query, Collection<List<Content>>>, Query> querySelector, Double minScore, Integer maxResults)
-
-
Method Detail
-
builder
static ReRankingContentAggregator.ReRankingContentAggregatorBuilder builder()
-
aggregate
List<Content> aggregate(Map<Query, Collection<List<Content>>> queryToContents)
Aggregates all Contents retrieved by all ContentRetrievers using all Querys. The Contents, both on input and output, are sorted by relevance, with the most relevant Contents appearing at the beginning of
List<Content>.
-
-
-
-