fastembed-gpu 0.2.7__tar.gz → 0.5.1__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.5.1/NOTICE +14 -0
- fastembed_gpu-0.5.1/PKG-INFO +262 -0
- fastembed_gpu-0.2.7/PKG-INFO → fastembed_gpu-0.5.1/README.md +121 -40
- fastembed_gpu-0.5.1/fastembed/__init__.py +20 -0
- fastembed_gpu-0.5.1/fastembed/common/__init__.py +3 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/common/model_management.py +104 -47
- fastembed_gpu-0.5.1/fastembed/common/onnx_model.py +132 -0
- fastembed_gpu-0.5.1/fastembed/common/preprocessor_utils.py +82 -0
- fastembed_gpu-0.5.1/fastembed/common/types.py +16 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/common/utils.py +25 -3
- fastembed_gpu-0.5.1/fastembed/image/__init__.py +3 -0
- fastembed_gpu-0.5.1/fastembed/image/image_embedding.py +97 -0
- fastembed_gpu-0.5.1/fastembed/image/image_embedding_base.py +44 -0
- fastembed_gpu-0.5.1/fastembed/image/onnx_embedding.py +211 -0
- fastembed_gpu-0.5.1/fastembed/image/onnx_image_model.py +131 -0
- fastembed_gpu-0.5.1/fastembed/image/transform/functional.py +150 -0
- fastembed_gpu-0.5.1/fastembed/image/transform/operators.py +268 -0
- fastembed_gpu-0.5.1/fastembed/late_interaction/__init__.py +5 -0
- fastembed_gpu-0.5.1/fastembed/late_interaction/colbert.py +256 -0
- fastembed_gpu-0.5.1/fastembed/late_interaction/jina_colbert.py +62 -0
- fastembed_gpu-0.5.1/fastembed/late_interaction/late_interaction_embedding_base.py +62 -0
- fastembed_gpu-0.5.1/fastembed/late_interaction/late_interaction_text_embedding.py +114 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/parallel_processor.py +54 -11
- fastembed_gpu-0.5.1/fastembed/rerank/cross_encoder/__init__.py +3 -0
- fastembed_gpu-0.5.1/fastembed/rerank/cross_encoder/onnx_text_cross_encoder.py +224 -0
- fastembed_gpu-0.5.1/fastembed/rerank/cross_encoder/onnx_text_model.py +150 -0
- fastembed_gpu-0.5.1/fastembed/rerank/cross_encoder/text_cross_encoder.py +120 -0
- fastembed_gpu-0.5.1/fastembed/rerank/cross_encoder/text_cross_encoder_base.py +58 -0
- fastembed_gpu-0.5.1/fastembed/sparse/bm25.py +347 -0
- fastembed_gpu-0.5.1/fastembed/sparse/bm42.py +340 -0
- fastembed_gpu-0.5.1/fastembed/sparse/sparse_embedding_base.py +83 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/sparse/sparse_text_embedding.py +43 -8
- fastembed_gpu-0.5.1/fastembed/sparse/splade_pp.py +180 -0
- fastembed_gpu-0.5.1/fastembed/sparse/utils/tokenizer.py +120 -0
- fastembed_gpu-0.5.1/fastembed/text/clip_embedding.py +54 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/text/e5_onnx_embedding.py +19 -9
- fastembed_gpu-0.5.1/fastembed/text/onnx_embedding.py +333 -0
- fastembed_gpu-0.5.1/fastembed/text/onnx_text_model.py +145 -0
- fastembed_gpu-0.5.1/fastembed/text/pooled_embedding.py +92 -0
- fastembed_gpu-0.5.1/fastembed/text/pooled_normalized_embedding.py +125 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/text/text_embedding.py +23 -9
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/text/text_embedding_base.py +3 -1
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/pyproject.toml +25 -13
- fastembed_gpu-0.2.7/README.md +0 -117
- fastembed_gpu-0.2.7/fastembed/__init__.py +0 -12
- fastembed_gpu-0.2.7/fastembed/common/__init__.py +0 -3
- fastembed_gpu-0.2.7/fastembed/common/models.py +0 -54
- fastembed_gpu-0.2.7/fastembed/common/onnx_model.py +0 -165
- fastembed_gpu-0.2.7/fastembed/image/__init__.py +0 -0
- fastembed_gpu-0.2.7/fastembed/sparse/sparse_embedding_base.py +0 -44
- fastembed_gpu-0.2.7/fastembed/sparse/splade_pp.py +0 -138
- fastembed_gpu-0.2.7/fastembed/text/jina_onnx_embedding.py +0 -67
- fastembed_gpu-0.2.7/fastembed/text/onnx_embedding.py +0 -298
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/LICENSE +0 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/embedding.py +0 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/sparse/__init__.py +0 -0
- {fastembed_gpu-0.2.7 → fastembed_gpu-0.5.1}/fastembed/text/__init__.py +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright 2024 Qdrant
|
|
2
|
+
|
|
3
|
+
This product includes software developed by Qdrant
|
|
4
|
+
|
|
5
|
+
This distribution includes the following Jina AI models, each with its respective license:
|
|
6
|
+
- jinaai/jina-colbert-v2
|
|
7
|
+
- License: cc-by-nc-4.0
|
|
8
|
+
- jinaai/jina-reranker-v2-base-multilingual
|
|
9
|
+
- License: cc-by-nc-4.0
|
|
10
|
+
|
|
11
|
+
These models are developed by Jina (https://jina.ai/) and are subject to Jina AI's licensing terms.
|
|
12
|
+
|
|
13
|
+
Additional Notes:
|
|
14
|
+
This project also includes third-party libraries with their respective licenses. Please refer to the documentation of each library for details regarding its usage and licensing terms.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: fastembed-gpu
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: Fast, light, accurate library built for retrieval embedding generation
|
|
5
|
+
License: Apache License
|
|
6
|
+
Keywords: vector,embedding,neural,search,qdrant,sentence-transformers
|
|
7
|
+
Author: Qdrant Team
|
|
8
|
+
Author-email: info@qdrant.tech
|
|
9
|
+
Requires-Python: >=3.9.0
|
|
10
|
+
Classifier: License :: Other/Proprietary License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Dist: huggingface-hub (>=0.20,<1.0)
|
|
18
|
+
Requires-Dist: loguru (>=0.7.2,<0.8.0)
|
|
19
|
+
Requires-Dist: mmh3 (>=4.1.0,<5.0.0)
|
|
20
|
+
Requires-Dist: numpy (>=1.21) ; python_version >= "3.10" and python_version < "3.12"
|
|
21
|
+
Requires-Dist: numpy (>=1.21,<2.1.0) ; python_version < "3.10"
|
|
22
|
+
Requires-Dist: numpy (>=1.26) ; python_version >= "3.12" and python_version < "3.13"
|
|
23
|
+
Requires-Dist: numpy (>=2.1.0) ; python_version >= "3.13"
|
|
24
|
+
Requires-Dist: onnxruntime-gpu (>1.20.0) ; python_version >= "3.13"
|
|
25
|
+
Requires-Dist: onnxruntime-gpu (>=1.17.0,!=1.20.0) ; python_version >= "3.10" and python_version < "3.13"
|
|
26
|
+
Requires-Dist: onnxruntime-gpu (>=1.17.0,<1.20.0) ; python_version < "3.10"
|
|
27
|
+
Requires-Dist: pillow (>=10.3.0,<11.0.0)
|
|
28
|
+
Requires-Dist: py-rust-stemmers (>=0.1.0,<0.2.0)
|
|
29
|
+
Requires-Dist: requests (>=2.31,<3.0)
|
|
30
|
+
Requires-Dist: tokenizers (>=0.15,<1.0)
|
|
31
|
+
Requires-Dist: tqdm (>=4.66,<5.0)
|
|
32
|
+
Project-URL: Homepage, https://github.com/qdrant/fastembed
|
|
33
|
+
Project-URL: Repository, https://github.com/qdrant/fastembed
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# ⚡️ What is FastEmbed?
|
|
37
|
+
|
|
38
|
+
FastEmbed is a lightweight, fast, Python library built for embedding generation. We [support popular text models](https://qdrant.github.io/fastembed/examples/Supported_Models/). Please [open a GitHub issue](https://github.com/qdrant/fastembed/issues/new) if you want us to add a new model.
|
|
39
|
+
|
|
40
|
+
The default text embedding (`TextEmbedding`) model is Flag Embedding, presented in the [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard. It supports "query" and "passage" prefixes for the input text. Here is an example for [Retrieval Embedding Generation](https://qdrant.github.io/fastembed/qdrant/Retrieval_with_FastEmbed/) and how to use [FastEmbed with Qdrant](https://qdrant.github.io/fastembed/qdrant/Usage_With_Qdrant/).
|
|
41
|
+
|
|
42
|
+
## 📈 Why FastEmbed?
|
|
43
|
+
|
|
44
|
+
1. Light: FastEmbed is a lightweight library with few external dependencies. We don't require a GPU and don't download GBs of PyTorch dependencies, and instead use the ONNX Runtime. This makes it a great candidate for serverless runtimes like AWS Lambda.
|
|
45
|
+
|
|
46
|
+
2. Fast: FastEmbed is designed for speed. We use the ONNX Runtime, which is faster than PyTorch. We also use data parallelism for encoding large datasets.
|
|
47
|
+
|
|
48
|
+
3. Accurate: FastEmbed is better than OpenAI Ada-002. We also [support](https://qdrant.github.io/fastembed/examples/Supported_Models/) an ever-expanding set of models, including a few multilingual models.
|
|
49
|
+
|
|
50
|
+
## 🚀 Installation
|
|
51
|
+
|
|
52
|
+
To install the FastEmbed library, pip works best. You can install it with or without GPU support:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install fastembed
|
|
56
|
+
|
|
57
|
+
# or with GPU support
|
|
58
|
+
|
|
59
|
+
pip install fastembed-gpu
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 📖 Quickstart
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from fastembed import TextEmbedding
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Example list of documents
|
|
69
|
+
documents: list[str] = [
|
|
70
|
+
"This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc.",
|
|
71
|
+
"fastembed is supported by and maintained by Qdrant.",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
# This will trigger the model download and initialization
|
|
75
|
+
embedding_model = TextEmbedding()
|
|
76
|
+
print("The model BAAI/bge-small-en-v1.5 is ready to use.")
|
|
77
|
+
|
|
78
|
+
embeddings_generator = embedding_model.embed(documents) # reminder this is a generator
|
|
79
|
+
embeddings_list = list(embedding_model.embed(documents))
|
|
80
|
+
# you can also convert the generator to a list, and that to a numpy array
|
|
81
|
+
len(embeddings_list[0]) # Vector of 384 dimensions
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Fastembed supports a variety of models for different tasks and modalities.
|
|
85
|
+
The list of all the available models can be found [here](https://qdrant.github.io/fastembed/examples/Supported_Models/)
|
|
86
|
+
### 🎒 Dense text embeddings
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from fastembed import TextEmbedding
|
|
90
|
+
|
|
91
|
+
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
|
92
|
+
embeddings = list(model.embed(documents))
|
|
93
|
+
|
|
94
|
+
# [
|
|
95
|
+
# array([-0.1115, 0.0097, 0.0052, 0.0195, ...], dtype=float32),
|
|
96
|
+
# array([-0.1019, 0.0635, -0.0332, 0.0522, ...], dtype=float32)
|
|
97
|
+
# ]
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### 🔱 Sparse text embeddings
|
|
104
|
+
|
|
105
|
+
* SPLADE++
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from fastembed import SparseTextEmbedding
|
|
109
|
+
|
|
110
|
+
model = SparseTextEmbedding(model_name="prithivida/Splade_PP_en_v1")
|
|
111
|
+
embeddings = list(model.embed(documents))
|
|
112
|
+
|
|
113
|
+
# [
|
|
114
|
+
# SparseEmbedding(indices=[ 17, 123, 919, ... ], values=[0.71, 0.22, 0.39, ...]),
|
|
115
|
+
# SparseEmbedding(indices=[ 38, 12, 91, ... ], values=[0.11, 0.22, 0.39, ...])
|
|
116
|
+
# ]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
<!--
|
|
120
|
+
* BM42 - ([link](ToDo))
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
from fastembed import SparseTextEmbedding
|
|
124
|
+
|
|
125
|
+
model = SparseTextEmbedding(model_name="Qdrant/bm42-all-minilm-l6-v2-attentions")
|
|
126
|
+
embeddings = list(model.embed(documents))
|
|
127
|
+
|
|
128
|
+
# [
|
|
129
|
+
# SparseEmbedding(indices=[ 17, 123, 919, ... ], values=[0.71, 0.22, 0.39, ...]),
|
|
130
|
+
# SparseEmbedding(indices=[ 38, 12, 91, ... ], values=[0.11, 0.22, 0.39, ...])
|
|
131
|
+
# ]
|
|
132
|
+
```
|
|
133
|
+
-->
|
|
134
|
+
|
|
135
|
+
### 🦥 Late interaction models (aka ColBERT)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from fastembed import LateInteractionTextEmbedding
|
|
140
|
+
|
|
141
|
+
model = LateInteractionTextEmbedding(model_name="colbert-ir/colbertv2.0")
|
|
142
|
+
embeddings = list(model.embed(documents))
|
|
143
|
+
|
|
144
|
+
# [
|
|
145
|
+
# array([
|
|
146
|
+
# [-0.1115, 0.0097, 0.0052, 0.0195, ...],
|
|
147
|
+
# [-0.1019, 0.0635, -0.0332, 0.0522, ...],
|
|
148
|
+
# ]),
|
|
149
|
+
# array([
|
|
150
|
+
# [-0.9019, 0.0335, -0.0032, 0.0991, ...],
|
|
151
|
+
# [-0.2115, 0.8097, 0.1052, 0.0195, ...],
|
|
152
|
+
# ]),
|
|
153
|
+
# ]
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 🖼️ Image embeddings
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from fastembed import ImageEmbedding
|
|
160
|
+
|
|
161
|
+
images = [
|
|
162
|
+
"./path/to/image1.jpg",
|
|
163
|
+
"./path/to/image2.jpg",
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
model = ImageEmbedding(model_name="Qdrant/clip-ViT-B-32-vision")
|
|
167
|
+
embeddings = list(model.embed(images))
|
|
168
|
+
|
|
169
|
+
# [
|
|
170
|
+
# array([-0.1115, 0.0097, 0.0052, 0.0195, ...], dtype=float32),
|
|
171
|
+
# array([-0.1019, 0.0635, -0.0332, 0.0522, ...], dtype=float32)
|
|
172
|
+
# ]
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 🔄 Rerankers
|
|
176
|
+
```python
|
|
177
|
+
from fastembed.rerank.cross_encoder import TextCrossEncoder
|
|
178
|
+
|
|
179
|
+
query = "Who is maintaining Qdrant?"
|
|
180
|
+
documents: list[str] = [
|
|
181
|
+
"This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc.",
|
|
182
|
+
"fastembed is supported by and maintained by Qdrant.",
|
|
183
|
+
]
|
|
184
|
+
encoder = TextCrossEncoder(model_name="Xenova/ms-marco-MiniLM-L-6-v2")
|
|
185
|
+
scores = list(encoder.rerank(query, documents))
|
|
186
|
+
|
|
187
|
+
# [-11.48061752319336, 5.472434997558594]
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## ⚡️ FastEmbed on a GPU
|
|
191
|
+
|
|
192
|
+
FastEmbed supports running on GPU devices.
|
|
193
|
+
It requires installation of the `fastembed-gpu` package.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
pip install fastembed-gpu
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Check our [example](https://qdrant.github.io/fastembed/examples/FastEmbed_GPU/) for detailed instructions, CUDA 12.x support and troubleshooting of the common issues.
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from fastembed import TextEmbedding
|
|
203
|
+
|
|
204
|
+
embedding_model = TextEmbedding(
|
|
205
|
+
model_name="BAAI/bge-small-en-v1.5",
|
|
206
|
+
providers=["CUDAExecutionProvider"]
|
|
207
|
+
)
|
|
208
|
+
print("The model BAAI/bge-small-en-v1.5 is ready to use on a GPU.")
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Usage with Qdrant
|
|
213
|
+
|
|
214
|
+
Installation with Qdrant Client in Python:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
pip install qdrant-client[fastembed]
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
or
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pip install qdrant-client[fastembed-gpu]
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
You might have to use quotes ```pip install 'qdrant-client[fastembed]'``` on zsh.
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from qdrant_client import QdrantClient
|
|
230
|
+
|
|
231
|
+
# Initialize the client
|
|
232
|
+
client = QdrantClient("localhost", port=6333) # For production
|
|
233
|
+
# client = QdrantClient(":memory:") # For small experiments
|
|
234
|
+
|
|
235
|
+
# Prepare your documents, metadata, and IDs
|
|
236
|
+
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
|
|
237
|
+
metadata = [
|
|
238
|
+
{"source": "Langchain-docs"},
|
|
239
|
+
{"source": "Llama-index-docs"},
|
|
240
|
+
]
|
|
241
|
+
ids = [42, 2]
|
|
242
|
+
|
|
243
|
+
# If you want to change the model:
|
|
244
|
+
# client.set_model("sentence-transformers/all-MiniLM-L6-v2")
|
|
245
|
+
# List of supported models: https://qdrant.github.io/fastembed/examples/Supported_Models
|
|
246
|
+
|
|
247
|
+
# Use the new add() instead of upsert()
|
|
248
|
+
# This internally calls embed() of the configured embedding model
|
|
249
|
+
client.add(
|
|
250
|
+
collection_name="demo_collection",
|
|
251
|
+
documents=docs,
|
|
252
|
+
metadata=metadata,
|
|
253
|
+
ids=ids
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
search_result = client.query(
|
|
257
|
+
collection_name="demo_collection",
|
|
258
|
+
query_text="This is a query document"
|
|
259
|
+
)
|
|
260
|
+
print(search_result)
|
|
261
|
+
```
|
|
262
|
+
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: fastembed-gpu
|
|
3
|
-
Version: 0.2.7
|
|
4
|
-
Summary: Fast, light, accurate library built for retrieval embedding generation
|
|
5
|
-
Home-page: https://github.com/qdrant/fastembed
|
|
6
|
-
License: Apache License
|
|
7
|
-
Keywords: vector,embedding,neural,search,qdrant,sentence-transformers
|
|
8
|
-
Author: NirantK
|
|
9
|
-
Author-email: nirant.bits@gmail.com
|
|
10
|
-
Requires-Python: >=3.8.0,<3.13
|
|
11
|
-
Classifier: License :: Other/Proprietary License
|
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Requires-Dist: huggingface-hub (>=0.20,<0.21)
|
|
19
|
-
Requires-Dist: loguru (>=0.7.2,<0.8.0)
|
|
20
|
-
Requires-Dist: numpy (>=1.21) ; python_version < "3.12"
|
|
21
|
-
Requires-Dist: numpy (>=1.26) ; python_version >= "3.12"
|
|
22
|
-
Requires-Dist: onnxruntime-gpu (>=1.17.0,<2.0.0)
|
|
23
|
-
Requires-Dist: requests (>=2.31,<3.0)
|
|
24
|
-
Requires-Dist: tokenizers (>=0.15,<0.16)
|
|
25
|
-
Requires-Dist: tqdm (>=4.66,<5.0)
|
|
26
|
-
Project-URL: Repository, https://github.com/qdrant/fastembed
|
|
27
|
-
Description-Content-Type: text/markdown
|
|
28
|
-
|
|
29
1
|
# ⚡️ What is FastEmbed?
|
|
30
2
|
|
|
31
3
|
FastEmbed is a lightweight, fast, Python library built for embedding generation. We [support popular text models](https://qdrant.github.io/fastembed/examples/Supported_Models/). Please [open a GitHub issue](https://github.com/qdrant/fastembed/issues/new) if you want us to add a new model.
|
|
@@ -36,9 +8,9 @@ The default text embedding (`TextEmbedding`) model is Flag Embedding, presented
|
|
|
36
8
|
|
|
37
9
|
1. Light: FastEmbed is a lightweight library with few external dependencies. We don't require a GPU and don't download GBs of PyTorch dependencies, and instead use the ONNX Runtime. This makes it a great candidate for serverless runtimes like AWS Lambda.
|
|
38
10
|
|
|
39
|
-
2. Fast: FastEmbed is designed for speed. We use the ONNX Runtime, which is faster than PyTorch. We also use data
|
|
11
|
+
2. Fast: FastEmbed is designed for speed. We use the ONNX Runtime, which is faster than PyTorch. We also use data parallelism for encoding large datasets.
|
|
40
12
|
|
|
41
|
-
3. Accurate: FastEmbed is better than OpenAI Ada-002. We also [
|
|
13
|
+
3. Accurate: FastEmbed is better than OpenAI Ada-002. We also [support](https://qdrant.github.io/fastembed/examples/Supported_Models/) an ever-expanding set of models, including a few multilingual models.
|
|
42
14
|
|
|
43
15
|
## 🚀 Installation
|
|
44
16
|
|
|
@@ -46,11 +18,9 @@ To install the FastEmbed library, pip works best. You can install it with or wit
|
|
|
46
18
|
|
|
47
19
|
```bash
|
|
48
20
|
pip install fastembed
|
|
49
|
-
```
|
|
50
21
|
|
|
51
|
-
|
|
22
|
+
# or with GPU support
|
|
52
23
|
|
|
53
|
-
```bash
|
|
54
24
|
pip install fastembed-gpu
|
|
55
25
|
```
|
|
56
26
|
|
|
@@ -58,10 +28,10 @@ pip install fastembed-gpu
|
|
|
58
28
|
|
|
59
29
|
```python
|
|
60
30
|
from fastembed import TextEmbedding
|
|
61
|
-
|
|
31
|
+
|
|
62
32
|
|
|
63
33
|
# Example list of documents
|
|
64
|
-
documents:
|
|
34
|
+
documents: list[str] = [
|
|
65
35
|
"This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc.",
|
|
66
36
|
"fastembed is supported by and maintained by Qdrant.",
|
|
67
37
|
]
|
|
@@ -76,19 +46,130 @@ embeddings_list = list(embedding_model.embed(documents))
|
|
|
76
46
|
len(embeddings_list[0]) # Vector of 384 dimensions
|
|
77
47
|
```
|
|
78
48
|
|
|
79
|
-
|
|
49
|
+
Fastembed supports a variety of models for different tasks and modalities.
|
|
50
|
+
The list of all the available models can be found [here](https://qdrant.github.io/fastembed/examples/Supported_Models/)
|
|
51
|
+
### 🎒 Dense text embeddings
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from fastembed import TextEmbedding
|
|
55
|
+
|
|
56
|
+
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")
|
|
57
|
+
embeddings = list(model.embed(documents))
|
|
58
|
+
|
|
59
|
+
# [
|
|
60
|
+
# array([-0.1115, 0.0097, 0.0052, 0.0195, ...], dtype=float32),
|
|
61
|
+
# array([-0.1019, 0.0635, -0.0332, 0.0522, ...], dtype=float32)
|
|
62
|
+
# ]
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### 🔱 Sparse text embeddings
|
|
69
|
+
|
|
70
|
+
* SPLADE++
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from fastembed import SparseTextEmbedding
|
|
74
|
+
|
|
75
|
+
model = SparseTextEmbedding(model_name="prithivida/Splade_PP_en_v1")
|
|
76
|
+
embeddings = list(model.embed(documents))
|
|
77
|
+
|
|
78
|
+
# [
|
|
79
|
+
# SparseEmbedding(indices=[ 17, 123, 919, ... ], values=[0.71, 0.22, 0.39, ...]),
|
|
80
|
+
# SparseEmbedding(indices=[ 38, 12, 91, ... ], values=[0.11, 0.22, 0.39, ...])
|
|
81
|
+
# ]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
<!--
|
|
85
|
+
* BM42 - ([link](ToDo))
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
from fastembed import SparseTextEmbedding
|
|
89
|
+
|
|
90
|
+
model = SparseTextEmbedding(model_name="Qdrant/bm42-all-minilm-l6-v2-attentions")
|
|
91
|
+
embeddings = list(model.embed(documents))
|
|
92
|
+
|
|
93
|
+
# [
|
|
94
|
+
# SparseEmbedding(indices=[ 17, 123, 919, ... ], values=[0.71, 0.22, 0.39, ...]),
|
|
95
|
+
# SparseEmbedding(indices=[ 38, 12, 91, ... ], values=[0.11, 0.22, 0.39, ...])
|
|
96
|
+
# ]
|
|
97
|
+
```
|
|
98
|
+
-->
|
|
80
99
|
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
### 🦥 Late interaction models (aka ColBERT)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from fastembed import LateInteractionTextEmbedding
|
|
105
|
+
|
|
106
|
+
model = LateInteractionTextEmbedding(model_name="colbert-ir/colbertv2.0")
|
|
107
|
+
embeddings = list(model.embed(documents))
|
|
108
|
+
|
|
109
|
+
# [
|
|
110
|
+
# array([
|
|
111
|
+
# [-0.1115, 0.0097, 0.0052, 0.0195, ...],
|
|
112
|
+
# [-0.1019, 0.0635, -0.0332, 0.0522, ...],
|
|
113
|
+
# ]),
|
|
114
|
+
# array([
|
|
115
|
+
# [-0.9019, 0.0335, -0.0032, 0.0991, ...],
|
|
116
|
+
# [-0.2115, 0.8097, 0.1052, 0.0195, ...],
|
|
117
|
+
# ]),
|
|
118
|
+
# ]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 🖼️ Image embeddings
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from fastembed import ImageEmbedding
|
|
125
|
+
|
|
126
|
+
images = [
|
|
127
|
+
"./path/to/image1.jpg",
|
|
128
|
+
"./path/to/image2.jpg",
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
model = ImageEmbedding(model_name="Qdrant/clip-ViT-B-32-vision")
|
|
132
|
+
embeddings = list(model.embed(images))
|
|
133
|
+
|
|
134
|
+
# [
|
|
135
|
+
# array([-0.1115, 0.0097, 0.0052, 0.0195, ...], dtype=float32),
|
|
136
|
+
# array([-0.1019, 0.0635, -0.0332, 0.0522, ...], dtype=float32)
|
|
137
|
+
# ]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 🔄 Rerankers
|
|
141
|
+
```python
|
|
142
|
+
from fastembed.rerank.cross_encoder import TextCrossEncoder
|
|
143
|
+
|
|
144
|
+
query = "Who is maintaining Qdrant?"
|
|
145
|
+
documents: list[str] = [
|
|
146
|
+
"This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc.",
|
|
147
|
+
"fastembed is supported by and maintained by Qdrant.",
|
|
148
|
+
]
|
|
149
|
+
encoder = TextCrossEncoder(model_name="Xenova/ms-marco-MiniLM-L-6-v2")
|
|
150
|
+
scores = list(encoder.rerank(query, documents))
|
|
151
|
+
|
|
152
|
+
# [-11.48061752319336, 5.472434997558594]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## ⚡️ FastEmbed on a GPU
|
|
156
|
+
|
|
157
|
+
FastEmbed supports running on GPU devices.
|
|
158
|
+
It requires installation of the `fastembed-gpu` package.
|
|
83
159
|
|
|
84
160
|
```bash
|
|
85
161
|
pip install fastembed-gpu
|
|
86
|
-
```
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Check our [example](https://qdrant.github.io/fastembed/examples/FastEmbed_GPU/) for detailed instructions, CUDA 12.x support and troubleshooting of the common issues.
|
|
87
165
|
|
|
88
166
|
```python
|
|
89
167
|
from fastembed import TextEmbedding
|
|
90
168
|
|
|
91
|
-
embedding_model = TextEmbedding(
|
|
169
|
+
embedding_model = TextEmbedding(
|
|
170
|
+
model_name="BAAI/bge-small-en-v1.5",
|
|
171
|
+
providers=["CUDAExecutionProvider"]
|
|
172
|
+
)
|
|
92
173
|
print("The model BAAI/bge-small-en-v1.5 is ready to use on a GPU.")
|
|
93
174
|
|
|
94
175
|
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
|
|
3
|
+
from fastembed.image import ImageEmbedding
|
|
4
|
+
from fastembed.late_interaction import LateInteractionTextEmbedding
|
|
5
|
+
from fastembed.sparse import SparseEmbedding, SparseTextEmbedding
|
|
6
|
+
from fastembed.text import TextEmbedding
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
version = importlib.metadata.version("fastembed")
|
|
10
|
+
except importlib.metadata.PackageNotFoundError as _:
|
|
11
|
+
version = importlib.metadata.version("fastembed-gpu")
|
|
12
|
+
|
|
13
|
+
__version__ = version
|
|
14
|
+
__all__ = [
|
|
15
|
+
"TextEmbedding",
|
|
16
|
+
"SparseTextEmbedding",
|
|
17
|
+
"SparseEmbedding",
|
|
18
|
+
"ImageEmbedding",
|
|
19
|
+
"LateInteractionTextEmbedding",
|
|
20
|
+
]
|