MCPcopy Create free account
hub / github.com/BeastyZ/ConvSearch-R1 / retrieve

Method retrieve

index/dense/libs.py:203–227  ·  view source on GitHub ↗
(self, qid2emb)

Source from the content-addressed store, hash-verified

201
202
203 def retrieve(self, qid2emb):
204 res = defaultdict(dict)
205 for qid in tqdm(qid2emb):
206 query_emb = qid2emb[qid]
207 query_emb = query_emb.view(1, -1)
208 row, col = torch.nonzero(query_emb, as_tuple=True)
209 values = query_emb[tensor_to_list(row), tensor_to_list(col)]
210 threshold = 0
211 filtered_indexes, scores = self.numba_score_float(self.numba_index_doc_ids,
212 self.numba_index_doc_values,
213 col.cpu().numpy(),
214 values.cpu().numpy().astype(np.float32),
215 threshold=threshold,
216 size_collection=self.sparse_index.nb_docs())
217 # threshold set to 0 by default, could be better
218 filtered_indexes, scores = self.select_topk(filtered_indexes, scores, k=self.top_k)
219 for id_, sc in zip(filtered_indexes, scores):
220 res[str(qid)][str(self.doc_ids[id_])] = float(sc)
221
222
223 with open(os.path.join(self.retrieval_output_path, "run.json"), "w") as f:
224 json.dump(res, f)
225 print("Write the retrieval result to {} successfully.".format(self.retrieval_output_path))
226
227 return res
228
229
230PyTorch_over_1_6 = float((torch.__version__.split('.')[1])) >= 6 and float((torch.__version__.split('.')[0])) >= 1

Callers

nothing calls this directly

Calls 5

numba_score_floatMethod · 0.95
select_topkMethod · 0.95
tensor_to_listFunction · 0.90
nb_docsMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected