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 Content
s in both the input and output lists are expected to be sorted by relevance,
with the most relevant Content
s 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: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
-