Skip to content

Commit

Permalink
remove scipy dep for sparse embed (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Sep 26, 2024
1 parent c7bfb53 commit cca4cdc
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions libs/milvus/langchain_milvus/utils/sparse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from abc import ABC, abstractmethod
from typing import Dict, List

from scipy.sparse import csr_array # type: ignore
from typing import Any, Dict, List


class BaseSparseEmbedding(ABC):
Expand Down Expand Up @@ -46,7 +44,7 @@ def embed_documents(self, texts: List[str]) -> List[Dict[int, float]]:
sparse_arrays = self.bm25_ef.encode_documents(texts)
return [self._sparse_to_dict(sparse_array) for sparse_array in sparse_arrays]

def _sparse_to_dict(self, sparse_array: csr_array) -> Dict[int, float]:
def _sparse_to_dict(self, sparse_array: Any) -> Dict[int, float]:
row_indices, col_indices = sparse_array.nonzero()
non_zero_values = sparse_array.data
result_dict = {}
Expand Down

0 comments on commit cca4cdc

Please sign in to comment.