fastembed 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastembed
3
- Version: 0.2.1
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 Github issue](https://github.com/qdrant/fastembed/issues/new) if you want us to add a new model.
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
- ## 📖 Usage
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
- Might have to use ```pip install 'qdrant-client[fastembed]'``` on zsh.
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
- # OR if you just want to try it out quickly:
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
- # Use the new add method
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 Github issue](https://github.com/qdrant/fastembed/issues/new) if you want us to add a new model.
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
- ## 📖 Usage
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
- Might have to use ```pip install 'qdrant-client[fastembed]'``` on zsh.
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
- # OR if you just want to try it out quickly:
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
- # Use the new add method
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,
@@ -0,0 +1,3 @@
1
+ from fastembed.text.text_embedding import TextEmbedding
2
+
3
+ __all__ = ["TextEmbedding"]
@@ -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["pad_token_id"], pad_token=tokenizer_config["pad_token"])
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
- cache_dir = Path(os.getenv("FASTEMBED_CACHE_PATH", default_cache_dir))
27
+ cache_path = Path(os.getenv("FASTEMBED_CACHE_PATH", default_cache_dir))
28
28
  else:
29
- cache_dir = Path(cache_dir)
29
+ cache_path = Path(cache_dir)
30
30
 
31
- cache_dir.mkdir(parents=True, exist_ok=True)
31
+ cache_path.mkdir(parents=True, exist_ok=True)
32
32
 
33
- return cache_dir
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." " Use TextEmbedding instead.")
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
- self,
55
- model_name: str,
56
- cache_dir: str,
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
- break
60
+ return
62
61
 
63
- if self.model is None:
64
- raise ValueError(
65
- f"Model {model_name} is not supported in TextEmbedding."
66
- "Please check the supported models using `TextEmbedding.list_supported_models()`"
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
  """
@@ -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()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fastembed"
3
- version = "0.2.1"
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.1.13"
29
+ ruff = "^0.2.2"
30
30
  notebook = ">=7.0.2"
31
- mkdocs-material = "^9.1.21"
32
- mkdocstrings = "^0.22.0"
33
- pillow = "^10.0.0"
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 = { version = "^3.6.0", python = ">=3.9,<3.12" }
36
+ pre-commit = {version = "^3.6.2", python = ">=3.9,<3.12" }
37
37
 
38
38
 
39
39
  [build-system]
@@ -1,3 +0,0 @@
1
- from .embedding import TextEmbedding
2
-
3
- __all__ = [TextEmbedding]
File without changes