Spaces:
Runtime error
Runtime error
from FlagEmbedding import FlagReranker | |
reranker = FlagReranker('BAAI/bge-reranker-large', | |
use_fp16=True) | |
def rerank(query: str, documents: [str], k: int) -> [str]: | |
scores = reranker.compute_score([(query, document) for document in documents]) | |
sorted_docs = sorted(enumerate(scores), key=lambda x: x[1], reverse=True) | |
return [sorted_docs[i] for i, _ in sorted_docs[:k]] | |