Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to use csr_matrix and np.float64 for sparse vectors #28

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions milvus_model/hybrid/bge_m3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from typing import Dict, List

from scipy.sparse import csr_array, vstack
from scipy.sparse import csr_matrix, vstack
import numpy as np

from milvus_model.base import BaseEmbeddingFunction
from milvus_model.utils import import_FlagEmbedding
Expand Down Expand Up @@ -78,9 +79,9 @@ def _encode(self, texts: List[str]) -> Dict:
results["sparse"] = []
for sparse_vec in output["lexical_weights"]:
indices = [int(k) for k in sparse_vec]
values = list(sparse_vec.values())
values = np.array(list(sparse_vec.values()), dtype=np.float64)
row_indices = [0] * len(indices)
csr = csr_array((values, (row_indices, indices)), shape=(1, sparse_dim))
csr = csr_matrix((values, (row_indices, indices)), shape=(1, sparse_dim))
results["sparse"].append(csr)
results["sparse"] = vstack(results["sparse"]).tocsr()
if self._encode_config["return_colbert_vecs"] is True:
Expand Down