Skip to content

Commit

Permalink
fix(bm25s): search implementation (#1566)
Browse files Browse the repository at this point in the history
fix: bm25s implementation
  • Loading branch information
dbuades authored Dec 7, 2024
1 parent 5e7e033 commit ac44e58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions mteb/evaluation/evaluators/RetrievalEvaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ def __call__(
if self.is_cross_encoder:
return self.retriever.search_cross_encoder(corpus, queries, self.top_k)
elif (
hasattr(self.retriever.model, "mteb_model_meta")
and self.retriever.model.mteb_model_meta.name == "bm25s"
hasattr(self.retriever.model.model, "mteb_model_meta")
and self.retriever.model.model.mteb_model_meta.name == "bm25s"
):
return self.retriever.model.search(
return self.retriever.model.model.search(
corpus,
queries,
self.top_k,
Expand Down
12 changes: 11 additions & 1 deletion mteb/models/bm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ def search(
) -> dict[str, dict[str, float]]:
logger.info("Encoding Corpus...")
corpus_ids = list(corpus.keys())
corpus_with_ids = [{"doc_id": cid, **corpus[cid]} for cid in corpus_ids]
corpus_with_ids = [
{
"doc_id": cid,
**(
{"text": corpus[cid]}
if isinstance(corpus[cid], str)
else corpus[cid]
),
}
for cid in corpus_ids
]

corpus_texts = [
"\n".join([doc.get("title", ""), doc["text"]])
Expand Down

0 comments on commit ac44e58

Please sign in to comment.