Class DefaultContentAggregator

java.lang.Object
dev.langchain4j.rag.content.aggregator.DefaultContentAggregator
All Implemented Interfaces:
ContentAggregator

public class DefaultContentAggregator extends Object implements ContentAggregator
Default implementation of ContentAggregator intended to be suitable for the majority of use cases.

It's important to note that while efforts will be made to avoid breaking changes, the default behavior of this class may be updated in the future if it's found that the current behavior does not adequately serve the majority of use cases. Such changes would be made to benefit both current and future users.

This implementation employs Reciprocal Rank Fusion (see ReciprocalRankFuser) in two stages to aggregate all Collection<List<Content>> into a single List<Content>. The Contents in both the input and output lists are expected to be sorted by relevance, with the most relevant Contents at the beginning of the List<Content>.
Stage 1: For each Query, all List<Content> retrieved with that Query are merged into a single List<Content>.
Stage 2: All List<Content> (results from stage 1) are merged into a single List<Content>.

Example:
Input (query -> multiple lists with ranked contents):
 home animals -> [cat, dog, hamster], [cat, parrot]
 domestic animals -> [dog, horse], [cat]
 
After stage 1 (query -> single list with ranked contents):
 home animals -> [cat, dog, parrot, hamster]
 domestic animals -> [dog, cat, horse]
 
After stage 2 (single list with ranked contents):
 [cat, dog, parrot, horse, hamster]
 
See Also: