fastembed 0.2.0__tar.gz → 0.2.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-0.2.0 → fastembed-0.2.2}/PKG-INFO +11 -8
- {fastembed-0.2.0 → fastembed-0.2.2}/README.md +10 -7
- fastembed-0.2.2/fastembed/__init__.py +3 -0
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/common/models.py +1 -1
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/common/utils.py +4 -4
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/embedding.py +1 -1
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/text/e5_onnx_embedding.py +5 -5
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/text/onnx_embedding.py +13 -4
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/text/text_embedding.py +6 -8
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/text/text_embedding_base.py +10 -8
- {fastembed-0.2.0 → fastembed-0.2.2}/pyproject.toml +6 -6
- fastembed-0.2.0/fastembed/text/__init__.py +0 -0
- {fastembed-0.2.0 → fastembed-0.2.2}/LICENSE +0 -0
- {fastembed-0.2.0/fastembed → fastembed-0.2.2/fastembed/common}/__init__.py +0 -0
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/common/model_management.py +0 -0
- {fastembed-0.2.0/fastembed/common → fastembed-0.2.2/fastembed/image}/__init__.py +0 -0
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/models.json +0 -0
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/parallel_processor.py +0 -0
- {fastembed-0.2.0/fastembed/image → fastembed-0.2.2/fastembed/sparse}/__init__.py +0 -0
- {fastembed-0.2.0/fastembed/sparse → fastembed-0.2.2/fastembed/text}/__init__.py +0 -0
- {fastembed-0.2.0 → fastembed-0.2.2}/fastembed/text/jina_onnx_embedding.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fastembed
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Fast, light, accurate library built for retrieval embedding generation
|
|
5
5
|
Home-page: https://github.com/qdrant/fastembed
|
|
6
6
|
License: Apache License
|
|
@@ -29,7 +29,7 @@ Description-Content-Type: text/markdown
|
|
|
29
29
|
|
|
30
30
|
# ⚡️ What is FastEmbed?
|
|
31
31
|
|
|
32
|
-
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
|
|
32
|
+
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.
|
|
33
33
|
|
|
34
34
|
The default text embedding (`TextEmbedding`) model is Flag Embedding, the top model 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/examples/Retrieval_with_FastEmbed/) and how to use [FastEmbed with Qdrant](https://qdrant.github.io/fastembed/examples/Usage_With_Qdrant/).
|
|
35
35
|
|
|
@@ -52,7 +52,7 @@ To install the FastEmbed library, pip works:
|
|
|
52
52
|
pip install fastembed
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
## 📖
|
|
55
|
+
## 📖 Quickstart
|
|
56
56
|
|
|
57
57
|
```python
|
|
58
58
|
from fastembed import TextEmbedding
|
|
@@ -77,16 +77,14 @@ Installation with Qdrant Client in Python:
|
|
|
77
77
|
pip install qdrant-client[fastembed]
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
You might have to use ```pip install 'qdrant-client[fastembed]'``` on zsh.
|
|
81
81
|
|
|
82
82
|
```python
|
|
83
83
|
from qdrant_client import QdrantClient
|
|
84
84
|
|
|
85
85
|
# Initialize the client
|
|
86
86
|
client = QdrantClient("localhost", port=6333) # For production
|
|
87
|
-
#
|
|
88
|
-
# client = QdrantClient(":memory:")
|
|
89
|
-
# client = QdrantClient(path="path/to/db")
|
|
87
|
+
# client = QdrantClient(":memory:") # For small experiments
|
|
90
88
|
|
|
91
89
|
# Prepare your documents, metadata, and IDs
|
|
92
90
|
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
|
|
@@ -96,7 +94,12 @@ metadata = [
|
|
|
96
94
|
]
|
|
97
95
|
ids = [42, 2]
|
|
98
96
|
|
|
99
|
-
#
|
|
97
|
+
# If you want to change the model:
|
|
98
|
+
# client.set_model("sentence-transformers/all-MiniLM-L6-v2")
|
|
99
|
+
# List of supported models: https://qdrant.github.io/fastembed/examples/Supported_Models
|
|
100
|
+
|
|
101
|
+
# Use the new add() instead of upsert()
|
|
102
|
+
# This internally calls embed() of the configured embedding model
|
|
100
103
|
client.add(
|
|
101
104
|
collection_name="demo_collection",
|
|
102
105
|
documents=docs,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ⚡️ What is FastEmbed?
|
|
2
2
|
|
|
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
|
|
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.
|
|
4
4
|
|
|
5
5
|
The default text embedding (`TextEmbedding`) model is Flag Embedding, the top model 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/examples/Retrieval_with_FastEmbed/) and how to use [FastEmbed with Qdrant](https://qdrant.github.io/fastembed/examples/Usage_With_Qdrant/).
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ To install the FastEmbed library, pip works:
|
|
|
23
23
|
pip install fastembed
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## 📖
|
|
26
|
+
## 📖 Quickstart
|
|
27
27
|
|
|
28
28
|
```python
|
|
29
29
|
from fastembed import TextEmbedding
|
|
@@ -48,16 +48,14 @@ Installation with Qdrant Client in Python:
|
|
|
48
48
|
pip install qdrant-client[fastembed]
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
You might have to use ```pip install 'qdrant-client[fastembed]'``` on zsh.
|
|
52
52
|
|
|
53
53
|
```python
|
|
54
54
|
from qdrant_client import QdrantClient
|
|
55
55
|
|
|
56
56
|
# Initialize the client
|
|
57
57
|
client = QdrantClient("localhost", port=6333) # For production
|
|
58
|
-
#
|
|
59
|
-
# client = QdrantClient(":memory:")
|
|
60
|
-
# client = QdrantClient(path="path/to/db")
|
|
58
|
+
# client = QdrantClient(":memory:") # For small experiments
|
|
61
59
|
|
|
62
60
|
# Prepare your documents, metadata, and IDs
|
|
63
61
|
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
|
|
@@ -67,7 +65,12 @@ metadata = [
|
|
|
67
65
|
]
|
|
68
66
|
ids = [42, 2]
|
|
69
67
|
|
|
70
|
-
#
|
|
68
|
+
# If you want to change the model:
|
|
69
|
+
# client.set_model("sentence-transformers/all-MiniLM-L6-v2")
|
|
70
|
+
# List of supported models: https://qdrant.github.io/fastembed/examples/Supported_Models
|
|
71
|
+
|
|
72
|
+
# Use the new add() instead of upsert()
|
|
73
|
+
# This internally calls embed() of the configured embedding model
|
|
71
74
|
client.add(
|
|
72
75
|
collection_name="demo_collection",
|
|
73
76
|
documents=docs,
|
|
@@ -33,7 +33,7 @@ def load_tokenizer(model_dir: Path, max_length: int = 512) -> Tokenizer:
|
|
|
33
33
|
|
|
34
34
|
tokenizer = Tokenizer.from_file(str(tokenizer_path))
|
|
35
35
|
tokenizer.enable_truncation(max_length=min(tokenizer_config["model_max_length"], max_length))
|
|
36
|
-
tokenizer.enable_padding(pad_id=config
|
|
36
|
+
tokenizer.enable_padding(pad_id=config.get("pad_token_id", 0), pad_token=tokenizer_config["pad_token"])
|
|
37
37
|
|
|
38
38
|
for token in tokens_map.values():
|
|
39
39
|
if isinstance(token, str):
|
|
@@ -24,10 +24,10 @@ def define_cache_dir(cache_dir: Optional[str] = None) -> Path:
|
|
|
24
24
|
"""
|
|
25
25
|
if cache_dir is None:
|
|
26
26
|
default_cache_dir = os.path.join(tempfile.gettempdir(), "fastembed_cache")
|
|
27
|
-
|
|
27
|
+
cache_path = Path(os.getenv("FASTEMBED_CACHE_PATH", default_cache_dir))
|
|
28
28
|
else:
|
|
29
|
-
|
|
29
|
+
cache_path = Path(cache_dir)
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
cache_path.mkdir(parents=True, exist_ok=True)
|
|
32
32
|
|
|
33
|
-
return
|
|
33
|
+
return cache_path
|
|
@@ -4,7 +4,7 @@ from loguru import logger
|
|
|
4
4
|
|
|
5
5
|
from fastembed.text.text_embedding import TextEmbedding
|
|
6
6
|
|
|
7
|
-
logger.warning("DefaultEmbedding, FlagEmbedding, JinaEmbedding are deprecated." "
|
|
7
|
+
logger.warning("DefaultEmbedding, FlagEmbedding, JinaEmbedding are deprecated." "Use from fastembed import TextEmbedding instead.")
|
|
8
8
|
|
|
9
9
|
DefaultEmbedding = TextEmbedding
|
|
10
10
|
FlagEmbedding = TextEmbedding
|
|
@@ -22,8 +22,8 @@ supported_multilingual_e5_models = [
|
|
|
22
22
|
"size_in_GB": 1.11,
|
|
23
23
|
"sources": {
|
|
24
24
|
"hf": "xenova/paraphrase-multilingual-mpnet-base-v2",
|
|
25
|
-
}
|
|
26
|
-
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
27
|
]
|
|
28
28
|
|
|
29
29
|
|
|
@@ -51,8 +51,8 @@ class E5OnnxEmbedding(OnnxTextEmbedding):
|
|
|
51
51
|
|
|
52
52
|
class E5OnnxEmbeddingWorker(OnnxTextEmbeddingWorker):
|
|
53
53
|
def init_embedding(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
self,
|
|
55
|
+
model_name: str,
|
|
56
|
+
cache_dir: str,
|
|
57
57
|
) -> E5OnnxEmbedding:
|
|
58
58
|
return E5OnnxEmbedding(model_name=model_name, cache_dir=cache_dir, threads=1)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from multiprocessing import get_all_start_methods
|
|
3
|
-
from typing import List, Dict, Any, Tuple, Union, Iterable, Type
|
|
3
|
+
from typing import List, Dict, Any, Optional, Tuple, Union, Iterable, Type
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import onnxruntime as ort
|
|
@@ -98,6 +98,15 @@ supported_onnx_models = [
|
|
|
98
98
|
"hf": "qdrant/all-MiniLM-L6-v2-onnx",
|
|
99
99
|
},
|
|
100
100
|
},
|
|
101
|
+
{
|
|
102
|
+
"model": "nomic-ai/nomic-embed-text-v1",
|
|
103
|
+
"dim": 768,
|
|
104
|
+
"description": "8192 context length english model",
|
|
105
|
+
"size_in_GB": 0.54,
|
|
106
|
+
"sources": {
|
|
107
|
+
"hf": "nomic-ai/nomic-embed-text-v1",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
101
110
|
# {
|
|
102
111
|
# "model": "sentence-transformers/all-MiniLM-L6-v2",
|
|
103
112
|
# "dim": 384,
|
|
@@ -149,8 +158,8 @@ class OnnxTextEmbedding(TextEmbeddingBase):
|
|
|
149
158
|
def __init__(
|
|
150
159
|
self,
|
|
151
160
|
model_name: str = "BAAI/bge-small-en-v1.5",
|
|
152
|
-
cache_dir: str = None,
|
|
153
|
-
threads: int = None,
|
|
161
|
+
cache_dir: Optional[str] = None,
|
|
162
|
+
threads: Optional[int] = None,
|
|
154
163
|
**kwargs,
|
|
155
164
|
):
|
|
156
165
|
"""
|
|
@@ -193,7 +202,7 @@ class OnnxTextEmbedding(TextEmbeddingBase):
|
|
|
193
202
|
self,
|
|
194
203
|
documents: Union[str, Iterable[str]],
|
|
195
204
|
batch_size: int = 256,
|
|
196
|
-
parallel: int = None,
|
|
205
|
+
parallel: Optional[int] = None,
|
|
197
206
|
**kwargs,
|
|
198
207
|
) -> Iterable[np.ndarray]:
|
|
199
208
|
"""
|
|
@@ -53,24 +53,22 @@ class TextEmbedding(TextEmbeddingBase):
|
|
|
53
53
|
):
|
|
54
54
|
super().__init__(model_name, cache_dir, threads, **kwargs)
|
|
55
55
|
|
|
56
|
-
self.model = None
|
|
57
56
|
for embedding in self.EMBEDDINGS_REGISTRY:
|
|
58
57
|
supported_models = embedding.list_supported_models()
|
|
59
58
|
if any(model_name == model["model"] for model in supported_models):
|
|
60
59
|
self.model = embedding(model_name, cache_dir, threads, **kwargs)
|
|
61
|
-
|
|
60
|
+
return
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
)
|
|
62
|
+
raise ValueError(
|
|
63
|
+
f"Model {model_name} is not supported in TextEmbedding."
|
|
64
|
+
"Please check the supported models using `TextEmbedding.list_supported_models()`"
|
|
65
|
+
)
|
|
68
66
|
|
|
69
67
|
def embed(
|
|
70
68
|
self,
|
|
71
69
|
documents: Union[str, Iterable[str]],
|
|
72
70
|
batch_size: int = 256,
|
|
73
|
-
parallel: int = None,
|
|
71
|
+
parallel: Optional[int] = None,
|
|
74
72
|
**kwargs,
|
|
75
73
|
) -> Iterable[np.ndarray]:
|
|
76
74
|
"""
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Any, Dict, Iterable, List, Optional, Union
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ class TextEmbeddingBase(ModelManagement):
|
|
|
19
19
|
self,
|
|
20
20
|
documents: Union[str, Iterable[str]],
|
|
21
21
|
batch_size: int = 256,
|
|
22
|
-
parallel: int = None,
|
|
22
|
+
parallel: Optional[int] = None,
|
|
23
23
|
**kwargs,
|
|
24
24
|
) -> Iterable[np.ndarray]:
|
|
25
25
|
raise NotImplementedError()
|
|
@@ -39,17 +39,19 @@ class TextEmbeddingBase(ModelManagement):
|
|
|
39
39
|
# This is model-specific, so that different models can have specialized implementations
|
|
40
40
|
yield from self.embed(texts, **kwargs)
|
|
41
41
|
|
|
42
|
-
def query_embed(self, query: str, **kwargs) -> np.ndarray:
|
|
42
|
+
def query_embed(self, query: Union[str, Iterable[str]], **kwargs) -> Iterable[np.ndarray]:
|
|
43
43
|
"""
|
|
44
|
-
Embeds
|
|
44
|
+
Embeds queries
|
|
45
45
|
|
|
46
46
|
Args:
|
|
47
|
-
query (str): The query to
|
|
47
|
+
query (Union[str, Iterable[str]]): The query to embed, or an iterable e.g. list of queries.
|
|
48
48
|
|
|
49
49
|
Returns:
|
|
50
|
-
np.ndarray: The embeddings.
|
|
50
|
+
Iterable[np.ndarray]: The embeddings.
|
|
51
51
|
"""
|
|
52
52
|
|
|
53
53
|
# This is model-specific, so that different models can have specialized implementations
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if isinstance(query, str):
|
|
55
|
+
yield from self.embed([query], **kwargs)
|
|
56
|
+
if isinstance(query, Iterable):
|
|
57
|
+
yield from self.embed(query, **kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "fastembed"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "Fast, light, accurate library built for retrieval embedding generation"
|
|
5
5
|
authors = ["NirantK <nirant.bits@gmail.com>"]
|
|
6
6
|
license = "Apache License"
|
|
@@ -26,14 +26,14 @@ numpy = [
|
|
|
26
26
|
|
|
27
27
|
[tool.poetry.group.dev.dependencies]
|
|
28
28
|
pytest = "^7.4.2"
|
|
29
|
-
ruff = "^0.
|
|
29
|
+
ruff = "^0.2.2"
|
|
30
30
|
notebook = ">=7.0.2"
|
|
31
|
-
mkdocs-material = "^9.
|
|
32
|
-
mkdocstrings = "^0.
|
|
33
|
-
pillow = "^10.
|
|
31
|
+
mkdocs-material = "^9.5.10"
|
|
32
|
+
mkdocstrings = "^0.24.0"
|
|
33
|
+
pillow = "^10.2.0"
|
|
34
34
|
cairosvg = "^2.7.1"
|
|
35
35
|
mknotebooks = "^0.8.0"
|
|
36
|
-
pre-commit = {
|
|
36
|
+
pre-commit = {version = "^3.6.2", python = ">=3.9,<3.12" }
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
[build-system]
|
|
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
|