opensearch-haystack 8.1.2__tar.gz → 8.2.1__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.
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/CHANGELOG.md +26 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/PKG-INFO +1 -1
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/pyproject.toml +1 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/bm25_retriever.py +12 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/embedding_retriever.py +12 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/metadata_retriever.py +12 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/open_search_hybrid_retriever.py +15 -2
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/sql_retriever.py +12 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/document_stores/opensearch/document_store.py +68 -25
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/document_stores/opensearch/filters.py +5 -2
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_bm25_retriever.py +23 -1
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_document_store.py +111 -65
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_document_store_async.py +150 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_embedding_retriever.py +23 -1
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_filters.py +53 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_metadata_retriever.py +23 -1
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_open_search_hybrid_retriever.py +102 -92
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_sql_retriever.py +22 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/.gitignore +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/LICENSE +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/README.md +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/docker-compose.yml +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/pydoc/config_docusaurus.yml +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/__init__.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/opensearch/utils.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/components/retrievers/py.typed +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/document_stores/opensearch/__init__.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/document_stores/opensearch/auth.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/document_stores/opensearch/opensearch_scripts.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/src/haystack_integrations/document_stores/py.typed +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/__init__.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/conftest.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_auth.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_document_store_common.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_metadata_retriever_async.py +0 -0
- {opensearch_haystack-8.1.2 → opensearch_haystack-8.2.1}/tests/test_utils.py +0 -0
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [integrations/opensearch-v8.2.0] - 2026-07-22
|
|
4
|
+
|
|
5
|
+
### 🚀 Features
|
|
6
|
+
|
|
7
|
+
- Opensearch - add methods to close resources (#3640)
|
|
8
|
+
|
|
9
|
+
### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- Adapt optimum, ragas, elasticsearch, opensearch to APIs removed in Haystack 3.0 (#3538)
|
|
12
|
+
|
|
13
|
+
### 🚜 Refactor
|
|
14
|
+
|
|
15
|
+
- Elasticsearch - split sync/async paths (#3633)
|
|
16
|
+
|
|
17
|
+
### 📚 Documentation
|
|
18
|
+
|
|
19
|
+
- Replace old haystack core imports with haystack_integrations paths (#3545)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [integrations/opensearch-v8.1.2] - 2026-06-24
|
|
23
|
+
|
|
24
|
+
### 🐛 Bug Fixes
|
|
25
|
+
|
|
26
|
+
- Serialize OpenSearchBM25Retriever all_terms_must_match (#3454)
|
|
27
|
+
|
|
28
|
+
|
|
3
29
|
## [integrations/opensearch-v8.1.1] - 2026-05-20
|
|
4
30
|
|
|
5
31
|
### 🐛 Bug Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opensearch-haystack
|
|
3
|
-
Version: 8.1
|
|
3
|
+
Version: 8.2.1
|
|
4
4
|
Summary: Haystack 2.x Document Store for OpenSearch
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/opensearch#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -157,6 +157,18 @@ class OpenSearchBM25Retriever:
|
|
|
157
157
|
data["init_parameters"]["filter_policy"] = FilterPolicy.from_str(data["init_parameters"]["filter_policy"])
|
|
158
158
|
return default_from_dict(cls, data)
|
|
159
159
|
|
|
160
|
+
def close(self) -> None:
|
|
161
|
+
"""
|
|
162
|
+
Release the synchronous resources of the underlying Document Store.
|
|
163
|
+
"""
|
|
164
|
+
self._document_store.close()
|
|
165
|
+
|
|
166
|
+
async def close_async(self) -> None:
|
|
167
|
+
"""
|
|
168
|
+
Release the asynchronous resources of the underlying Document Store.
|
|
169
|
+
"""
|
|
170
|
+
await self._document_store.close_async()
|
|
171
|
+
|
|
160
172
|
def _prepare_bm25_args(
|
|
161
173
|
self,
|
|
162
174
|
*,
|
|
@@ -163,6 +163,18 @@ class OpenSearchEmbeddingRetriever:
|
|
|
163
163
|
data["init_parameters"]["filter_policy"] = FilterPolicy.from_str(data["init_parameters"]["filter_policy"])
|
|
164
164
|
return default_from_dict(cls, data)
|
|
165
165
|
|
|
166
|
+
def close(self) -> None:
|
|
167
|
+
"""
|
|
168
|
+
Release the synchronous resources of the underlying Document Store.
|
|
169
|
+
"""
|
|
170
|
+
self._document_store.close()
|
|
171
|
+
|
|
172
|
+
async def close_async(self) -> None:
|
|
173
|
+
"""
|
|
174
|
+
Release the asynchronous resources of the underlying Document Store.
|
|
175
|
+
"""
|
|
176
|
+
await self._document_store.close_async()
|
|
177
|
+
|
|
166
178
|
@component.output_types(documents=list[Document])
|
|
167
179
|
def run(
|
|
168
180
|
self,
|
|
@@ -181,6 +181,18 @@ class OpenSearchMetadataRetriever:
|
|
|
181
181
|
)
|
|
182
182
|
return default_from_dict(cls, data)
|
|
183
183
|
|
|
184
|
+
def close(self) -> None:
|
|
185
|
+
"""
|
|
186
|
+
Release the synchronous resources of the underlying Document Store.
|
|
187
|
+
"""
|
|
188
|
+
self._document_store.close()
|
|
189
|
+
|
|
190
|
+
async def close_async(self) -> None:
|
|
191
|
+
"""
|
|
192
|
+
Release the asynchronous resources of the underlying Document Store.
|
|
193
|
+
"""
|
|
194
|
+
await self._document_store.close_async()
|
|
195
|
+
|
|
184
196
|
@component.output_types(metadata=list[dict[str, Any]])
|
|
185
197
|
def run(
|
|
186
198
|
self,
|
|
@@ -37,7 +37,9 @@ class OpenSearchHybridRetriever:
|
|
|
37
37
|
|
|
38
38
|
```python
|
|
39
39
|
from haystack import Document
|
|
40
|
-
|
|
40
|
+
# Requires: pip install sentence-transformers-haystack
|
|
41
|
+
from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersTextEmbedder
|
|
42
|
+
from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersDocumentEmbedder
|
|
41
43
|
from haystack_integrations.components.retrievers.opensearch import OpenSearchHybridRetriever
|
|
42
44
|
from haystack_integrations.document_stores.opensearch import OpenSearchDocumentStore
|
|
43
45
|
|
|
@@ -59,7 +61,6 @@ class OpenSearchHybridRetriever:
|
|
|
59
61
|
|
|
60
62
|
# Embed the documents and add them to the document store
|
|
61
63
|
doc_embedder = SentenceTransformersDocumentEmbedder(model="sentence-transformers/all-MiniLM-L6-v2")
|
|
62
|
-
doc_embedder.warm_up()
|
|
63
64
|
docs = doc_embedder.run(docs)
|
|
64
65
|
doc_store.write_documents(docs['documents'])
|
|
65
66
|
|
|
@@ -356,3 +357,15 @@ class OpenSearchHybridRetriever:
|
|
|
356
357
|
data["init_parameters"]["join_mode"] = join_mode
|
|
357
358
|
|
|
358
359
|
return default_from_dict(cls, data)
|
|
360
|
+
|
|
361
|
+
def close(self) -> None:
|
|
362
|
+
"""
|
|
363
|
+
Release the synchronous resources of the underlying Document Store.
|
|
364
|
+
"""
|
|
365
|
+
self.document_store.close()
|
|
366
|
+
|
|
367
|
+
async def close_async(self) -> None:
|
|
368
|
+
"""
|
|
369
|
+
Release the asynchronous resources of the underlying Document Store.
|
|
370
|
+
"""
|
|
371
|
+
await self.document_store.close_async()
|
|
@@ -80,6 +80,18 @@ class OpenSearchSQLRetriever:
|
|
|
80
80
|
)
|
|
81
81
|
return default_from_dict(cls, data)
|
|
82
82
|
|
|
83
|
+
def close(self) -> None:
|
|
84
|
+
"""
|
|
85
|
+
Release the synchronous resources of the underlying Document Store.
|
|
86
|
+
"""
|
|
87
|
+
self._document_store.close()
|
|
88
|
+
|
|
89
|
+
async def close_async(self) -> None:
|
|
90
|
+
"""
|
|
91
|
+
Release the asynchronous resources of the underlying Document Store.
|
|
92
|
+
"""
|
|
93
|
+
await self._document_store.close_async()
|
|
94
|
+
|
|
83
95
|
@component.output_types(result=dict[str, Any])
|
|
84
96
|
def run(
|
|
85
97
|
self,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# ruff: noqa: FBT001, FBT002 boolean-type-hint-positional-argument and boolean-default-value-positional-argument
|
|
6
6
|
|
|
7
7
|
from collections.abc import Generator, Mapping
|
|
8
|
+
from contextlib import suppress
|
|
8
9
|
from dataclasses import replace
|
|
9
10
|
from math import exp
|
|
10
11
|
from typing import Any, Literal
|
|
@@ -162,7 +163,6 @@ class OpenSearchDocumentStore:
|
|
|
162
163
|
# the document store is instantiated.
|
|
163
164
|
self._client: OpenSearch | None = None
|
|
164
165
|
self._async_client: AsyncOpenSearch | None = None
|
|
165
|
-
self._initialized = False
|
|
166
166
|
|
|
167
167
|
def _get_default_mappings(self) -> dict[str, Any]:
|
|
168
168
|
default_mappings: dict[str, Any] = {
|
|
@@ -303,8 +303,6 @@ class OpenSearchDocumentStore:
|
|
|
303
303
|
timeout=self._timeout,
|
|
304
304
|
**self._kwargs,
|
|
305
305
|
)
|
|
306
|
-
self._initialized = True
|
|
307
|
-
|
|
308
306
|
self._ensure_index_exists()
|
|
309
307
|
|
|
310
308
|
async def _ensure_initialized_async(self) -> None:
|
|
@@ -322,9 +320,26 @@ class OpenSearchDocumentStore:
|
|
|
322
320
|
connection_class=AsyncHttpConnection,
|
|
323
321
|
**self._kwargs,
|
|
324
322
|
)
|
|
325
|
-
self._initialized = True
|
|
326
323
|
await self._ensure_index_exists_async()
|
|
327
324
|
|
|
325
|
+
def close(self) -> None:
|
|
326
|
+
"""
|
|
327
|
+
Release the associated synchronous resources.
|
|
328
|
+
"""
|
|
329
|
+
if self._client is not None:
|
|
330
|
+
with suppress(Exception):
|
|
331
|
+
self._client.close()
|
|
332
|
+
self._client = None
|
|
333
|
+
|
|
334
|
+
async def close_async(self) -> None:
|
|
335
|
+
"""
|
|
336
|
+
Release the associated asynchronous resources.
|
|
337
|
+
"""
|
|
338
|
+
if self._async_client is not None:
|
|
339
|
+
with suppress(Exception):
|
|
340
|
+
await self._async_client.close()
|
|
341
|
+
self._async_client = None
|
|
342
|
+
|
|
328
343
|
@staticmethod
|
|
329
344
|
def _extract_nested_fields_from_mapping(mapping_properties: dict[str, Any]) -> set[str]:
|
|
330
345
|
return {name for name, defn in mapping_properties.items() if defn.get("type") == "nested"}
|
|
@@ -2038,16 +2053,19 @@ class OpenSearchDocumentStore:
|
|
|
2038
2053
|
self,
|
|
2039
2054
|
metadata_field: str,
|
|
2040
2055
|
search_term: str | None = None,
|
|
2041
|
-
size: int | None =
|
|
2056
|
+
size: int | None = 10,
|
|
2042
2057
|
after: dict[str, Any] | None = None,
|
|
2043
2058
|
) -> tuple[list[str], dict[str, Any] | None]:
|
|
2044
2059
|
"""
|
|
2045
|
-
Returns unique values for a metadata field, optionally filtered by a search term
|
|
2060
|
+
Returns unique values for a metadata field, optionally filtered by a search term.
|
|
2046
2061
|
|
|
2047
2062
|
Uses composite aggregations for proper pagination beyond 10k results.
|
|
2048
2063
|
|
|
2049
2064
|
:param metadata_field: The metadata field to get unique values for.
|
|
2050
|
-
:param search_term: Optional
|
|
2065
|
+
:param search_term: Optional term to filter the returned values by, matching as a case-insensitive substring
|
|
2066
|
+
of the metadata field's own value (not the document content). NOTE: The matching is done with a server-side
|
|
2067
|
+
script to accomplish the substring matching on the value of the field and this operation is quite expensive
|
|
2068
|
+
for a large corpus.
|
|
2051
2069
|
:param size: The number of unique values to return per page. Defaults to 10000.
|
|
2052
2070
|
:param after: Optional pagination key from the previous response. Use None for the first page.
|
|
2053
2071
|
For subsequent pages, pass the `after_key` from the previous response.
|
|
@@ -2060,12 +2078,6 @@ class OpenSearchDocumentStore:
|
|
|
2060
2078
|
|
|
2061
2079
|
field_name = _normalize_metadata_field_name(metadata_field)
|
|
2062
2080
|
|
|
2063
|
-
# filter by search_term if provided
|
|
2064
|
-
query: dict[str, Any] = {"match_all": {}}
|
|
2065
|
-
if search_term:
|
|
2066
|
-
# Use match_phrase for exact phrase matching to avoid tokenization issues
|
|
2067
|
-
query = {"match_phrase": {"content": search_term}}
|
|
2068
|
-
|
|
2069
2081
|
# Build composite aggregation for proper pagination
|
|
2070
2082
|
composite_agg: dict[str, Any] = {
|
|
2071
2083
|
"size": size,
|
|
@@ -2074,8 +2086,7 @@ class OpenSearchDocumentStore:
|
|
|
2074
2086
|
if after is not None:
|
|
2075
2087
|
composite_agg["after"] = after
|
|
2076
2088
|
|
|
2077
|
-
body = {
|
|
2078
|
-
"query": query,
|
|
2089
|
+
body: dict[str, Any] = {
|
|
2079
2090
|
"aggs": {
|
|
2080
2091
|
"unique_values": {
|
|
2081
2092
|
"composite": composite_agg,
|
|
@@ -2083,6 +2094,24 @@ class OpenSearchDocumentStore:
|
|
|
2083
2094
|
},
|
|
2084
2095
|
"size": 0, # we only need aggregations, not documents
|
|
2085
2096
|
}
|
|
2097
|
+
if search_term:
|
|
2098
|
+
# Composite aggregation terms sources don't support `include`/`exclude` (that's only valid on
|
|
2099
|
+
# standalone `terms` aggregations), and a `regexp` query only works on keyword/text fields, not
|
|
2100
|
+
# numeric ones. A doc-value script query works uniformly across field types by stringifying the
|
|
2101
|
+
# field's value, matching the case-insensitive substring semantics documented above. The term is
|
|
2102
|
+
# lower-cased once here rather than per-document in the script.
|
|
2103
|
+
body["query"] = {
|
|
2104
|
+
"script": {
|
|
2105
|
+
"script": {
|
|
2106
|
+
"source": (
|
|
2107
|
+
"def v = doc[params.field]; "
|
|
2108
|
+
"if (v.size() == 0) { return false; } "
|
|
2109
|
+
"return v.value.toString().toLowerCase().contains(params.term)"
|
|
2110
|
+
),
|
|
2111
|
+
"params": {"field": field_name, "term": search_term.lower()},
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2086
2115
|
|
|
2087
2116
|
result = self._client.search(index=self._index, body=body)
|
|
2088
2117
|
aggregations = result.get("aggregations", {})
|
|
@@ -2108,12 +2137,15 @@ class OpenSearchDocumentStore:
|
|
|
2108
2137
|
after: dict[str, Any] | None = None,
|
|
2109
2138
|
) -> tuple[list[str], dict[str, Any] | None]:
|
|
2110
2139
|
"""
|
|
2111
|
-
Asynchronously returns unique values for a metadata field, optionally filtered by a search term
|
|
2140
|
+
Asynchronously returns unique values for a metadata field, optionally filtered by a search term.
|
|
2112
2141
|
|
|
2113
2142
|
Uses composite aggregations for proper pagination beyond 10k results.
|
|
2114
2143
|
|
|
2115
2144
|
:param metadata_field: The metadata field to get unique values for.
|
|
2116
|
-
:param search_term: Optional
|
|
2145
|
+
:param search_term: Optional term to filter the returned values by, matching as a case-insensitive substring
|
|
2146
|
+
of the metadata field's own value (not the document content). NOTE: The matching is done with a server-side
|
|
2147
|
+
script to accomplish the substring matching on the value of the field and this operation is quite expensive
|
|
2148
|
+
for a large corpus.
|
|
2117
2149
|
:param size: The number of unique values to return per page. Defaults to 10000.
|
|
2118
2150
|
:param after: Optional pagination key from the previous response. Use None for the first page.
|
|
2119
2151
|
For subsequent pages, pass the `after_key` from the previous response.
|
|
@@ -2126,12 +2158,6 @@ class OpenSearchDocumentStore:
|
|
|
2126
2158
|
|
|
2127
2159
|
field_name = _normalize_metadata_field_name(metadata_field)
|
|
2128
2160
|
|
|
2129
|
-
# filter by search_term if provided
|
|
2130
|
-
query: dict[str, Any] = {"match_all": {}}
|
|
2131
|
-
if search_term:
|
|
2132
|
-
# Use match_phrase for exact phrase matching to avoid tokenization issues
|
|
2133
|
-
query = {"match_phrase": {"content": search_term}}
|
|
2134
|
-
|
|
2135
2161
|
# Build composite aggregation for proper pagination
|
|
2136
2162
|
composite_agg: dict[str, Any] = {
|
|
2137
2163
|
"size": size,
|
|
@@ -2140,8 +2166,7 @@ class OpenSearchDocumentStore:
|
|
|
2140
2166
|
if after is not None:
|
|
2141
2167
|
composite_agg["after"] = after
|
|
2142
2168
|
|
|
2143
|
-
body = {
|
|
2144
|
-
"query": query,
|
|
2169
|
+
body: dict[str, Any] = {
|
|
2145
2170
|
"aggs": {
|
|
2146
2171
|
"unique_values": {
|
|
2147
2172
|
"composite": composite_agg,
|
|
@@ -2149,6 +2174,24 @@ class OpenSearchDocumentStore:
|
|
|
2149
2174
|
},
|
|
2150
2175
|
"size": 0, # we only need aggregations, not documents
|
|
2151
2176
|
}
|
|
2177
|
+
if search_term:
|
|
2178
|
+
# Composite aggregation terms sources don't support `include`/`exclude` (that's only valid on
|
|
2179
|
+
# standalone `terms` aggregations), and a `regexp` query only works on keyword/text fields, not
|
|
2180
|
+
# numeric ones. A doc-value script query works uniformly across field types by stringifying the
|
|
2181
|
+
# field's value, matching the case-insensitive substring semantics documented above. The term is
|
|
2182
|
+
# lower-cased once here rather than per-document in the script.
|
|
2183
|
+
body["query"] = {
|
|
2184
|
+
"script": {
|
|
2185
|
+
"script": {
|
|
2186
|
+
"source": (
|
|
2187
|
+
"def v = doc[params.field]; "
|
|
2188
|
+
"if (v.size() == 0) { return false; } "
|
|
2189
|
+
"return v.value.toString().toLowerCase().contains(params.term)"
|
|
2190
|
+
),
|
|
2191
|
+
"params": {"field": field_name, "term": search_term.lower()},
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2152
2195
|
|
|
2153
2196
|
result = await self._async_client.search(index=self._index, body=body)
|
|
2154
2197
|
aggregations = result.get("aggregations", {})
|
|
@@ -93,7 +93,7 @@ def _group_nested_conditions(
|
|
|
93
93
|
inner.append(_parse_logical_condition(c, nested_fields=None))
|
|
94
94
|
else:
|
|
95
95
|
inner.append(_parse_comparison_condition(c, nested_fields))
|
|
96
|
-
if len(inner) > 1:
|
|
96
|
+
if len(inner) > 1 and operator != "OR":
|
|
97
97
|
inner = _normalize_ranges(inner)
|
|
98
98
|
if len(inner) == 1:
|
|
99
99
|
conditions.append({"nested": {"path": path, "query": inner[0]}})
|
|
@@ -120,7 +120,10 @@ def _parse_logical_condition(condition: dict[str, Any], nested_fields: set[str]
|
|
|
120
120
|
else:
|
|
121
121
|
conditions = [_parse_comparison_condition(c, nested_fields) for c in condition["conditions"]]
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
# Range merging is only valid when the conditions are AND-combined (AND, and the
|
|
124
|
+
# inner `must` of NOT). Merging same-field ranges under OR would collapse e.g.
|
|
125
|
+
# `price < 10 OR price > 100` into a single impossible range, matching nothing.
|
|
126
|
+
if len(conditions) > 1 and operator != "OR":
|
|
124
127
|
conditions = _normalize_ranges(conditions)
|
|
125
128
|
if operator == "AND":
|
|
126
129
|
return {"bool": {"must": conditions}}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from unittest.mock import Mock, patch
|
|
5
|
+
from unittest.mock import AsyncMock, Mock, patch
|
|
6
6
|
|
|
7
7
|
import pytest
|
|
8
8
|
from haystack.dataclasses import Document
|
|
@@ -159,6 +159,28 @@ def test_from_dict_not_defaults(_mock_opensearch_client):
|
|
|
159
159
|
assert retriever._raise_on_failure is True
|
|
160
160
|
|
|
161
161
|
|
|
162
|
+
def test_close():
|
|
163
|
+
mock_store = Mock(spec=OpenSearchDocumentStore)
|
|
164
|
+
retriever = OpenSearchBM25Retriever(document_store=mock_store)
|
|
165
|
+
|
|
166
|
+
retriever.close()
|
|
167
|
+
|
|
168
|
+
mock_store.close.assert_called_once_with()
|
|
169
|
+
assert retriever._document_store is mock_store
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@pytest.mark.asyncio
|
|
173
|
+
async def test_close_async():
|
|
174
|
+
mock_store = Mock(spec=OpenSearchDocumentStore)
|
|
175
|
+
mock_store.close_async = AsyncMock()
|
|
176
|
+
retriever = OpenSearchBM25Retriever(document_store=mock_store)
|
|
177
|
+
|
|
178
|
+
await retriever.close_async()
|
|
179
|
+
|
|
180
|
+
mock_store.close_async.assert_awaited_once_with()
|
|
181
|
+
assert retriever._document_store is mock_store
|
|
182
|
+
|
|
183
|
+
|
|
162
184
|
def test_run():
|
|
163
185
|
mock_store = Mock(spec=OpenSearchDocumentStore)
|
|
164
186
|
mock_store._bm25_retrieval.return_value = [Document(content="Test doc")]
|