FusionRanker.rerank:v0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import weave
from typing import List
from typing import Dict
from typing import Any
import json
import numpy as np
@weave.op()
def rerank(self, *docs: List[List[Dict[Any, Any]]], k=60):
"""
Reranks the given documents using a fusion ranking approach.
Args:
docs (List[List[Dict[Any, Any]]]): A variable number of lists of documents to be reranked.
k (int, optional): A parameter to adjust the ranking score. Defaults to 60.
Returns:
List[Dict[Any, Any]]: A list of reranked documents with fusion scores.
"""
class NumpyEncoder(json.JSONEncoder):
"""
Custom JSON encoder for handling numpy data types.
"""
def default(self, obj):
if isinstance(obj, np.integer):