Full disclosure I don't have any experience using the BM25 ranking, however I do have quite a bit of experience with gensim's TF-IDF and LSI distributed models, along with gensim's similarity index.
The author does a really good job at keeping a readable codebase, so if you're ever having trouble with anything like this again, I recommend just jumping into the source code.
Looking at the source code: https://github.com/RaRe-Technologies/gensim/blob/develop/gensim/summarization/bm25.py
So I initialized a object with the documents you pasted above. BM25()
It looks like our good old friend Radim didn't include a function to calculate the for us, which no biggie, we can just plagarize line 65 for our cause: average_idf
average_idf = sum(map(lambda k: float(bm25.idf[k]), bm25.idf.keys())) / len(bm25.idf.keys())
Then, well if I understand the original intention of correctly, you should get each BM25 score with respect to your original query, simply by doing get_scores
scores = bm_25_object.get_scores(query_doc, average_idf)
Which returns all the scores for each document, and then, if I understand the BM25 ranking based on what I read on this wikipedia page: https://en.wikipedia.org/wiki/Okapi_BM25
You should be able to just pick the document with the highest score as follows:
best_result = docs[scores.index(max(scores))]
So the first document should be the most relevant to your query? I hope that's what you were expecting anyways, and I hope that this helped in some capacity. Good luck!
1 ) tokenize corpus or send tokinizing function to class
2 ) send only queries to "get_scores" function
read official example
from rank_bm25 import BM25Okapi
corpus = [
"Hello there good man!",
"It is quite windy in London",
"How is the weather today?"
]
tokenized_corpus = [doc.split(" ") for doc in corpus]
bm25 = BM25Okapi(tokenized_corpus)
query = "windy London"
tokenized_query = query.split(" ")
doc_scores = bm25.get_scores(tokenized_query)