Kushalguptaiitb commited on
Commit
2239a6e
·
verified ·
1 Parent(s): 5f1b991

Delete reranker.py

Browse files
Files changed (1) hide show
  1. reranker.py +0 -32
reranker.py DELETED
@@ -1,32 +0,0 @@
1
- from rank_bm25 import BM25Okapi
2
- from typing import List, Dict
3
-
4
- class Reranker:
5
- def __init__(self):
6
- self.tokenized_docs = []
7
- self.bm25 = None
8
-
9
- def prepare(self, documents: List[Dict]):
10
- """Prepare the reranker with documents."""
11
- self.tokenized_docs = [doc['content'].split() for doc in documents]
12
- self.bm25 = BM25Okapi(self.tokenized_docs)
13
-
14
- def rerank(self, query: str, initial_results: List[Dict], top_k: int) -> List[Dict]:
15
- """Rerank initial search results using BM25."""
16
- tokenized_query = query.split()
17
- scores = self.bm25.get_scores(tokenized_query)
18
-
19
- # Combine initial scores with BM25 scores
20
- reranked = []
21
- for idx, result in enumerate(initial_results):
22
- doc_idx = int(result['id'].split('_')[1])
23
- combined_score = result['score'] + scores[doc_idx]
24
- reranked.append({
25
- 'id': result['id'],
26
- 'content': result['content'],
27
- 'score': combined_score
28
- })
29
-
30
- # Sort by combined score
31
- reranked.sort(key=lambda x: x['score'], reverse=True)
32
- return reranked[:top_k]