weaviate-haystack 2.1.0__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.
Files changed (23) hide show
  1. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/.gitignore +9 -0
  2. weaviate_haystack-2.1.2/CHANGELOG.md +62 -0
  3. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/PKG-INFO +1 -1
  4. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/pyproject.toml +12 -16
  5. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/components/retrievers/weaviate/__init__.py +4 -0
  6. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/components/retrievers/weaviate/bm25_retriever.py +19 -4
  7. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/components/retrievers/weaviate/embedding_retriever.py +20 -4
  8. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/_filters.py +4 -0
  9. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/auth.py +4 -0
  10. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/document_store.py +31 -16
  11. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/conftest.py +4 -0
  12. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/test_auth.py +4 -0
  13. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/test_bm25_retriever.py +15 -0
  14. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/test_document_store.py +36 -2
  15. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/test_embedding_retriever.py +14 -0
  16. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/test_filters.py +4 -0
  17. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/LICENSE.txt +0 -0
  18. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/README.md +0 -0
  19. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/docker-compose.yml +0 -0
  20. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/pydoc/config.yml +0 -0
  21. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/src/haystack_integrations/document_stores/weaviate/__init__.py +0 -0
  22. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/__init__.py +0 -0
  23. {weaviate_haystack-2.1.0 → weaviate_haystack-2.1.2}/tests/test_files/robot1.jpg +0 -0
@@ -135,3 +135,12 @@ dmypy.json
135
135
  # Docs generation artifacts
136
136
  _readme_*.md
137
137
  .idea
