Class DefaultContentAggregator
java.lang.Object
dev.langchain4j.rag.content.aggregator.DefaultContentAggregator
- All Implemented Interfaces:
ContentAggregator
Default implementation of
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
Stage 1: For each
Stage 2: All
Example:
Input (query -> multiple lists with ranked contents):
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:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
DefaultContentAggregator
public DefaultContentAggregator()
-
-
Method Details
-
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
-