weaviate-haystack 2.1.1__tar.gz → 2.1.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.
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/.gitignore +9 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/CHANGELOG.md +11 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/PKG-INFO +1 -1
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/pyproject.toml +7 -7
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/components/retrievers/weaviate/__init__.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/components/retrievers/weaviate/bm25_retriever.py +19 -4
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/components/retrievers/weaviate/embedding_retriever.py +20 -4
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/_filters.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/auth.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/conftest.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/test_auth.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/test_bm25_retriever.py +15 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/test_document_store.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/test_embedding_retriever.py +14 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/test_filters.py +4 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/LICENSE.txt +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/README.md +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/docker-compose.yml +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/pydoc/config.yml +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/__init__.py +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/document_store.py +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/__init__.py +0 -0
- {weaviate_haystack-2.1.1 → weaviate_haystack-2.1.2}/tests/test_files/robot1.jpg +0 -0
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [unreleased]
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Weaviate filter error (#811)
|
|
8
|
+
- Fix connection to Weaviate Cloud Service (#624)
|
|
9
|
+
|
|
10
|
+
### ⚙️ Miscellaneous Tasks
|
|
11
|
+
|
|
12
|
+
- Retry tests to reduce flakyness (#836)
|
|
13
|
+
|
|
3
14
|
## [integrations/weaviate-v2.1.0] - 2024-06-10
|
|
4
15
|
|
|
5
16
|
### 🚀 Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: weaviate-haystack
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: An integration of Weaviate vector database with Haystack
|
|
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/weaviate/README.md
|
|
@@ -63,7 +63,7 @@ detached = true
|
|
|
63
63
|
dependencies = ["black>=23.1.0", "mypy>=1.0.0", "ruff>=0.0.243"]
|
|
64
64
|
[tool.hatch.envs.lint.scripts]
|
|
65
65
|
typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}"
|
|
66
|
-
style = ["ruff {args:.}", "black --check --diff {args:.}"]
|
|
66
|
+
style = ["ruff check {args:.}", "black --check --diff {args:.}"]
|
|
67
67
|
fmt = ["black {args:.}", "ruff --fix {args:.}", "style"]
|
|
68
68
|
all = ["style", "typing"]
|
|
69
69
|
|
|
@@ -75,7 +75,7 @@ skip-string-normalization = true
|
|
|
75
75
|
[tool.ruff]
|
|
76
76
|
target-version = "py38"
|
|
77
77
|
line-length = 120
|
|
78
|
-
select = [
|
|
78
|
+
lint.select = [
|
|
79
79
|
"A",
|
|
80
80
|
"ARG",
|
|
81
81
|
"B",
|
|
@@ -102,7 +102,7 @@ select = [
|
|
|
102
102
|
"W",
|
|
103
103
|
"YTT",
|
|
104
104
|
]
|
|
105
|
-
ignore = [
|
|
105
|
+
lint.ignore = [
|
|
106
106
|
# Allow non-abstract empty methods in abstract base classes
|
|
107
107
|
"B027",
|
|
108
108
|
# Allow boolean positional values in function calls, like `dict.get(... True)`
|
|
@@ -118,18 +118,18 @@ ignore = [
|
|
|
118
118
|
"PLR0913",
|
|
119
119
|
"PLR0915",
|
|
120
120
|
]
|
|
121
|
-
unfixable = [
|
|
121
|
+
lint.unfixable = [
|
|
122
122
|
# Don't touch unused imports
|
|
123
123
|
"F401",
|
|
124
124
|
]
|
|
125
125
|
|
|
126
|
-
[tool.ruff.isort]
|
|
126
|
+
[tool.ruff.lint.isort]
|
|
127
127
|
known-first-party = ["src"]
|
|
128
128
|
|
|
129
|
-
[tool.ruff.flake8-tidy-imports]
|
|
129
|
+
[tool.ruff.lint.flake8-tidy-imports]
|
|
130
130
|
ban-relative-imports = "parents"
|
|
131
131
|
|
|
132
|
-
[tool.ruff.per-file-ignores]
|
|
132
|
+
[tool.ruff.lint.per-file-ignores]
|
|
133
133
|
# Tests can use magic values, assertions, and relative imports
|
|
134
134
|
"tests/**/*" = ["PLR2004", "S101", "TID252"]
|
|
135
135
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List, Optional, Union
|
|
2
6
|
|
|
3
7
|
from haystack import Document, component, default_from_dict, default_to_dict
|
|
8
|
+
from haystack.document_stores.types import FilterPolicy
|
|
9
|
+
from haystack.document_stores.types.filter_policy import apply_filter_policy
|
|
4
10
|
from haystack_integrations.document_stores.weaviate import WeaviateDocumentStore
|
|
5
11
|
|
|
6
12
|
|
|
@@ -26,6 +32,7 @@ class WeaviateBM25Retriever:
|
|
|
26
32
|
document_store: WeaviateDocumentStore,
|
|
27
33
|
filters: Optional[Dict[str, Any]] = None,
|
|
28
34
|
top_k: int = 10,
|
|
35
|
+
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
|
|
29
36
|
):
|
|
30
37
|
"""
|
|
31
38
|
Create a new instance of WeaviateBM25Retriever.
|
|
@@ -36,10 +43,14 @@ class WeaviateBM25Retriever:
|
|
|
36
43
|
Custom filters applied when running the retriever
|
|
37
44
|
:param top_k:
|
|
38
45
|
Maximum number of documents to return
|
|
46
|
+
:param filter_policy: Policy to determine how filters are applied.
|
|
39
47
|
"""
|
|
40
48
|
self._document_store = document_store
|
|
41
49
|
self._filters = filters or {}
|
|
42
50
|
self._top_k = top_k
|
|
51
|
+
self._filter_policy = (
|
|
52
|
+
filter_policy if isinstance(filter_policy, FilterPolicy) else FilterPolicy.from_str(filter_policy)
|
|
53
|
+
)
|
|
43
54
|
|
|
44
55
|
def to_dict(self) -> Dict[str, Any]:
|
|
45
56
|
"""
|
|
@@ -52,6 +63,7 @@ class WeaviateBM25Retriever:
|
|
|
52
63
|
self,
|
|
53
64
|
filters=self._filters,
|
|
54
65
|
top_k=self._top_k,
|
|
66
|
+
filter_policy=self._filter_policy.value,
|
|
55
67
|
document_store=self._document_store.to_dict(),
|
|
56
68
|
)
|
|
57
69
|
|
|
@@ -68,6 +80,7 @@ class WeaviateBM25Retriever:
|
|
|
68
80
|
data["init_parameters"]["document_store"] = WeaviateDocumentStore.from_dict(
|
|
69
81
|
data["init_parameters"]["document_store"]
|
|
70
82
|
)
|
|
83
|
+
data["init_parameters"]["filter_policy"] = FilterPolicy.from_str(data["init_parameters"]["filter_policy"])
|
|
71
84
|
return default_from_dict(cls, data)
|
|
72
85
|
|
|
73
86
|
@component.output_types(documents=List[Document])
|
|
@@ -77,12 +90,14 @@ class WeaviateBM25Retriever:
|
|
|
77
90
|
|
|
78
91
|
:param query:
|
|
79
92
|
The query text.
|
|
80
|
-
:param filters:
|
|
81
|
-
|
|
93
|
+
:param filters: Filters applied to the retrieved Documents. The way runtime filters are applied depends on
|
|
94
|
+
the `filter_policy` chosen at retriever initialization. See init method docstring for more
|
|
95
|
+
details.
|
|
82
96
|
:param top_k:
|
|
83
97
|
The maximum number of documents to return.
|
|
84
98
|
"""
|
|
85
|
-
filters =
|
|
99
|
+
filters = apply_filter_policy(self._filter_policy, self._filters, filters)
|
|
100
|
+
|
|
86
101
|
top_k = top_k or self._top_k
|
|
87
102
|
documents = self._document_store._bm25_retrieval(query=query, filters=filters, top_k=top_k)
|
|
88
103
|
return {"documents": documents}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List, Optional, Union
|
|
2
6
|
|
|
3
7
|
from haystack import Document, component, default_from_dict, default_to_dict
|
|
8
|
+
from haystack.document_stores.types import FilterPolicy
|
|
9
|
+
from haystack.document_stores.types.filter_policy import apply_filter_policy
|
|
4
10
|
from haystack_integrations.document_stores.weaviate import WeaviateDocumentStore
|
|
5
11
|
|
|
6
12
|
|
|
@@ -18,6 +24,7 @@ class WeaviateEmbeddingRetriever:
|
|
|
18
24
|
top_k: int = 10,
|
|
19
25
|
distance: Optional[float] = None,
|
|
20
26
|
certainty: Optional[float] = None,
|
|
27
|
+
filter_policy: Union[str, FilterPolicy] = FilterPolicy.REPLACE,
|
|
21
28
|
):
|
|
22
29
|
"""
|
|
23
30
|
Creates a new instance of WeaviateEmbeddingRetriever.
|
|
@@ -32,6 +39,8 @@ class WeaviateEmbeddingRetriever:
|
|
|
32
39
|
The maximum allowed distance between Documents' embeddings.
|
|
33
40
|
:param certainty:
|
|
34
41
|
Normalized distance between the result item and the search vector.
|
|
42
|
+
:param filter_policy:
|
|
43
|
+
Policy to determine how filters are applied.
|
|
35
44
|
:raises ValueError:
|
|
36
45
|
If both `distance` and `certainty` are provided.
|
|
37
46
|
See https://weaviate.io/developers/weaviate/api/graphql/search-operators#variables to learn more about
|
|
@@ -46,6 +55,9 @@ class WeaviateEmbeddingRetriever:
|
|
|
46
55
|
self._top_k = top_k
|
|
47
56
|
self._distance = distance
|
|
48
57
|
self._certainty = certainty
|
|
58
|
+
self._filter_policy = (
|
|
59
|
+
filter_policy if isinstance(filter_policy, FilterPolicy) else FilterPolicy.from_str(filter_policy)
|
|
60
|
+
)
|
|
49
61
|
|
|
50
62
|
def to_dict(self) -> Dict[str, Any]:
|
|
51
63
|
"""
|
|
@@ -60,6 +72,7 @@ class WeaviateEmbeddingRetriever:
|
|
|
60
72
|
top_k=self._top_k,
|
|
61
73
|
distance=self._distance,
|
|
62
74
|
certainty=self._certainty,
|
|
75
|
+
filter_policy=self._filter_policy.value,
|
|
63
76
|
document_store=self._document_store.to_dict(),
|
|
64
77
|
)
|
|
65
78
|
|
|
@@ -76,6 +89,8 @@ class WeaviateEmbeddingRetriever:
|
|
|
76
89
|
data["init_parameters"]["document_store"] = WeaviateDocumentStore.from_dict(
|
|
77
90
|
data["init_parameters"]["document_store"]
|
|
78
91
|
)
|
|
92
|
+
|
|
93
|
+
data["init_parameters"]["filter_policy"] = FilterPolicy.from_str(data["init_parameters"]["filter_policy"])
|
|
79
94
|
return default_from_dict(cls, data)
|
|
80
95
|
|
|
81
96
|
@component.output_types(documents=List[Document])
|
|
@@ -92,8 +107,9 @@ class WeaviateEmbeddingRetriever:
|
|
|
92
107
|
|
|
93
108
|
:param query_embedding:
|
|
94
109
|
Embedding of the query.
|
|
95
|
-
:param filters:
|
|
96
|
-
|
|
110
|
+
:param filters: Filters applied to the retrieved Documents. The way runtime filters are applied depends on
|
|
111
|
+
the `filter_policy` chosen at retriever initialization. See init method docstring for more
|
|
112
|
+
details.
|
|
97
113
|
:param top_k:
|
|
98
114
|
The maximum number of documents to return.
|
|
99
115
|
:param distance:
|
|
@@ -105,7 +121,7 @@ class WeaviateEmbeddingRetriever:
|
|
|
105
121
|
See https://weaviate.io/developers/weaviate/api/graphql/search-operators#variables to learn more about
|
|
106
122
|
`distance` and `certainty` parameters.
|
|
107
123
|
"""
|
|
108
|
-
filters =
|
|
124
|
+
filters = apply_filter_policy(self._filter_policy, self._filters, filters)
|
|
109
125
|
top_k = top_k or self._top_k
|
|
110
126
|
|
|
111
127
|
distance = distance or self._distance
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
1
5
|
from unittest.mock import Mock, patch
|
|
2
6
|
|
|
7
|
+
import pytest
|
|
8
|
+
from haystack.document_stores.types import FilterPolicy
|
|
3
9
|
from haystack_integrations.components.retrievers.weaviate import WeaviateBM25Retriever
|
|
4
10
|
from haystack_integrations.document_stores.weaviate import WeaviateDocumentStore
|
|
5
11
|
|
|
@@ -10,6 +16,13 @@ def test_init_default():
|
|
|
10
16
|
assert retriever._document_store == mock_document_store
|
|
11
17
|
assert retriever._filters == {}
|
|
12
18
|
assert retriever._top_k == 10
|
|
19
|
+
assert retriever._filter_policy == FilterPolicy.REPLACE
|
|
20
|
+
|
|
21
|
+
retriever = WeaviateBM25Retriever(document_store=mock_document_store, filter_policy="replace")
|
|
22
|
+
assert retriever._filter_policy == FilterPolicy.REPLACE
|
|
23
|
+
|
|
24
|
+
with pytest.raises(ValueError):
|
|
25
|
+
WeaviateBM25Retriever(document_store=mock_document_store, filter_policy="keep_all")
|
|
13
26
|
|
|
14
27
|
|
|
15
28
|
@patch("haystack_integrations.document_stores.weaviate.document_store.weaviate")
|
|
@@ -21,6 +34,7 @@ def test_to_dict(_mock_weaviate):
|
|
|
21
34
|
"init_parameters": {
|
|
22
35
|
"filters": {},
|
|
23
36
|
"top_k": 10,
|
|
37
|
+
"filter_policy": "replace",
|
|
24
38
|
"document_store": {
|
|
25
39
|
"type": "haystack_integrations.document_stores.weaviate.document_store.WeaviateDocumentStore",
|
|
26
40
|
"init_parameters": {
|
|
@@ -55,6 +69,7 @@ def test_from_dict(_mock_weaviate):
|
|
|
55
69
|
"init_parameters": {
|
|
56
70
|
"filters": {},
|
|
57
71
|
"top_k": 10,
|
|
72
|
+
"filter_policy": "replace",
|
|
58
73
|
"document_store": {
|
|
59
74
|
"type": "haystack_integrations.document_stores.weaviate.document_store.WeaviateDocumentStore",
|
|
60
75
|
"init_parameters": {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
1
5
|
from unittest.mock import Mock, patch
|
|
2
6
|
|
|
3
7
|
import pytest
|
|
8
|
+
from haystack.document_stores.types import FilterPolicy
|
|
4
9
|
from haystack_integrations.components.retrievers.weaviate import WeaviateEmbeddingRetriever
|
|
5
10
|
from haystack_integrations.document_stores.weaviate import WeaviateDocumentStore
|
|
6
11
|
|
|
@@ -11,9 +16,16 @@ def test_init_default():
|
|
|
11
16
|
assert retriever._document_store == mock_document_store
|
|
12
17
|
assert retriever._filters == {}
|
|
13
18
|
assert retriever._top_k == 10
|
|
19
|
+
assert retriever._filter_policy == FilterPolicy.REPLACE
|
|
14
20
|
assert retriever._distance is None
|
|
15
21
|
assert retriever._certainty is None
|
|
16
22
|
|
|
23
|
+
retriever = WeaviateEmbeddingRetriever(document_store=mock_document_store, filter_policy="replace")
|
|
24
|
+
assert retriever._filter_policy == FilterPolicy.REPLACE
|
|
25
|
+
|
|
26
|
+
with pytest.raises(ValueError):
|
|
27
|
+
WeaviateEmbeddingRetriever(document_store=mock_document_store, filter_policy="keep_all")
|
|
28
|
+
|
|
17
29
|
|
|
18
30
|
def test_init_with_distance_and_certainty():
|
|
19
31
|
mock_document_store = Mock(spec=WeaviateDocumentStore)
|
|
@@ -30,6 +42,7 @@ def test_to_dict(_mock_weaviate):
|
|
|
30
42
|
"init_parameters": {
|
|
31
43
|
"filters": {},
|
|
32
44
|
"top_k": 10,
|
|
45
|
+
"filter_policy": "replace",
|
|
33
46
|
"distance": None,
|
|
34
47
|
"certainty": None,
|
|
35
48
|
"document_store": {
|
|
@@ -66,6 +79,7 @@ def test_from_dict(_mock_weaviate):
|
|
|
66
79
|
"init_parameters": {
|
|
67
80
|
"filters": {},
|
|
68
81
|
"top_k": 10,
|
|
82
|
+
"filter_policy": "replace",
|
|
69
83
|
"distance": None,
|
|
70
84
|
"certainty": None,
|
|
71
85
|
"document_store": {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|