fastembed-haystack 1.1.0__tar.gz → 1.3.0__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_haystack-1.1.0 → fastembed_haystack-1.3.0}/.gitignore +9 -0
- fastembed_haystack-1.3.0/CHANGELOG.md +63 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/PKG-INFO +1 -1
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/examples/example.py +1 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/examples/sparse_example.py +1 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/pyproject.toml +31 -51
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/embedding_backend/fastembed_backend.py +16 -4
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/fastembed_sparse_document_embedder.py +6 -1
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/fastembed_sparse_text_embedder.py +6 -1
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/test_fastembed_backend.py +26 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/test_fastembed_document_embedder.py +1 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/test_fastembed_sparse_document_embedder.py +55 -2
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/test_fastembed_sparse_text_embedder.py +56 -1
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/test_fastembed_text_embedder.py +1 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/LICENSE.txt +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/README.md +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/pydoc/config.yml +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/__init__.py +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/embedding_backend/__init__.py +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/fastembed_document_embedder.py +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/src/haystack_integrations/components/embedders/fastembed/fastembed_text_embedder.py +0 -0
- {fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/__init__.py +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [unreleased]
|
|
4
|
+
|
|
5
|
+
### ⚙️ Miscellaneous Tasks
|
|
6
|
+
|
|
7
|
+
- Retry tests to reduce flakyness (#836)
|
|
8
|
+
- Update ruff invocation to include check parameter (#853)
|
|
9
|
+
|
|
10
|
+
### Fix
|
|
11
|
+
|
|
12
|
+
- Typo on Sparse embedders. The parameter should be "progress_bar" … (#814)
|
|
13
|
+
|
|
14
|
+
## [integrations/fastembed-v1.1.0] - 2024-05-15
|
|
15
|
+
|
|
16
|
+
## [integrations/fastembed-v1.0.0] - 2024-05-06
|
|
17
|
+
|
|
18
|
+
## [integrations/fastembed-v0.1.0] - 2024-04-10
|
|
19
|
+
|
|
20
|
+
### 🚀 Features
|
|
21
|
+
|
|
22
|
+
- *(FastEmbed)* Support for SPLADE Sparse Embedder (#579)
|
|
23
|
+
|
|
24
|
+
### 📚 Documentation
|
|
25
|
+
|
|
26
|
+
- Disable-class-def (#556)
|
|
27
|
+
|
|
28
|
+
## [integrations/fastembed-v0.0.6] - 2024-03-07
|
|
29
|
+
|
|
30
|
+
### 📚 Documentation
|
|
31
|
+
|
|
32
|
+
- Review and normalize docstrings - `integrations.fastembed` (#519)
|
|
33
|
+
- Small consistency improvements (#536)
|
|
34
|
+
|
|
35
|
+
## [integrations/fastembed-v0.0.5] - 2024-02-20
|
|
36
|
+
|
|
37
|
+
### 🐛 Bug Fixes
|
|
38
|
+
|
|
39
|
+
- Fix order of API docs (#447)
|
|
40
|
+
|
|
41
|
+
This PR will also push the docs to Readme
|
|
42
|
+
|
|
43
|
+
### 📚 Documentation
|
|
44
|
+
|
|
45
|
+
- Update category slug (#442)
|
|
46
|
+
|
|
47
|
+
## [integrations/fastembed-v0.0.4] - 2024-02-16
|
|
48
|
+
|
|
49
|
+
## [integrations/fastembed-v0.0.3] - 2024-02-12
|
|
50
|
+
|
|
51
|
+
### 🐛 Bug Fixes
|
|
52
|
+
|
|
53
|
+
- From numpy float to float (#391)
|
|
54
|
+
|
|
55
|
+
### 📚 Documentation
|
|
56
|
+
|
|
57
|
+
- Update paths and titles (#397)
|
|
58
|
+
|
|
59
|
+
## [integrations/fastembed-v0.0.2] - 2024-02-11
|
|
60
|
+
|
|
61
|
+
## [integrations/fastembed-v0.0.1] - 2024-02-10
|
|
62
|
+
|
|
63
|
+
<!-- generated by git-cliff -->
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: fastembed-haystack
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Haystack 2.x component to embed strings and Documents using fastembed embedding model
|
|
5
5
|
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations
|
|
6
6
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/fastembed/README.md
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from haystack import Document, Pipeline
|
|
2
2
|
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
|
|
3
3
|
from haystack.document_stores.in_memory import InMemoryDocumentStore
|
|
4
|
+
|
|
4
5
|
from haystack_integrations.components.embedders.fastembed import FastembedDocumentEmbedder, FastembedTextEmbedder
|
|
5
6
|
|
|
6
7
|
document_store = InMemoryDocumentStore(embedding_similarity_function="cosine")
|
|
@@ -10,9 +10,7 @@ readme = "README.md"
|
|
|
10
10
|
requires-python = ">=3.8"
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
keywords = []
|
|
13
|
-
authors = [
|
|
14
|
-
{ name = "deepset GmbH", email = "info@deepset.ai" },
|
|
15
|
-
]
|
|
13
|
+
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
|
|
16
14
|
classifiers = [
|
|
17
15
|
"License :: OSI Approved :: Apache Software License",
|
|
18
16
|
"Development Status :: 4 - Beta",
|
|
@@ -25,10 +23,7 @@ classifiers = [
|
|
|
25
23
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
26
24
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
27
25
|
]
|
|
28
|
-
dependencies = [
|
|
29
|
-
"haystack-ai>=2.0.1",
|
|
30
|
-
"fastembed>=0.2.5",
|
|
31
|
-
]
|
|
26
|
+
dependencies = ["haystack-ai>=2.0.1", "fastembed>=0.2.5"]
|
|
32
27
|
|
|
33
28
|
[project.urls]
|
|
34
29
|
Source = "https://github.com/deepset-ai/haystack-core-integrations"
|
|
@@ -50,50 +45,30 @@ git_describe_command = 'git describe --tags --match="integrations/fastembed-v[0-
|
|
|
50
45
|
dependencies = [
|
|
51
46
|
"coverage[toml]>=6.5",
|
|
52
47
|
"pytest",
|
|
48
|
+
"pytest-rerunfailures",
|
|
53
49
|
"ipython",
|
|
54
50
|
"haystack-pydoc-tools",
|
|
55
51
|
]
|
|
56
52
|
[tool.hatch.envs.default.scripts]
|
|
57
53
|
test = "pytest {args:tests}"
|
|
58
54
|
test-cov = "coverage run -m pytest {args:tests}"
|
|
59
|
-
cov-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
]
|
|
63
|
-
|
|
64
|
-
"test-cov",
|
|
65
|
-
"cov-report",
|
|
66
|
-
]
|
|
67
|
-
docs = [
|
|
68
|
-
"pydoc-markdown pydoc/config.yml"
|
|
69
|
-
]
|
|
55
|
+
test-cov-retry = "test-cov --reruns 3 --reruns-delay 30 -x"
|
|
56
|
+
cov-report = ["- coverage combine", "coverage report"]
|
|
57
|
+
cov = ["test-cov", "cov-report"]
|
|
58
|
+
cov-retry = ["test-cov-retry", "cov-report"]
|
|
59
|
+
docs = ["pydoc-markdown pydoc/config.yml"]
|
|
70
60
|
|
|
71
61
|
[[tool.hatch.envs.all.matrix]]
|
|
72
62
|
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
|
73
63
|
|
|
74
64
|
[tool.hatch.envs.lint]
|
|
75
65
|
detached = true
|
|
76
|
-
dependencies = [
|
|
77
|
-
"black>=23.1.0",
|
|
78
|
-
"mypy>=1.0.0",
|
|
79
|
-
"ruff>=0.0.243",
|
|
80
|
-
"numpy"
|
|
81
|
-
]
|
|
66
|
+
dependencies = ["black>=23.1.0", "mypy>=1.0.0", "ruff>=0.0.243", "numpy"]
|
|
82
67
|
[tool.hatch.envs.lint.scripts]
|
|
83
68
|
typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
|
|
84
|
-
style = [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
]
|
|
88
|
-
fmt = [
|
|
89
|
-
"black {args:.}",
|
|
90
|
-
"ruff --fix {args:.}",
|
|
91
|
-
"style",
|
|
92
|
-
]
|
|
93
|
-
all = [
|
|
94
|
-
"style",
|
|
95
|
-
"typing",
|
|
96
|
-
]
|
|
69
|
+
style = ["ruff check {args:.}", "black --check --diff {args:.}"]
|
|
70
|
+
fmt = ["black {args:.}", "ruff check --fix {args:.}", "style"]
|
|
71
|
+
all = ["style", "typing"]
|
|
97
72
|
|
|
98
73
|
[tool.black]
|
|
99
74
|
target-version = ["py38"]
|
|
@@ -103,6 +78,8 @@ skip-string-normalization = true
|
|
|
103
78
|
[tool.ruff]
|
|
104
79
|
target-version = "py38"
|
|
105
80
|
line-length = 120
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint]
|
|
106
83
|
select = [
|
|
107
84
|
"A",
|
|
108
85
|
"ARG",
|
|
@@ -135,24 +112,31 @@ ignore = [
|
|
|
135
112
|
"B027",
|
|
136
113
|
# Allow boolean positional values in function calls, like `dict.get(... True)`
|
|
137
114
|
"FBT003",
|
|
138
|
-
"FBT001",
|
|
115
|
+
"FBT001",
|
|
116
|
+
"FBT002",
|
|
139
117
|
# Ignore checks for possible passwords
|
|
140
|
-
"S105",
|
|
118
|
+
"S105",
|
|
119
|
+
"S106",
|
|
120
|
+
"S107",
|
|
141
121
|
# Ignore complexity
|
|
142
|
-
"C901",
|
|
122
|
+
"C901",
|
|
123
|
+
"PLR0911",
|
|
124
|
+
"PLR0912",
|
|
125
|
+
"PLR0913",
|
|
126
|
+
"PLR0915",
|
|
143
127
|
]
|
|
144
128
|
unfixable = [
|
|
145
129
|
# Don't touch unused imports
|
|
146
130
|
"F401",
|
|
147
131
|
]
|
|
148
132
|
|
|
149
|
-
[tool.ruff.isort]
|
|
150
|
-
known-first-party = ["
|
|
133
|
+
[tool.ruff.lint.isort]
|
|
134
|
+
known-first-party = ["haystack_integrations"]
|
|
151
135
|
|
|
152
|
-
[tool.ruff.flake8-tidy-imports]
|
|
136
|
+
[tool.ruff.lint.flake8-tidy-imports]
|
|
153
137
|
ban-relative-imports = "parents"
|
|
154
138
|
|
|
155
|
-
[tool.ruff.per-file-ignores]
|
|
139
|
+
[tool.ruff.lint.per-file-ignores]
|
|
156
140
|
# Tests can use magic values, assertions, and relative imports
|
|
157
141
|
"tests/**/*" = ["PLR2004", "S101", "TID252"]
|
|
158
142
|
# examples can contain "print" commands
|
|
@@ -165,12 +149,8 @@ parallel = false
|
|
|
165
149
|
|
|
166
150
|
[tool.coverage.report]
|
|
167
151
|
omit = ["*/tests/*", "*/__init__.py"]
|
|
168
|
-
show_missing=true
|
|
169
|
-
exclude_lines = [
|
|
170
|
-
"no cov",
|
|
171
|
-
"if __name__ == .__main__.:",
|
|
172
|
-
"if TYPE_CHECKING:",
|
|
173
|
-
]
|
|
152
|
+
show_missing = true
|
|
153
|
+
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
|
|
174
154
|
|
|
175
155
|
[[tool.mypy.overrides]]
|
|
176
156
|
module = [
|
|
@@ -178,6 +158,6 @@ module = [
|
|
|
178
158
|
"haystack_integrations.*",
|
|
179
159
|
"fastembed.*",
|
|
180
160
|
"pytest.*",
|
|
181
|
-
"numpy.*"
|
|
161
|
+
"numpy.*",
|
|
182
162
|
]
|
|
183
163
|
ignore_missing_imports = true
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import ClassVar, Dict, List, Optional
|
|
1
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
2
2
|
|
|
3
3
|
from haystack.dataclasses.sparse_embedding import SparseEmbedding
|
|
4
4
|
from tqdm import tqdm
|
|
@@ -73,14 +73,19 @@ class _FastembedSparseEmbeddingBackendFactory:
|
|
|
73
73
|
cache_dir: Optional[str] = None,
|
|
74
74
|
threads: Optional[int] = None,
|
|
75
75
|
local_files_only: bool = False,
|
|
76
|
+
model_kwargs: Optional[Dict[str, Any]] = None,
|
|
76
77
|
):
|
|
77
|
-
embedding_backend_id = f"{model_name}{cache_dir}{threads}"
|
|
78
|
+
embedding_backend_id = f"{model_name}{cache_dir}{threads}{local_files_only}{model_kwargs}"
|
|
78
79
|
|
|
79
80
|
if embedding_backend_id in _FastembedSparseEmbeddingBackendFactory._instances:
|
|
80
81
|
return _FastembedSparseEmbeddingBackendFactory._instances[embedding_backend_id]
|
|
81
82
|
|
|
82
83
|
embedding_backend = _FastembedSparseEmbeddingBackend(
|
|
83
|
-
model_name=model_name,
|
|
84
|
+
model_name=model_name,
|
|
85
|
+
cache_dir=cache_dir,
|
|
86
|
+
threads=threads,
|
|
87
|
+
local_files_only=local_files_only,
|
|
88
|
+
model_kwargs=model_kwargs,
|
|
84
89
|
)
|
|
85
90
|
_FastembedSparseEmbeddingBackendFactory._instances[embedding_backend_id] = embedding_backend
|
|
86
91
|
return embedding_backend
|
|
@@ -97,9 +102,16 @@ class _FastembedSparseEmbeddingBackend:
|
|
|
97
102
|
cache_dir: Optional[str] = None,
|
|
98
103
|
threads: Optional[int] = None,
|
|
99
104
|
local_files_only: bool = False,
|
|
105
|
+
model_kwargs: Optional[Dict[str, Any]] = None,
|
|
100
106
|
):
|
|
107
|
+
model_kwargs = model_kwargs or {}
|
|
108
|
+
|
|
101
109
|
self.model = SparseTextEmbedding(
|
|
102
|
-
model_name=model_name,
|
|
110
|
+
model_name=model_name,
|
|
111
|
+
cache_dir=cache_dir,
|
|
112
|
+
threads=threads,
|
|
113
|
+
local_files_only=local_files_only,
|
|
114
|
+
**model_kwargs,
|
|
103
115
|
)
|
|
104
116
|
|
|
105
117
|
def embed(self, data: List[List[str]], progress_bar=True, **kwargs) -> List[SparseEmbedding]:
|
|
@@ -62,6 +62,7 @@ class FastembedSparseDocumentEmbedder:
|
|
|
62
62
|
local_files_only: bool = False,
|
|
63
63
|
meta_fields_to_embed: Optional[List[str]] = None,
|
|
64
64
|
embedding_separator: str = "\n",
|
|
65
|
+
model_kwargs: Optional[Dict[str, Any]] = None,
|
|
65
66
|
):
|
|
66
67
|
"""
|
|
67
68
|
Create an FastembedDocumentEmbedder component.
|
|
@@ -81,6 +82,7 @@ class FastembedSparseDocumentEmbedder:
|
|
|
81
82
|
:param local_files_only: If `True`, only use the model files in the `cache_dir`.
|
|
82
83
|
:param meta_fields_to_embed: List of meta fields that should be embedded along with the Document content.
|
|
83
84
|
:param embedding_separator: Separator used to concatenate the meta fields to the Document content.
|
|
85
|
+
:param model_kwargs: Dictionary containing model parameters such as `k`, `b`, `avg_len`, `language`.
|
|
84
86
|
"""
|
|
85
87
|
|
|
86
88
|
self.model_name = model
|
|
@@ -92,6 +94,7 @@ class FastembedSparseDocumentEmbedder:
|
|
|
92
94
|
self.local_files_only = local_files_only
|
|
93
95
|
self.meta_fields_to_embed = meta_fields_to_embed or []
|
|
94
96
|
self.embedding_separator = embedding_separator
|
|
97
|
+
self.model_kwargs = model_kwargs
|
|
95
98
|
|
|
96
99
|
def to_dict(self) -> Dict[str, Any]:
|
|
97
100
|
"""
|
|
@@ -110,6 +113,7 @@ class FastembedSparseDocumentEmbedder:
|
|
|
110
113
|
local_files_only=self.local_files_only,
|
|
111
114
|
meta_fields_to_embed=self.meta_fields_to_embed,
|
|
112
115
|
embedding_separator=self.embedding_separator,
|
|
116
|
+
model_kwargs=self.model_kwargs,
|
|
113
117
|
)
|
|
114
118
|
|
|
115
119
|
def warm_up(self):
|
|
@@ -122,6 +126,7 @@ class FastembedSparseDocumentEmbedder:
|
|
|
122
126
|
cache_dir=self.cache_dir,
|
|
123
127
|
threads=self.threads,
|
|
124
128
|
local_files_only=self.local_files_only,
|
|
129
|
+
model_kwargs=self.model_kwargs,
|
|
125
130
|
)
|
|
126
131
|
|
|
127
132
|
def _prepare_texts_to_embed(self, documents: List[Document]) -> List[str]:
|
|
@@ -159,7 +164,7 @@ class FastembedSparseDocumentEmbedder:
|
|
|
159
164
|
embeddings = self.embedding_backend.embed(
|
|
160
165
|
texts_to_embed,
|
|
161
166
|
batch_size=self.batch_size,
|
|
162
|
-
|
|
167
|
+
progress_bar=self.progress_bar,
|
|
163
168
|
parallel=self.parallel,
|
|
164
169
|
)
|
|
165
170
|
|
|
@@ -35,6 +35,7 @@ class FastembedSparseTextEmbedder:
|
|
|
35
35
|
progress_bar: bool = True,
|
|
36
36
|
parallel: Optional[int] = None,
|
|
37
37
|
local_files_only: bool = False,
|
|
38
|
+
model_kwargs: Optional[Dict[str, Any]] = None,
|
|
38
39
|
):
|
|
39
40
|
"""
|
|
40
41
|
Create a FastembedSparseTextEmbedder component.
|
|
@@ -50,6 +51,7 @@ class FastembedSparseTextEmbedder:
|
|
|
50
51
|
If 0, use all available cores.
|
|
51
52
|
If None, don't use data-parallel processing, use default onnxruntime threading instead.
|
|
52
53
|
:param local_files_only: If `True`, only use the model files in the `cache_dir`.
|
|
54
|
+
:param model_kwargs: Dictionary containing model parameters such as `k`, `b`, `avg_len`, `language`.
|
|
53
55
|
"""
|
|
54
56
|
|
|
55
57
|
self.model_name = model
|
|
@@ -58,6 +60,7 @@ class FastembedSparseTextEmbedder:
|
|
|
58
60
|
self.progress_bar = progress_bar
|
|
59
61
|
self.parallel = parallel
|
|
60
62
|
self.local_files_only = local_files_only
|
|
63
|
+
self.model_kwargs = model_kwargs
|
|
61
64
|
|
|
62
65
|
def to_dict(self) -> Dict[str, Any]:
|
|
63
66
|
"""
|
|
@@ -74,6 +77,7 @@ class FastembedSparseTextEmbedder:
|
|
|
74
77
|
progress_bar=self.progress_bar,
|
|
75
78
|
parallel=self.parallel,
|
|
76
79
|
local_files_only=self.local_files_only,
|
|
80
|
+
model_kwargs=self.model_kwargs,
|
|
77
81
|
)
|
|
78
82
|
|
|
79
83
|
def warm_up(self):
|
|
@@ -86,6 +90,7 @@ class FastembedSparseTextEmbedder:
|
|
|
86
90
|
cache_dir=self.cache_dir,
|
|
87
91
|
threads=self.threads,
|
|
88
92
|
local_files_only=self.local_files_only,
|
|
93
|
+
model_kwargs=self.model_kwargs,
|
|
89
94
|
)
|
|
90
95
|
|
|
91
96
|
@component.output_types(sparse_embedding=SparseEmbedding)
|
|
@@ -111,7 +116,7 @@ class FastembedSparseTextEmbedder:
|
|
|
111
116
|
|
|
112
117
|
embedding = self.embedding_backend.embed(
|
|
113
118
|
[text],
|
|
114
|
-
|
|
119
|
+
progress_bar=self.progress_bar,
|
|
115
120
|
parallel=self.parallel,
|
|
116
121
|
)[0]
|
|
117
122
|
return {"sparse_embedding": embedding}
|
|
@@ -2,6 +2,7 @@ from unittest.mock import patch
|
|
|
2
2
|
|
|
3
3
|
from haystack_integrations.components.embedders.fastembed.embedding_backend.fastembed_backend import (
|
|
4
4
|
_FastembedEmbeddingBackendFactory,
|
|
5
|
+
_FastembedSparseEmbeddingBackendFactory,
|
|
5
6
|
)
|
|
6
7
|
|
|
7
8
|
|
|
@@ -44,3 +45,28 @@ def test_embedding_function_with_kwargs(mock_instructor): # noqa: ARG001
|
|
|
44
45
|
embedding_backend.model.embed.assert_called_once_with(data)
|
|
45
46
|
# restore the factory stateTrue
|
|
46
47
|
_FastembedEmbeddingBackendFactory._instances = {}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@patch("haystack_integrations.components.embedders.fastembed.embedding_backend.fastembed_backend.SparseTextEmbedding")
|
|
51
|
+
def test_model_kwargs_initialization(mock_instructor):
|
|
52
|
+
bm25_config = {
|
|
53
|
+
"k": 1.2,
|
|
54
|
+
"b": 0.75,
|
|
55
|
+
"avg_len": 300.0,
|
|
56
|
+
"language": "english",
|
|
57
|
+
"token_max_length": 40,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Invoke the backend factory with the BM25 configuration
|
|
61
|
+
_FastembedSparseEmbeddingBackendFactory.get_embedding_backend(
|
|
62
|
+
model_name="Qdrant/bm25",
|
|
63
|
+
model_kwargs=bm25_config,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Check if SparseTextEmbedding was called with the correct arguments
|
|
67
|
+
mock_instructor.assert_called_once_with(
|
|
68
|
+
model_name="Qdrant/bm25", cache_dir=None, threads=None, local_files_only=False, **bm25_config
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Restore factory state after the test
|
|
72
|
+
_FastembedSparseEmbeddingBackendFactory._instances = {}
|
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
|
4
4
|
import pytest
|
|
5
5
|
from haystack import Document, default_from_dict
|
|
6
6
|
from haystack.dataclasses.sparse_embedding import SparseEmbedding
|
|
7
|
+
|
|
7
8
|
from haystack_integrations.components.embedders.fastembed.fastembed_sparse_document_embedder import (
|
|
8
9
|
FastembedSparseDocumentEmbedder,
|
|
9
10
|
)
|
|
@@ -68,6 +69,7 @@ class TestFastembedSparseDocumentEmbedderDoc:
|
|
|
68
69
|
"local_files_only": False,
|
|
69
70
|
"embedding_separator": "\n",
|
|
70
71
|
"meta_fields_to_embed": [],
|
|
72
|
+
"model_kwargs": None,
|
|
71
73
|
},
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -99,6 +101,7 @@ class TestFastembedSparseDocumentEmbedderDoc:
|
|
|
99
101
|
"local_files_only": True,
|
|
100
102
|
"meta_fields_to_embed": ["test_field"],
|
|
101
103
|
"embedding_separator": " | ",
|
|
104
|
+
"model_kwargs": None,
|
|
102
105
|
},
|
|
103
106
|
}
|
|
104
107
|
|
|
@@ -173,7 +176,11 @@ class TestFastembedSparseDocumentEmbedderDoc:
|
|
|
173
176
|
mocked_factory.get_embedding_backend.assert_not_called()
|
|
174
177
|
embedder.warm_up()
|
|
175
178
|
mocked_factory.get_embedding_backend.assert_called_once_with(
|
|
176
|
-
model_name="prithvida/Splade_PP_en_v1",
|
|
179
|
+
model_name="prithvida/Splade_PP_en_v1",
|
|
180
|
+
cache_dir=None,
|
|
181
|
+
threads=None,
|
|
182
|
+
local_files_only=False,
|
|
183
|
+
model_kwargs=None,
|
|
177
184
|
)
|
|
178
185
|
|
|
179
186
|
@patch(
|
|
@@ -270,10 +277,56 @@ class TestFastembedSparseDocumentEmbedderDoc:
|
|
|
270
277
|
"meta_value 4\ndocument-number 4",
|
|
271
278
|
],
|
|
272
279
|
batch_size=32,
|
|
273
|
-
|
|
280
|
+
progress_bar=True,
|
|
274
281
|
parallel=None,
|
|
275
282
|
)
|
|
276
283
|
|
|
284
|
+
def test_init_with_model_kwargs_parameters(self):
|
|
285
|
+
"""
|
|
286
|
+
Test initialization of FastembedSparseDocumentEmbedder with model_kwargs parameters.
|
|
287
|
+
"""
|
|
288
|
+
bm25_config = {
|
|
289
|
+
"k": 1.2,
|
|
290
|
+
"b": 0.75,
|
|
291
|
+
"avg_len": 300.0,
|
|
292
|
+
"language": "english",
|
|
293
|
+
"token_max_length": 50,
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
embedder = FastembedSparseDocumentEmbedder(
|
|
297
|
+
model="Qdrant/bm25",
|
|
298
|
+
model_kwargs=bm25_config,
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
assert embedder.model_kwargs == bm25_config
|
|
302
|
+
|
|
303
|
+
@pytest.mark.integration
|
|
304
|
+
def test_run_with_model_kwargs(self):
|
|
305
|
+
"""
|
|
306
|
+
Integration test to check the embedding with model_kwargs parameters.
|
|
307
|
+
"""
|
|
308
|
+
bm42_config = {
|
|
309
|
+
"alpha": 0.2,
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
embedder = FastembedSparseDocumentEmbedder(
|
|
313
|
+
model="Qdrant/bm42-all-minilm-l6-v2-attentions",
|
|
314
|
+
model_kwargs=bm42_config,
|
|
315
|
+
)
|
|
316
|
+
embedder.warm_up()
|
|
317
|
+
|
|
318
|
+
doc = Document(content="Example content using BM42")
|
|
319
|
+
|
|
320
|
+
result = embedder.run(documents=[doc])
|
|
321
|
+
embedding = result["documents"][0].sparse_embedding
|
|
322
|
+
embedding_dict = embedding.to_dict()
|
|
323
|
+
|
|
324
|
+
assert isinstance(embedding, SparseEmbedding)
|
|
325
|
+
assert isinstance(embedding_dict["indices"], list)
|
|
326
|
+
assert isinstance(embedding_dict["values"], list)
|
|
327
|
+
assert isinstance(embedding_dict["indices"][0], int)
|
|
328
|
+
assert isinstance(embedding_dict["values"][0], float)
|
|
329
|
+
|
|
277
330
|
@pytest.mark.integration
|
|
278
331
|
def test_run(self):
|
|
279
332
|
embedder = FastembedSparseDocumentEmbedder(
|
{fastembed_haystack-1.1.0 → fastembed_haystack-1.3.0}/tests/test_fastembed_sparse_text_embedder.py
RENAMED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
|
4
4
|
import pytest
|
|
5
5
|
from haystack import default_from_dict
|
|
6
6
|
from haystack.dataclasses.sparse_embedding import SparseEmbedding
|
|
7
|
+
|
|
7
8
|
from haystack_integrations.components.embedders.fastembed.fastembed_sparse_text_embedder import (
|
|
8
9
|
FastembedSparseTextEmbedder,
|
|
9
10
|
)
|
|
@@ -53,6 +54,7 @@ class TestFastembedSparseTextEmbedder:
|
|
|
53
54
|
"progress_bar": True,
|
|
54
55
|
"parallel": None,
|
|
55
56
|
"local_files_only": False,
|
|
57
|
+
"model_kwargs": None,
|
|
56
58
|
},
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -78,6 +80,7 @@ class TestFastembedSparseTextEmbedder:
|
|
|
78
80
|
"progress_bar": False,
|
|
79
81
|
"parallel": 1,
|
|
80
82
|
"local_files_only": True,
|
|
83
|
+
"model_kwargs": None,
|
|
81
84
|
},
|
|
82
85
|
}
|
|
83
86
|
|
|
@@ -134,7 +137,11 @@ class TestFastembedSparseTextEmbedder:
|
|
|
134
137
|
mocked_factory.get_embedding_backend.assert_not_called()
|
|
135
138
|
embedder.warm_up()
|
|
136
139
|
mocked_factory.get_embedding_backend.assert_called_once_with(
|
|
137
|
-
model_name="prithvida/Splade_PP_en_v1",
|
|
140
|
+
model_name="prithvida/Splade_PP_en_v1",
|
|
141
|
+
cache_dir=None,
|
|
142
|
+
threads=None,
|
|
143
|
+
local_files_only=False,
|
|
144
|
+
model_kwargs=None,
|
|
138
145
|
)
|
|
139
146
|
|
|
140
147
|
@patch(
|
|
@@ -194,6 +201,54 @@ class TestFastembedSparseTextEmbedder:
|
|
|
194
201
|
with pytest.raises(TypeError, match="FastembedSparseTextEmbedder expects a string as input"):
|
|
195
202
|
embedder.run(text=list_integers_input)
|
|
196
203
|
|
|
204
|
+
def test_init_with_model_kwargs_parameters(self):
|
|
205
|
+
"""
|
|
206
|
+
Test initialization of FastembedSparseTextEmbedder with model_kwargs parameters.
|
|
207
|
+
"""
|
|
208
|
+
bm25_config = {
|
|
209
|
+
"k": 1.2,
|
|
210
|
+
"b": 0.75,
|
|
211
|
+
"avg_len": 300.0,
|
|
212
|
+
"language": "english",
|
|
213
|
+
"token_max_length": 50,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
embedder = FastembedSparseTextEmbedder(
|
|
217
|
+
model="Qdrant/bm25",
|
|
218
|
+
model_kwargs=bm25_config,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
assert embedder.model_kwargs == bm25_config
|
|
222
|
+
|
|
223
|
+
@pytest.mark.integration
|
|
224
|
+
def test_run_with_model_kwargs(self):
|
|
225
|
+
"""
|
|
226
|
+
Integration test to check the embedding with model_kwargs parameters.
|
|
227
|
+
"""
|
|
228
|
+
bm25_config = {
|
|
229
|
+
"k": 1.2,
|
|
230
|
+
"b": 0.75,
|
|
231
|
+
"avg_len": 256.0,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
embedder = FastembedSparseTextEmbedder(
|
|
235
|
+
model="Qdrant/bm25",
|
|
236
|
+
model_kwargs=bm25_config,
|
|
237
|
+
)
|
|
238
|
+
embedder.warm_up()
|
|
239
|
+
|
|
240
|
+
text = "Example content using BM25"
|
|
241
|
+
|
|
242
|
+
result = embedder.run(text=text)
|
|
243
|
+
embedding = result["sparse_embedding"]
|
|
244
|
+
embedding_dict = embedding.to_dict()
|
|
245
|
+
|
|
246
|
+
assert isinstance(embedding, SparseEmbedding)
|
|
247
|
+
assert isinstance(embedding_dict["indices"], list)
|
|
248
|
+
assert isinstance(embedding_dict["values"], list)
|
|
249
|
+
assert isinstance(embedding_dict["indices"][0], int)
|
|
250
|
+
assert isinstance(embedding_dict["values"][0], float)
|
|
251
|
+
|
|
197
252
|
@pytest.mark.integration
|
|
198
253
|
def test_run(self):
|
|
199
254
|
embedder = FastembedSparseTextEmbedder(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|