Skip to content

Get "not enough values to unpack" error from BM25EmbeddingFunction with scipy v1.15.0 #76

Open
@yhmo

Description

@yhmo

Script to reproduce:

from langchain_milvus.utils.sparse import BM25SparseEmbedding
from typing import List

from milvus_model.sparse import BM25EmbeddingFunction


class MyBM25SparseEmbedding(BM25SparseEmbedding):
    def __init__(self, corpus: List[str] = None):
        if corpus is not None:
            super().__init__(corpus=corpus)

    def load(self, save_path: str):
        self.bm25_ef = BM25EmbeddingFunction()
        self.bm25_ef.load(save_path)

    def save(self, save_path: str):
        self.bm25_ef.save(save_path)


bm25_store_file = 'bm25.json'  # Name of the file to save the sparse embeddings

docs = ["hello hello world", "welcome to wonderful wonderful world"]

sparse_embedding_func = MyBM25SparseEmbedding(docs)
sparse_embedding_func.save(bm25_store_file)
print(sparse_embedding_func.bm25_ef.idf)
print("=====================================")
print(docs)
print("=====================================")
print(sparse_embedding_func.embed_documents(docs)) # Error here

With scipy version== 1.14.1, it works fine.
With scipy version==1.15.0, it throws this error:

Traceback (most recent call last):
  File "/Users/test.py", line 28, in <module>
    print(sparse_embedding_func.embed_documents(docs))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test_venv/lib/python3.12/site-packages/langchain_milvus/utils/sparse.py", line 45, in embed_documents
    return [self._sparse_to_dict(sparse_array) for sparse_array in sparse_arrays]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test_venv/lib/python3.12/site-packages/langchain_milvus/utils/sparse.py", line 48, in _sparse_to_dict
    row_indices, col_indices = sparse_array.nonzero()
    ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions