I have a somewhat silly use case. I'm running retriever.retrieve, with a queries dict with only 1 entry. However, this causes an IndexError with pytorch due to how pytorch indexes 2D arrays where the first dim is of size 1:
File "<dir>/script.py", line 83, in <module>
results = retriever.retrieve(para_d, one_query_d)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<env>/beir/retrieval/evaluation.py", line 20, in retrieve
return self.retriever.search(corpus, queries, self.top_k, self.score_function, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<env>/beir/retrieval/search/dense/exact_search.py", line 73, in search
scores_dim = cos_scores[1]
~~~~~~~~~~^^^
IndexError: index 1 is out of bounds for dimension 0 with size 1
I have a somewhat silly use case. I'm running
retriever.retrieve
, with aqueries
dict with only 1 entry. However, this causes an IndexError with pytorch due to how pytorch indexes 2D arrays where the first dim is of size 1:I was able to fix this by changing the below line: https://github.com/beir-cellar/beir/blob/f062f038c4bfd19a8ca942a9910b1e0d218759d4/beir/retrieval/search/dense/exact_search.py#L73
And swapping out
cos_scores[1]
withscores_dim
:This monkey patch works for me, but I'm just curious if there's a more appropriate way to retrieve given only 1 query. Thanks!