---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], line 2
1 # Output is a list of indices
----> 2 bm25_retrieve("What are the recent news about GDP?")
Cell In[8], line 27, in bm25_retrieve(query, top_k)
23 print(tokenized_query)
25 # Use the 'BM25_RETRIEVER' to retrieve documents and their scores based on the tokenized query
26 # Retrieve the top 'k' documents
---> 27 results, scores = BM25_RETRIEVER.retrieve(tokenized_query, 3)
29 # Extract the first element from 'results' to get the list of retrieved documents
30 results = None
File /opt/conda/lib/python3.12/site-packages/bm25s/__init__.py:866, in BM25.retrieve(self, query_tokens, corpus, k, sorted, return_as, show_progress, leave_progress, n_threads, chunksize, backend_selection, weight_mask)
864 else:
865 index_flat = indices.flatten().tolist()
--> 866 results = [corpus[i] for i in index_flat]
867 retrieved_docs = np.array(results).reshape(indices.shape)
869 if return_as == "tuple":
TypeError: 'int' object is not subscriptable
BTW, is it possible to reload the ‘original’ template? I want to get rid of all my previous codes and re-do the exercise from scratch. Thanks.
I figured it out. All good now.
Hi, I have the same issue but I still do not understand what is the problem in these two simple lines of code.
Any useful hint?
Thank
Hi all, this is happening because the second expected argument for BM25_RETRIEVER.retrieve is not the k you need to pass. So you actually need to pass k = top_k instead of only top_k.
I hope that helps. Let me know if you still encounter issues.
Cheers,
Lucas
2 Likes