fastembed-gpu 0.7.0__tar.gz → 0.7.2__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.0 → fastembed_gpu-0.7.2}/PKG-INFO +20 -20
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/README.md +19 -19
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/image_embedding.py +34 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/image_embedding_base.py +11 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/onnx_embedding.py +4 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/onnx_image_model.py +4 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction/colbert.py +9 -3
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction/late_interaction_embedding_base.py +11 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction/late_interaction_text_embedding.py +34 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction/token_embeddings.py +1 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction_multimodal/colpali.py +7 -2
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction_multimodal/late_interaction_multimodal_embedding.py +34 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction_multimodal/late_interaction_multimodal_embedding_base.py +11 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction_multimodal/onnx_multimodal_model.py +8 -0
- fastembed_gpu-0.7.2/fastembed/postprocess/__init__.py +3 -0
- fastembed_gpu-0.7.2/fastembed/postprocess/muvera.py +364 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/rerank/cross_encoder/onnx_text_cross_encoder.py +4 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/rerank/cross_encoder/onnx_text_model.py +4 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/bm25.py +8 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/bm42.py +4 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/minicoil.py +8 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/sparse_text_embedding.py +1 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/splade_pp.py +4 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/custom_text_embedding.py +5 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/onnx_embedding.py +4 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/onnx_text_model.py +4 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/text_embedding.py +41 -7
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/text_embedding_base.py +11 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/pyproject.toml +1 -1
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/LICENSE +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/NOTICE +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/model_description.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/model_management.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/onnx_model.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/preprocessor_utils.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/types.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/common/utils.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/embedding.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/transform/functional.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/image/transform/operators.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction/jina_colbert.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction_multimodal/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/parallel_processor.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/py.typed +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/rerank/cross_encoder/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/rerank/cross_encoder/custom_text_cross_encoder.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/rerank/cross_encoder/text_cross_encoder.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/rerank/cross_encoder/text_cross_encoder_base.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/sparse_embedding_base.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/utils/minicoil_encoder.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/utils/sparse_vectors_converter.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/utils/tokenizer.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/sparse/utils/vocab_resolver.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/__init__.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/clip_embedding.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/multitask_embedding.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/pooled_embedding.py +0 -0
- {fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/text/pooled_normalized_embedding.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: fastembed-gpu
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: Fast, light, accurate library built for retrieval embedding generation
|
|
5
5
|
License: Apache License
|
|
6
6
|
Keywords: vector,embedding,neural,search,qdrant,sentence-transformers
|
|
@@ -281,37 +281,37 @@ pip install qdrant-client[fastembed-gpu]
|
|
|
281
281
|
You might have to use quotes ```pip install 'qdrant-client[fastembed]'``` on zsh.
|
|
282
282
|
|
|
283
283
|
```python
|
|
284
|
-
from qdrant_client import QdrantClient
|
|
284
|
+
from qdrant_client import QdrantClient, models
|
|
285
285
|
|
|
286
286
|
# Initialize the client
|
|
287
287
|
client = QdrantClient("localhost", port=6333) # For production
|
|
288
|
-
# client = QdrantClient(":memory:") # For
|
|
288
|
+
# client = QdrantClient(":memory:") # For experimentation
|
|
289
289
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
{"source": "
|
|
294
|
-
{"source": "Llama-index-docs"},
|
|
290
|
+
model_name = "sentence-transformers/all-MiniLM-L6-v2"
|
|
291
|
+
payload = [
|
|
292
|
+
{"document": "Qdrant has Langchain integrations", "source": "Langchain-docs", },
|
|
293
|
+
{"document": "Qdrant also has Llama Index integrations", "source": "LlamaIndex-docs"},
|
|
295
294
|
]
|
|
295
|
+
docs = [models.Document(text=data["document"], model=model_name) for data in payload]
|
|
296
296
|
ids = [42, 2]
|
|
297
297
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
client.create_collection(
|
|
299
|
+
"demo_collection",
|
|
300
|
+
vectors_config=models.VectorParams(
|
|
301
|
+
size=client.get_embedding_size(model_name), distance=models.Distance.COSINE)
|
|
302
|
+
)
|
|
301
303
|
|
|
302
|
-
|
|
303
|
-
# This internally calls embed() of the configured embedding model
|
|
304
|
-
client.add(
|
|
304
|
+
client.upload_collection(
|
|
305
305
|
collection_name="demo_collection",
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
306
|
+
vectors=docs,
|
|
307
|
+
ids=ids,
|
|
308
|
+
payload=payload,
|
|
309
309
|
)
|
|
310
310
|
|
|
311
|
-
search_result = client.
|
|
311
|
+
search_result = client.query_points(
|
|
312
312
|
collection_name="demo_collection",
|
|
313
|
-
|
|
314
|
-
)
|
|
313
|
+
query=models.Document(text="This is a query document", model=model_name)
|
|
314
|
+
).points
|
|
315
315
|
print(search_result)
|
|
316
316
|
```
|
|
317
317
|
|
|
@@ -246,36 +246,36 @@ pip install qdrant-client[fastembed-gpu]
|
|
|
246
246
|
You might have to use quotes ```pip install 'qdrant-client[fastembed]'``` on zsh.
|
|
247
247
|
|
|
248
248
|
```python
|
|
249
|
-
from qdrant_client import QdrantClient
|
|
249
|
+
from qdrant_client import QdrantClient, models
|
|
250
250
|
|
|
251
251
|
# Initialize the client
|
|
252
252
|
client = QdrantClient("localhost", port=6333) # For production
|
|
253
|
-
# client = QdrantClient(":memory:") # For
|
|
253
|
+
# client = QdrantClient(":memory:") # For experimentation
|
|
254
254
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
{"source": "
|
|
259
|
-
{"source": "Llama-index-docs"},
|
|
255
|
+
model_name = "sentence-transformers/all-MiniLM-L6-v2"
|
|
256
|
+
payload = [
|
|
257
|
+
{"document": "Qdrant has Langchain integrations", "source": "Langchain-docs", },
|
|
258
|
+
{"document": "Qdrant also has Llama Index integrations", "source": "LlamaIndex-docs"},
|
|
260
259
|
]
|
|
260
|
+
docs = [models.Document(text=data["document"], model=model_name) for data in payload]
|
|
261
261
|
ids = [42, 2]
|
|
262
262
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
263
|
+
client.create_collection(
|
|
264
|
+
"demo_collection",
|
|
265
|
+
vectors_config=models.VectorParams(
|
|
266
|
+
size=client.get_embedding_size(model_name), distance=models.Distance.COSINE)
|
|
267
|
+
)
|
|
266
268
|
|
|
267
|
-
|
|
268
|
-
# This internally calls embed() of the configured embedding model
|
|
269
|
-
client.add(
|
|
269
|
+
client.upload_collection(
|
|
270
270
|
collection_name="demo_collection",
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
vectors=docs,
|
|
272
|
+
ids=ids,
|
|
273
|
+
payload=payload,
|
|
274
274
|
)
|
|
275
275
|
|
|
276
|
-
search_result = client.
|
|
276
|
+
search_result = client.query_points(
|
|
277
277
|
collection_name="demo_collection",
|
|
278
|
-
|
|
279
|
-
)
|
|
278
|
+
query=models.Document(text="This is a query document", model=model_name)
|
|
279
|
+
).points
|
|
280
280
|
print(search_result)
|
|
281
281
|
```
|
|
@@ -77,6 +77,40 @@ class ImageEmbedding(ImageEmbeddingBase):
|
|
|
77
77
|
"Please check the supported models using `ImageEmbedding.list_supported_models()`"
|
|
78
78
|
)
|
|
79
79
|
|
|
80
|
+
@property
|
|
81
|
+
def embedding_size(self) -> int:
|
|
82
|
+
"""Get the embedding size of the current model"""
|
|
83
|
+
if self._embedding_size is None:
|
|
84
|
+
self._embedding_size = self.get_embedding_size(self.model_name)
|
|
85
|
+
return self._embedding_size
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def get_embedding_size(cls, model_name: str) -> int:
|
|
89
|
+
"""Get the embedding size of the passed model
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
model_name (str): The name of the model to get embedding size for.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
int: The size of the embedding.
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
ValueError: If the model name is not found in the supported models.
|
|
99
|
+
"""
|
|
100
|
+
descriptions = cls._list_supported_models()
|
|
101
|
+
embedding_size: Optional[int] = None
|
|
102
|
+
for description in descriptions:
|
|
103
|
+
if description.model.lower() == model_name.lower():
|
|
104
|
+
embedding_size = description.dim
|
|
105
|
+
break
|
|
106
|
+
if embedding_size is None:
|
|
107
|
+
model_names = [description.model for description in descriptions]
|
|
108
|
+
raise ValueError(
|
|
109
|
+
f"Embedding size for model {model_name} was None. "
|
|
110
|
+
f"Available model names: {model_names}"
|
|
111
|
+
)
|
|
112
|
+
return embedding_size
|
|
113
|
+
|
|
80
114
|
def embed(
|
|
81
115
|
self,
|
|
82
116
|
images: Union[ImageInput, Iterable[ImageInput]],
|
|
@@ -18,6 +18,7 @@ class ImageEmbeddingBase(ModelManagement[DenseModelDescription]):
|
|
|
18
18
|
self.cache_dir = cache_dir
|
|
19
19
|
self.threads = threads
|
|
20
20
|
self._local_files_only = kwargs.pop("local_files_only", False)
|
|
21
|
+
self._embedding_size: Optional[int] = None
|
|
21
22
|
|
|
22
23
|
def embed(
|
|
23
24
|
self,
|
|
@@ -42,3 +43,13 @@ class ImageEmbeddingBase(ModelManagement[DenseModelDescription]):
|
|
|
42
43
|
Iterable[NdArray]: The embeddings.
|
|
43
44
|
"""
|
|
44
45
|
raise NotImplementedError()
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def get_embedding_size(cls, model_name: str) -> int:
|
|
49
|
+
"""Returns embedding size of the chosen model."""
|
|
50
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def embedding_size(self) -> int:
|
|
54
|
+
"""Returns embedding size for the current model"""
|
|
55
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
@@ -112,11 +112,12 @@ class OnnxImageEmbedding(ImageEmbeddingBase, OnnxImageModel[NumpyArray]):
|
|
|
112
112
|
|
|
113
113
|
self.model_description = self._get_model_description(model_name)
|
|
114
114
|
self.cache_dir = str(define_cache_dir(cache_dir))
|
|
115
|
+
self._specific_model_path = specific_model_path
|
|
115
116
|
self._model_dir = self.download_model(
|
|
116
117
|
self.model_description,
|
|
117
118
|
self.cache_dir,
|
|
118
119
|
local_files_only=self._local_files_only,
|
|
119
|
-
specific_model_path=
|
|
120
|
+
specific_model_path=self._specific_model_path,
|
|
120
121
|
)
|
|
121
122
|
|
|
122
123
|
if not self.lazy_load:
|
|
@@ -177,6 +178,8 @@ class OnnxImageEmbedding(ImageEmbeddingBase, OnnxImageModel[NumpyArray]):
|
|
|
177
178
|
providers=self.providers,
|
|
178
179
|
cuda=self.cuda,
|
|
179
180
|
device_ids=self.device_ids,
|
|
181
|
+
local_files_only=self._local_files_only,
|
|
182
|
+
specific_model_path=self._specific_model_path,
|
|
180
183
|
**kwargs,
|
|
181
184
|
)
|
|
182
185
|
|
|
@@ -97,6 +97,8 @@ class OnnxImageModel(OnnxModel[T]):
|
|
|
97
97
|
providers: Optional[Sequence[OnnxProvider]] = None,
|
|
98
98
|
cuda: bool = False,
|
|
99
99
|
device_ids: Optional[list[int]] = None,
|
|
100
|
+
local_files_only: bool = False,
|
|
101
|
+
specific_model_path: Optional[str] = None,
|
|
100
102
|
**kwargs: Any,
|
|
101
103
|
) -> Iterable[T]:
|
|
102
104
|
is_small = False
|
|
@@ -123,6 +125,8 @@ class OnnxImageModel(OnnxModel[T]):
|
|
|
123
125
|
"model_name": model_name,
|
|
124
126
|
"cache_dir": cache_dir,
|
|
125
127
|
"providers": providers,
|
|
128
|
+
"local_files_only": local_files_only,
|
|
129
|
+
"specific_model_path": specific_model_path,
|
|
126
130
|
**kwargs,
|
|
127
131
|
}
|
|
128
132
|
|
|
@@ -46,7 +46,8 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
46
46
|
self, output: OnnxOutputContext, is_doc: bool = True, **kwargs: Any
|
|
47
47
|
) -> Iterable[NumpyArray]:
|
|
48
48
|
if not is_doc:
|
|
49
|
-
|
|
49
|
+
for embedding in output.model_output:
|
|
50
|
+
yield embedding
|
|
50
51
|
|
|
51
52
|
if output.input_ids is None or output.attention_mask is None:
|
|
52
53
|
raise ValueError(
|
|
@@ -62,7 +63,9 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
62
63
|
norm = np.linalg.norm(output.model_output, ord=2, axis=2, keepdims=True)
|
|
63
64
|
norm_clamped = np.maximum(norm, 1e-12)
|
|
64
65
|
output.model_output /= norm_clamped
|
|
65
|
-
|
|
66
|
+
|
|
67
|
+
for embedding, attention_mask in zip(output.model_output, output.attention_mask):
|
|
68
|
+
yield embedding[attention_mask == 1]
|
|
66
69
|
|
|
67
70
|
def _preprocess_onnx_input(
|
|
68
71
|
self, onnx_input: dict[str, NumpyArray], is_doc: bool = True, **kwargs: Any
|
|
@@ -169,11 +172,12 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
169
172
|
self.model_description = self._get_model_description(model_name)
|
|
170
173
|
self.cache_dir = str(define_cache_dir(cache_dir))
|
|
171
174
|
|
|
175
|
+
self._specific_model_path = specific_model_path
|
|
172
176
|
self._model_dir = self.download_model(
|
|
173
177
|
self.model_description,
|
|
174
178
|
self.cache_dir,
|
|
175
179
|
local_files_only=self._local_files_only,
|
|
176
|
-
specific_model_path=
|
|
180
|
+
specific_model_path=self._specific_model_path,
|
|
177
181
|
)
|
|
178
182
|
self.mask_token_id: Optional[int] = None
|
|
179
183
|
self.pad_token_id: Optional[int] = None
|
|
@@ -233,6 +237,8 @@ class Colbert(LateInteractionTextEmbeddingBase, OnnxTextModel[NumpyArray]):
|
|
|
233
237
|
providers=self.providers,
|
|
234
238
|
cuda=self.cuda,
|
|
235
239
|
device_ids=self.device_ids,
|
|
240
|
+
local_files_only=self._local_files_only,
|
|
241
|
+
specific_model_path=self._specific_model_path,
|
|
236
242
|
**kwargs,
|
|
237
243
|
)
|
|
238
244
|
|
|
@@ -17,6 +17,7 @@ class LateInteractionTextEmbeddingBase(ModelManagement[DenseModelDescription]):
|
|
|
17
17
|
self.cache_dir = cache_dir
|
|
18
18
|
self.threads = threads
|
|
19
19
|
self._local_files_only = kwargs.pop("local_files_only", False)
|
|
20
|
+
self._embedding_size: Optional[int] = None
|
|
20
21
|
|
|
21
22
|
def embed(
|
|
22
23
|
self,
|
|
@@ -58,3 +59,13 @@ class LateInteractionTextEmbeddingBase(ModelManagement[DenseModelDescription]):
|
|
|
58
59
|
yield from self.embed([query], **kwargs)
|
|
59
60
|
else:
|
|
60
61
|
yield from self.embed(query, **kwargs)
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def get_embedding_size(cls, model_name: str) -> int:
|
|
65
|
+
"""Returns embedding size of the chosen model."""
|
|
66
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def embedding_size(self) -> int:
|
|
70
|
+
"""Returns embedding size for the current model"""
|
|
71
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
@@ -80,6 +80,40 @@ class LateInteractionTextEmbedding(LateInteractionTextEmbeddingBase):
|
|
|
80
80
|
"Please check the supported models using `LateInteractionTextEmbedding.list_supported_models()`"
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
+
@property
|
|
84
|
+
def embedding_size(self) -> int:
|
|
85
|
+
"""Get the embedding size of the current model"""
|
|
86
|
+
if self._embedding_size is None:
|
|
87
|
+
self._embedding_size = self.get_embedding_size(self.model_name)
|
|
88
|
+
return self._embedding_size
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def get_embedding_size(cls, model_name: str) -> int:
|
|
92
|
+
"""Get the embedding size of the passed model
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
model_name (str): The name of the model to get embedding size for.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
int: The size of the embedding.
|
|
99
|
+
|
|
100
|
+
Raises:
|
|
101
|
+
ValueError: If the model name is not found in the supported models.
|
|
102
|
+
"""
|
|
103
|
+
descriptions = cls._list_supported_models()
|
|
104
|
+
embedding_size: Optional[int] = None
|
|
105
|
+
for description in descriptions:
|
|
106
|
+
if description.model.lower() == model_name.lower():
|
|
107
|
+
embedding_size = description.dim
|
|
108
|
+
break
|
|
109
|
+
if embedding_size is None:
|
|
110
|
+
model_names = [description.model for description in descriptions]
|
|
111
|
+
raise ValueError(
|
|
112
|
+
f"Embedding size for model {model_name} was None. "
|
|
113
|
+
f"Available model names: {model_names}"
|
|
114
|
+
)
|
|
115
|
+
return embedding_size
|
|
116
|
+
|
|
83
117
|
def embed(
|
|
84
118
|
self,
|
|
85
119
|
documents: Union[str, Iterable[str]],
|
|
@@ -9,7 +9,7 @@ from fastembed.late_interaction.late_interaction_embedding_base import (
|
|
|
9
9
|
)
|
|
10
10
|
from fastembed.text.onnx_embedding import OnnxTextEmbedding
|
|
11
11
|
from fastembed.text.onnx_text_model import TextEmbeddingWorker
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
|
|
14
14
|
supported_token_embeddings_models = [
|
|
15
15
|
DenseModelDescription(
|
{fastembed_gpu-0.7.0 → fastembed_gpu-0.7.2}/fastembed/late_interaction_multimodal/colpali.py
RENAMED
|
@@ -95,11 +95,12 @@ class ColPali(LateInteractionMultimodalEmbeddingBase, OnnxMultimodalModel[NumpyA
|
|
|
95
95
|
self.model_description = self._get_model_description(model_name)
|
|
96
96
|
self.cache_dir = str(define_cache_dir(cache_dir))
|
|
97
97
|
|
|
98
|
+
self._specific_model_path = specific_model_path
|
|
98
99
|
self._model_dir = self.download_model(
|
|
99
100
|
self.model_description,
|
|
100
101
|
self.cache_dir,
|
|
101
102
|
local_files_only=self._local_files_only,
|
|
102
|
-
specific_model_path=
|
|
103
|
+
specific_model_path=self._specific_model_path,
|
|
103
104
|
)
|
|
104
105
|
self.mask_token_id = None
|
|
105
106
|
self.pad_token_id = None
|
|
@@ -174,7 +175,7 @@ class ColPali(LateInteractionMultimodalEmbeddingBase, OnnxMultimodalModel[NumpyA
|
|
|
174
175
|
) -> dict[str, NumpyArray]:
|
|
175
176
|
onnx_input["input_ids"] = np.array(
|
|
176
177
|
[
|
|
177
|
-
self.QUERY_MARKER_TOKEN_ID + input_ids[2:].tolist()
|
|
178
|
+
self.QUERY_MARKER_TOKEN_ID + input_ids[2:].tolist() # type: ignore[index]
|
|
178
179
|
for input_ids in onnx_input["input_ids"]
|
|
179
180
|
]
|
|
180
181
|
)
|
|
@@ -235,6 +236,8 @@ class ColPali(LateInteractionMultimodalEmbeddingBase, OnnxMultimodalModel[NumpyA
|
|
|
235
236
|
providers=self.providers,
|
|
236
237
|
cuda=self.cuda,
|
|
237
238
|
device_ids=self.device_ids,
|
|
239
|
+
local_files_only=self._local_files_only,
|
|
240
|
+
specific_model_path=self._specific_model_path,
|
|
238
241
|
**kwargs,
|
|
239
242
|
)
|
|
240
243
|
|
|
@@ -268,6 +271,8 @@ class ColPali(LateInteractionMultimodalEmbeddingBase, OnnxMultimodalModel[NumpyA
|
|
|
268
271
|
providers=self.providers,
|
|
269
272
|
cuda=self.cuda,
|
|
270
273
|
device_ids=self.device_ids,
|
|
274
|
+
local_files_only=self._local_files_only,
|
|
275
|
+
specific_model_path=self._specific_model_path,
|
|
271
276
|
**kwargs,
|
|
272
277
|
)
|
|
273
278
|
|
|
@@ -83,6 +83,40 @@ class LateInteractionMultimodalEmbedding(LateInteractionMultimodalEmbeddingBase)
|
|
|
83
83
|
"Please check the supported models using `LateInteractionMultimodalEmbedding.list_supported_models()`"
|
|
84
84
|
)
|
|
85
85
|
|
|
86
|
+
@property
|
|
87
|
+
def embedding_size(self) -> int:
|
|
88
|
+
"""Get the embedding size of the current model"""
|
|
89
|
+
if self._embedding_size is None:
|
|
90
|
+
self._embedding_size = self.get_embedding_size(self.model_name)
|
|
91
|
+
return self._embedding_size
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def get_embedding_size(cls, model_name: str) -> int:
|
|
95
|
+
"""Get the embedding size of the passed model
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
model_name (str): The name of the model to get embedding size for.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
int: The size of the embedding.
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
ValueError: If the model name is not found in the supported models.
|
|
105
|
+
"""
|
|
106
|
+
descriptions = cls._list_supported_models()
|
|
107
|
+
embedding_size: Optional[int] = None
|
|
108
|
+
for description in descriptions:
|
|
109
|
+
if description.model.lower() == model_name.lower():
|
|
110
|
+
embedding_size = description.dim
|
|
111
|
+
break
|
|
112
|
+
if embedding_size is None:
|
|
113
|
+
model_names = [description.model for description in descriptions]
|
|
114
|
+
raise ValueError(
|
|
115
|
+
f"Embedding size for model {model_name} was None. "
|
|
116
|
+
f"Available model names: {model_names}"
|
|
117
|
+
)
|
|
118
|
+
return embedding_size
|
|
119
|
+
|
|
86
120
|
def embed_text(
|
|
87
121
|
self,
|
|
88
122
|
documents: Union[str, Iterable[str]],
|
|
@@ -19,6 +19,7 @@ class LateInteractionMultimodalEmbeddingBase(ModelManagement[DenseModelDescripti
|
|
|
19
19
|
self.cache_dir = cache_dir
|
|
20
20
|
self.threads = threads
|
|
21
21
|
self._local_files_only = kwargs.pop("local_files_only", False)
|
|
22
|
+
self._embedding_size: Optional[int] = None
|
|
22
23
|
|
|
23
24
|
def embed_text(
|
|
24
25
|
self,
|
|
@@ -65,3 +66,13 @@ class LateInteractionMultimodalEmbeddingBase(ModelManagement[DenseModelDescripti
|
|
|
65
66
|
List of embeddings, one per image
|
|
66
67
|
"""
|
|
67
68
|
raise NotImplementedError()
|
|
69
|
+
|
|
70
|
+
@classmethod
|
|
71
|
+
def get_embedding_size(cls, model_name: str) -> int:
|
|
72
|
+
"""Returns embedding size of the chosen model."""
|
|
73
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def embedding_size(self) -> int:
|
|
77
|
+
"""Returns embedding size for the current model"""
|
|
78
|
+
raise NotImplementedError("Subclasses must implement this method")
|
|
@@ -120,6 +120,8 @@ class OnnxMultimodalModel(OnnxModel[T]):
|
|
|
120
120
|
providers: Optional[Sequence[OnnxProvider]] = None,
|
|
121
121
|
cuda: bool = False,
|
|
122
122
|
device_ids: Optional[list[int]] = None,
|
|
123
|
+
local_files_only: bool = False,
|
|
124
|
+
specific_model_path: Optional[str] = None,
|
|
123
125
|
**kwargs: Any,
|
|
124
126
|
) -> Iterable[T]:
|
|
125
127
|
is_small = False
|
|
@@ -146,6 +148,8 @@ class OnnxMultimodalModel(OnnxModel[T]):
|
|
|
146
148
|
"model_name": model_name,
|
|
147
149
|
"cache_dir": cache_dir,
|
|
148
150
|
"providers": providers,
|
|
151
|
+
"local_files_only": local_files_only,
|
|
152
|
+
"specific_model_path": specific_model_path,
|
|
149
153
|
**kwargs,
|
|
150
154
|
}
|
|
151
155
|
|
|
@@ -183,6 +187,8 @@ class OnnxMultimodalModel(OnnxModel[T]):
|
|
|
183
187
|
providers: Optional[Sequence[OnnxProvider]] = None,
|
|
184
188
|
cuda: bool = False,
|
|
185
189
|
device_ids: Optional[list[int]] = None,
|
|
190
|
+
local_files_only: bool = False,
|
|
191
|
+
specific_model_path: Optional[str] = None,
|
|
186
192
|
**kwargs: Any,
|
|
187
193
|
) -> Iterable[T]:
|
|
188
194
|
is_small = False
|
|
@@ -209,6 +215,8 @@ class OnnxMultimodalModel(OnnxModel[T]):
|
|
|
209
215
|
"model_name": model_name,
|
|
210
216
|
"cache_dir": cache_dir,
|
|
211
217
|
"providers": providers,
|
|
218
|
+
"local_files_only": local_files_only,
|
|
219
|
+
"specific_model_path": specific_model_path,
|
|
212
220
|
**kwargs,
|
|
213
221
|
}
|
|
214
222
|
|