| 167 | @staticmethod |
| 168 | @numba.njit(nogil=True, parallel=True, cache=True) |
| 169 | def numba_score_float(inverted_index_ids: numba.typed.Dict, |
| 170 | inverted_index_floats: numba.typed.Dict, |
| 171 | indexes_to_retrieve: np.ndarray, |
| 172 | query_values: np.ndarray, |
| 173 | threshold: float, |
| 174 | size_collection: int): |
| 175 | scores = np.zeros(size_collection, dtype=np.float32) # initialize array with size = size of collection |
| 176 | n = len(indexes_to_retrieve) |
| 177 | for _idx in range(n): |
| 178 | local_idx = indexes_to_retrieve[_idx] # which posting list to search |
| 179 | query_float = query_values[_idx] # what is the value of the query for this posting list |
| 180 | retrieved_indexes = inverted_index_ids[local_idx] # get indexes from posting list |
| 181 | retrieved_floats = inverted_index_floats[local_idx] # get values from posting list |
| 182 | for j in numba.prange(len(retrieved_indexes)): |
| 183 | scores[retrieved_indexes[j]] += query_float * retrieved_floats[j] |
| 184 | filtered_indexes = np.argwhere(scores > threshold)[:, 0] # ideally we should have a threshold to filter |
| 185 | # unused documents => this should be tuned, currently it is set to 0 |
| 186 | return filtered_indexes, -scores[filtered_indexes] |
| 187 | |
| 188 | def __init__(self, index_dir_path, retrieval_output_path, dim_voc, top_k): |
| 189 | self.sparse_index = IndexDictOfArray(index_dir_path, dim_voc=dim_voc) |