fastembed-gpu 0.7.2__tar.gz → 0.7.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/PKG-INFO +1 -1
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction/colbert.py +29 -33
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/pyproject.toml +1 -1
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/LICENSE +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/NOTICE +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/README.md +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/model_description.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/model_management.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/onnx_model.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/preprocessor_utils.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/types.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/common/utils.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/image_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/image_embedding_base.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/onnx_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/onnx_image_model.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/transform/functional.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/image/transform/operators.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction/jina_colbert.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction/late_interaction_embedding_base.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction/late_interaction_text_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction/token_embeddings.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/colpali.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/late_interaction_multimodal_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/late_interaction_multimodal_embedding_base.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/onnx_multimodal_model.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/parallel_processor.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/postprocess/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/postprocess/muvera.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/py.typed +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/custom_text_cross_encoder.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/onnx_text_cross_encoder.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/onnx_text_model.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/text_cross_encoder.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/text_cross_encoder_base.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/bm25.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/bm42.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/minicoil.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/sparse_embedding_base.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/sparse_text_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/splade_pp.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/utils/minicoil_encoder.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/utils/sparse_vectors_converter.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/utils/tokenizer.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/utils/vocab_resolver.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/__init__.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/clip_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/custom_text_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/multitask_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/onnx_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/onnx_text_model.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/pooled_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/pooled_normalized_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/text_embedding.py +0 -0
- {fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/text/text_embedding_base.py +0 -0
|
@@ -2,8 +2,9 @@ import string
|
|
|
2
2
|
from typing import Any, Iterable, Optional, Sequence, Type, Union
|
|
3
3
|
|
|
4
4
|
import numpy as np
|
|
5
|
-
from tokenizers import Encoding
|
|
5
|
+
from tokenizers import Encoding, Tokenizer
|
|
6
6
|
|
|
7
|
+
from fastembed.common.preprocessor_utils import load_tokenizer
|
|
7
8
|
from fastembed.common.types import NumpyArray
|
|
8
9
|
from fastembed.common import OnnxProvider
|
|
9
10
|
from fastembed.common.onnx_model import OnnxOutputContext
|
|
@@ -48,24 +49,24 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
48
49
|
if not is_doc:
|
|
49
50
|
for embedding in output.model_output:
|
|
50
51
|
yield embedding
|
|
52
|
+
else:
|
|
53
|
+
if output.input_ids is None or output.attention_mask is None:
|
|
54
|
+
raise ValueError(
|
|
55
|
+
"input_ids and attention_mask must be provided for document post-processing"
|
|
56
|
+
)
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for i, token_sequence in enumerate(output.input_ids):
|
|
58
|
-
for j, token_id in enumerate(token_sequence): # type: ignore
|
|
59
|
-
if token_id in self.skip_list or token_id == self.pad_token_id:
|
|
60
|
-
output.attention_mask[i, j] = 0
|
|
58
|
+
for i, token_sequence in enumerate(output.input_ids):
|
|
59
|
+
for j, token_id in enumerate(token_sequence): # type: ignore
|
|
60
|
+
if token_id in self.skip_list or token_id == self.pad_token_id:
|
|
61
|
+
output.attention_mask[i, j] = 0
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
output.model_output *= np.expand_dims(output.attention_mask, 2)
|
|
64
|
+
norm = np.linalg.norm(output.model_output, ord=2, axis=2, keepdims=True)
|
|
65
|
+
norm_clamped = np.maximum(norm, 1e-12)
|
|
66
|
+
output.model_output /= norm_clamped
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
for embedding, attention_mask in zip(output.model_output, output.attention_mask):
|
|
69
|
+
yield embedding[attention_mask == 1]
|
|
69
70
|
|
|
70
71
|
def _preprocess_onnx_input(
|
|
71
72
|
self, onnx_input: dict[str, NumpyArray], is_doc: bool = True, **kwargs: Any
|
|
@@ -87,23 +88,8 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
87
88
|
)
|
|
88
89
|
|
|
89
90
|
def _tokenize_query(self, query: str) -> list[Encoding]:
|
|
90
|
-
assert self.
|
|
91
|
-
encoded = self.
|
|
92
|
-
# colbert authors recommend to pad queries with [MASK] tokens for query augmentation to improve performance
|
|
93
|
-
if len(encoded[0].ids) < self.MIN_QUERY_LENGTH:
|
|
94
|
-
prev_padding = None
|
|
95
|
-
if self.tokenizer.padding:
|
|
96
|
-
prev_padding = self.tokenizer.padding
|
|
97
|
-
self.tokenizer.enable_padding(
|
|
98
|
-
pad_token=self.MASK_TOKEN,
|
|
99
|
-
pad_id=self.mask_token_id,
|
|
100
|
-
length=self.MIN_QUERY_LENGTH,
|
|
101
|
-
)
|
|
102
|
-
encoded = self.tokenizer.encode_batch([query])
|
|
103
|
-
if prev_padding is None:
|
|
104
|
-
self.tokenizer.no_padding()
|
|
105
|
-
else:
|
|
106
|
-
self.tokenizer.enable_padding(**prev_padding)
|
|
91
|
+
assert self.query_tokenizer is not None
|
|
92
|
+
encoded = self.query_tokenizer.encode_batch([query])
|
|
107
93
|
return encoded
|
|
108
94
|
|
|
109
95
|
def _tokenize_documents(self, documents: list[str]) -> list[Encoding]:
|
|
@@ -183,6 +169,8 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
183
169
|
self.pad_token_id: Optional[int] = None
|
|
184
170
|
self.skip_list: set[int] = set()
|
|
185
171
|
|
|
172
|
+
self.query_tokenizer: Optional[Tokenizer] = None
|
|
173
|
+
|
|
186
174
|
if not self.lazy_load:
|
|
187
175
|
self.load_onnx_model()
|
|
188
176
|
|
|
@@ -195,6 +183,8 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
195
183
|
cuda=self.cuda,
|
|
196
184
|
device_id=self.device_id,
|
|
197
185
|
)
|
|
186
|
+
self.query_tokenizer, _ = load_tokenizer(model_dir=self._model_dir)
|
|
187
|
+
|
|
198
188
|
assert self.tokenizer is not None
|
|
199
189
|
self.mask_token_id = self.special_token_to_id[self.MASK_TOKEN]
|
|
200
190
|
self.pad_token_id = self.tokenizer.padding["pad_id"]
|
|
@@ -205,6 +195,12 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
205
195
|
current_max_length = self.tokenizer.truncation["max_length"]
|
|
206
196
|
# ensure not to overflow after adding document-marker
|
|
207
197
|
self.tokenizer.enable_truncation(max_length=current_max_length - 1)
|
|
198
|
+
self.query_tokenizer.enable_truncation(max_length=current_max_length - 1)
|
|
199
|
+
self.query_tokenizer.enable_padding(
|
|
200
|
+
pad_token=self.MASK_TOKEN,
|
|
201
|
+
pad_id=self.mask_token_id,
|
|
202
|
+
length=self.MIN_QUERY_LENGTH,
|
|
203
|
+
)
|
|
208
204
|
|
|
209
205
|
def embed(
|
|
210
206
|
self,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "fastembed-gpu"
|
|
3
|
-
version = "0.7.
|
|
3
|
+
version = "0.7.3"
|
|
4
4
|
description = "Fast, light, accurate library built for retrieval embedding generation"
|
|
5
5
|
authors = ["Qdrant Team <info@qdrant.tech>", "NirantK <nirant.bits@gmail.com>"]
|
|
6
6
|
license = "Apache License"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/__init__.py
RENAMED
|
File without changes
|
{fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/late_interaction_multimodal/colpali.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/onnx_text_model.py
RENAMED
|
File without changes
|
{fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/rerank/cross_encoder/text_cross_encoder.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastembed_gpu-0.7.2 → fastembed_gpu-0.7.3}/fastembed/sparse/utils/sparse_vectors_converter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|