def query(self, query, k=1, sort=True):
models = self.retrieval_models
weights = maxabs_scale(self.weights) # max 1 does not crash [0,1]
agg_fn = self.aggregation_fn
# we only need to sort in the final run
combined = [m.query(query, k=k, sort=False) for m in models]
if weights is not None:
combined = [{k: v * w for k, v in r.items()} for r, w in
zip(combined, weights)]
combined = aggregate_dicts(combined, agg_fn=agg_fn, sort=True)
if sort:
# only cut-off at k if this is the final (sorted) output
combined = OrderedDict(sorted(combined.items(), key=itemgetter(1),
reverse=True)[:k])
return combined
评论列表
文章目录