138
+
139
+ # macOS
140
+ .DS_Store
141
+
142
+ # http cache (requests-cache)
143
+ **/http_cache.sqlite
144
+
145
+ # ruff
146
+ .ruff_cache
@@ -0,0 +1,62 @@
1
+ # Changelog
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
+
14
+ ## [integrations/weaviate-v2.1.0] - 2024-06-10
15
+
16
+ ### 🚀 Features
17
+
18
+ - Defer the database connection to when it's needed (#802)
19
+
20
+ ### 🐛 Bug Fixes
21
+
22
+ - Weaviate schema class name conversion which preserves PascalCase (#707)
23
+
24
+ ## [integrations/weaviate-v2.0.0] - 2024-03-25
25
+
26
+ ### 📚 Documentation
27
+
28
+ - Disable-class-def (#556)
29
+ - Fix docstrings (#586)
30
+
31
+ ### Weaviate
32
+
33
+ - Migrate from weaviate python client v3 to v4 (#463)
34
+
35
+ ## [integrations/weaviate-v1.0.2] - 2024-02-27
36
+
37
+ ### 🐛 Bug Fixes
38
+
39
+ - Fix order of API docs (#447)
40
+
41
+ This PR will also push the docs to Readme
42
+ - Fix weaviate auth tests (#488)
43
+
44
+
45
+
46
+ ### 📚 Documentation
47
+
48
+ - Update category slug (#442)
49
+
50
+ ### Weaviate
51
+
52
+ - Make retrievers return dicts (#491)
53
+
54
+ ## [integrations/weaviate-v1.0.0] - 2024-02-15
55
+
56
+ ### 🚀 Features
57
+
58
+ - Generate weaviate API docs (#351)
59
+
60
+ ## [integrations/weaviate-v0.0.0] - 2024-01-10
61
+
62
+ <!-- generated by git-cliff -->
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: weaviate-haystack
3
- Version: 2.1.0
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
@@ -47,10 +47,10 @@ root = "../.."
47
47
  git_describe_command = 'git describe --tags --match="integrations/weaviate-v[0-9]*"'
48
48
 
49
49
  [tool.hatch.envs.default]
50
- dependencies = ["coverage[toml]>=6.5", "pytest", "ipython"]
50
+ dependencies = ["coverage[toml]>=6.5", "pytest", "pytest-rerunfailures", "ipython"]
51
51
  [tool.hatch.envs.default.scripts]
52
- test = "pytest {args:tests}"
53
- test-cov = "coverage run -m pytest {args:tests}"
52
+ test = "pytest --reruns 3 --reruns-delay 30 -x {args:tests}"
53
+ test-cov = "coverage run -m pytest --reruns 3 --reruns-delay 30 -x {args:tests}"
54
54
  cov-report = ["- coverage combine", "coverage report"]
55
55
  cov = ["test-cov", "cov-report"]
56
56
  docs = ["pydoc-markdown pydoc/config.yml"]
@@ -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
 
@@ -141,12 +141,8 @@ parallel = false
141
141
 
142
142
  [tool.coverage.report]
143
143
  omit = ["*/tests/*", "*/__init__.py"]
144
- show_missing=true
145
- exclude_lines = [
146
- "no cov",
147
- "if __name__ == .__main__.:",
148
- "if TYPE_CHECKING:",
149
- ]
144
+ show_missing = true
145
+ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
150
146
 
151
147
 
152
148
  [[tool.mypy.overrides]]
@@ -1,3 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  from .bm25_retriever import WeaviateBM25Retriever
2
6
  from .embedding_retriever import WeaviateEmbeddingRetriever
3
7
 
@@ -1,6 +1,12 @@
1
- from typing import Any, Dict, List, Optional
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
- Filters to use when running the retriever.
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 = filters or self._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
- from typing import Any, Dict, List, Optional
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
- Filters to use when running the retriever.
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 = filters or self._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,3 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  from typing import Any, Dict
2
6
 
3
7
  from dateutil import parser
@@ -1,3 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  from abc import ABC, abstractmethod
2
6
  from dataclasses import dataclass, field, fields
3
7
  from enum import Enum
@@ -12,6 +12,7 @@ from haystack.core.serialization import default_from_dict, default_to_dict
12
12
  from haystack.dataclasses.document import Document
13
13
  from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError
14
14
  from haystack.document_stores.types.policy import DuplicatePolicy
15
+ from haystack.utils.filters import convert
15
16
 
16
17
  import weaviate
17
18
  from weaviate.collections.classes.data import DataObject
@@ -171,22 +172,33 @@ class WeaviateDocumentStore:
171
172
  if self._client:
172
173
  return self._client
173
174
 
174
- # proxies, timeout_config, trust_env are part of additional_config now
175
- # startup_period has been removed
176
- self._client = weaviate.WeaviateClient(
177
- connection_params=(
178
- weaviate.connect.base.ConnectionParams.from_url(
179
- url=self._url, grpc_port=self._grpc_port, grpc_secure=self._grpc_secure
180
- )
181
- if self._url
182
- else None
183
- ),
184
- auth_client_secret=self._auth_client_secret.resolve_value() if self._auth_client_secret else None,
185
- additional_config=self._additional_config,
186
- additional_headers=self._additional_headers,
187
- embedded_options=self._embedded_options,
188
- skip_init_checks=False,
189
- )
175
+ if self._url and self._url.startswith("http") and self._url.endswith(".weaviate.network"):
176
+ # We use this utility function instead of using WeaviateClient directly like in other cases
177
+ # otherwise we'd have to parse the URL to get some information about the connection.
178
+ # This utility function does all that for us.
179
+ self._client = weaviate.connect_to_wcs(
180
+ self._url,
181
+ auth_credentials=self._auth_client_secret.resolve_value() if self._auth_client_secret else None,
182
+ headers=self._additional_headers,
183
+ additional_config=self._additional_config,
184
+ )
185
+ else:
186
+ # proxies, timeout_config, trust_env are part of additional_config now
187
+ # startup_period has been removed
188
+ self._client = weaviate.WeaviateClient(
189
+ connection_params=(
190
+ weaviate.connect.base.ConnectionParams.from_url(
191
+ url=self._url, grpc_port=self._grpc_port, grpc_secure=self._grpc_secure
192
+ )
193
+ if self._url
194
+ else None
195
+ ),
196
+ auth_client_secret=self._auth_client_secret.resolve_value() if self._auth_client_secret else None,
197
+ additional_config=self._additional_config,
198
+ additional_headers=self._additional_headers,
199
+ embedded_options=self._embedded_options,
200
+ skip_init_checks=False,
201
+ )
190
202
 
191
203
  self._client.connect()
192
204
 
@@ -374,6 +386,9 @@ class WeaviateDocumentStore:
374
386
  :param filters: The filters to apply to the document list.
375
387
  :returns: A list of Documents that match the given filters.
376
388
  """
389
+ if filters and "operator" not in filters and "conditions" not in filters:
390
+ filters = convert(filters)
391
+
377
392
  result = []
378
393
  if filters:
379
394
  result = self._query_with_filters(filters)
@@ -1,3 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  from pathlib import Path
2
6
 
3
7
  import pytest
@@ -1,3 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  from haystack_integrations.document_stores.weaviate.auth import (
2
6
  AuthApiKey,
3
7
  AuthBearerToken,
@@ -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,4 +1,9 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  import base64
6
+ import os
2
7
  import random
3
8
  from typing import List
4
9
  from unittest.mock import MagicMock, patch
@@ -16,6 +21,7 @@ from haystack.testing.document_store import (
16
21
  FilterDocumentsTest,
17
22
  WriteDocumentsTest,
18
23
  )
24
+ from haystack.utils.auth import Secret
19
25
  from haystack_integrations.document_stores.weaviate.auth import AuthApiKey
20
26
  from haystack_integrations.document_stores.weaviate.document_store import (
21
27
  DOCUMENT_COLLECTION_PROPERTIES,
@@ -26,8 +32,6 @@ from numpy import array_equal as np_array_equal
26
32
  from numpy import float32 as np_float32
27
33
  from pandas import DataFrame
28
34
  from weaviate.collections.classes.data import DataObject
29
-
30
- # from weaviate.auth import AuthApiKey as WeaviateAuthApiKey
31
35
  from weaviate.config import AdditionalConfig, ConnectionConfig, Proxies, Timeout
32
36
  from weaviate.embedded import (
33
37
  DEFAULT_BINARY_PATH,
@@ -655,6 +659,15 @@ class TestWeaviateDocumentStore(CountDocumentsTest, WriteDocumentsTest, DeleteDo
655
659
  with pytest.raises(ValueError):
656
660
  document_store._embedding_retrieval(query_embedding=[], distance=0.1, certainty=0.1)
657
661
 
662
+ def test_filter_documents_with_legacy_filters(self, document_store):
663
+ docs = []
664
+ for index in range(10):
665
+ docs.append(Document(content="This is some content", meta={"index": index}))
666
+ document_store.write_documents(docs)
667
+ result = document_store.filter_documents({"content": {"$eq": "This is some content"}})
668
+
669
+ assert len(result) == 10
670
+
658
671
  def test_filter_documents_below_default_limit(self, document_store):
659
672
  docs = []
660
673
  for index in range(9998):
@@ -688,3 +701,24 @@ class TestWeaviateDocumentStore(CountDocumentsTest, WriteDocumentsTest, DeleteDo
688
701
  collection_settings=collection_settings,
689
702
  )
690
703
  assert doc_score._collection_settings["class"] == "Lower_case_name"
704
+
705
+ @pytest.mark.skipif(
706
+ not os.environ.get("WEAVIATE_API_KEY", None) and not os.environ.get("WEAVIATE_CLOUD_CLUSTER_URL", None),
707
+ reason="Both WEAVIATE_API_KEY and WEAVIATE_CLOUD_CLUSTER_URL are not set. Skipping test.",
708
+ )
709
+ def test_connect_to_weaviate_cloud(self):
710
+ document_store = WeaviateDocumentStore(
711
+ url=os.environ.get("WEAVIATE_CLOUD_CLUSTER_URL"),
712
+ auth_client_secret=AuthApiKey(api_key=Secret.from_env_var("WEAVIATE_API_KEY")),
713
+ )
714
+ assert document_store.client
715
+
716
+ def test_connect_to_local(self):
717
+ document_store = WeaviateDocumentStore(
718
+ url="http://localhost:8080",
719
+ )
720
+ assert document_store.client
721
+
722
+ def test_connect_to_embedded(self):
723
+ document_store = WeaviateDocumentStore(embedded_options=EmbeddedOptions())
724
+ assert document_store.client
@@ -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": {
@@ -1,3 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
1
5
  from haystack_integrations.document_stores.weaviate._filters import _invert_condition
2
6
 
3
7