opensearch-haystack 8.1.0__tar.gz → 8.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.
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/CHANGELOG.md +14 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/PKG-INFO +1 -1
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/bm25_retriever.py +1 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/document_stores/opensearch/document_store.py +32 -10
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_bm25_retriever.py +4 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_document_store.py +160 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_document_store_async.py +114 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/.gitignore +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/LICENSE +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/README.md +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/docker-compose.yml +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/pydoc/config_docusaurus.yml +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/pyproject.toml +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/__init__.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/embedding_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/metadata_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/open_search_hybrid_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/sql_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/opensearch/utils.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/components/retrievers/py.typed +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/document_stores/opensearch/__init__.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/document_stores/opensearch/auth.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/document_stores/opensearch/filters.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/document_stores/opensearch/opensearch_scripts.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/src/haystack_integrations/document_stores/py.typed +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/__init__.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/conftest.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_auth.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_document_store_common.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_embedding_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_filters.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_metadata_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_metadata_retriever_async.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_open_search_hybrid_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_sql_retriever.py +0 -0
- {opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_utils.py +0 -0
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [integrations/opensearch-v8.1.1] - 2026-05-20
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Support aliases in all OpenSearchDocumentStore methods (#3336)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [integrations/opensearch-v8.1.0] - 2026-05-20
|
|
11
|
+
|
|
12
|
+
### 🐛 Bug Fixes
|
|
13
|
+
|
|
14
|
+
- _ensure_index_exists for aliases in OpenSearch (#3335)
|
|
15
|
+
|
|
16
|
+
|
|
3
17
|
## [integrations/opensearch-v8.0.0] - 2026-04-29
|
|
4
18
|
|
|
5
19
|
### 🚀 Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opensearch-haystack
|
|
3
|
-
Version: 8.1.
|
|
3
|
+
Version: 8.1.2
|
|
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
|
|
@@ -774,6 +774,8 @@ class OpenSearchDocumentStore:
|
|
|
774
774
|
|
|
775
775
|
:param recreate_index: If True, the index will be deleted and recreated with the original mappings and
|
|
776
776
|
settings. If False, all documents will be deleted using the `delete_by_query` API.
|
|
777
|
+
``recreate_index=True`` is not supported when the configured index name is an alias; a
|
|
778
|
+
:class:`haystack.document_stores.errors.DocumentStoreError` is raised in that case.
|
|
777
779
|
:param refresh: If True, OpenSearch refreshes all shards involved in the delete by query after the request
|
|
778
780
|
completes. If False, no refresh is performed. For more details, see the
|
|
779
781
|
[OpenSearch delete_by_query refresh documentation](https://opensearch.org/docs/latest/api-reference/document-apis/delete-by-query/).
|
|
@@ -784,11 +786,18 @@ class OpenSearchDocumentStore:
|
|
|
784
786
|
try:
|
|
785
787
|
if recreate_index:
|
|
786
788
|
# get the current index mappings and settings
|
|
787
|
-
index_name = self._index
|
|
788
789
|
index_info = self._client.indices.get(index=self._index)
|
|
790
|
+
actual_index = next(iter(index_info))
|
|
791
|
+
if actual_index != self._index:
|
|
792
|
+
msg = (
|
|
793
|
+
f"Cannot recreate index '{self._index}' because it is an alias pointing to "
|
|
794
|
+
f"'{actual_index}'. Use recreate_index=False to delete all documents via "
|
|
795
|
+
f"delete_by_query, or operate directly on the concrete index."
|
|
796
|
+
)
|
|
797
|
+
raise DocumentStoreError(msg)
|
|
789
798
|
body = {
|
|
790
|
-
"mappings": index_info[
|
|
791
|
-
"settings": index_info[
|
|
799
|
+
"mappings": index_info[actual_index]["mappings"],
|
|
800
|
+
"settings": index_info[actual_index]["settings"],
|
|
792
801
|
}
|
|
793
802
|
body["settings"]["index"].pop("uuid", None)
|
|
794
803
|
body["settings"]["index"].pop("creation_date", None)
|
|
@@ -818,6 +827,8 @@ class OpenSearchDocumentStore:
|
|
|
818
827
|
|
|
819
828
|
:param recreate_index: If True, the index will be deleted and recreated with the original mappings and
|
|
820
829
|
settings. If False, all documents will be deleted using the `delete_by_query` API.
|
|
830
|
+
``recreate_index=True`` is not supported when the configured index name is an alias; a
|
|
831
|
+
:class:`haystack.document_stores.errors.DocumentStoreError` is raised in that case.
|
|
821
832
|
:param refresh: If True, OpenSearch refreshes all shards involved in the delete by query after the request
|
|
822
833
|
completes. If False, no refresh is performed. For more details, see the
|
|
823
834
|
[OpenSearch delete_by_query refresh documentation](https://opensearch.org/docs/latest/api-reference/document-apis/delete-by-query/).
|
|
@@ -828,11 +839,18 @@ class OpenSearchDocumentStore:
|
|
|
828
839
|
try:
|
|
829
840
|
if recreate_index:
|
|
830
841
|
# get the current index mappings and settings
|
|
831
|
-
index_name = self._index
|
|
832
842
|
index_info = await self._async_client.indices.get(index=self._index)
|
|
843
|
+
actual_index = next(iter(index_info))
|
|
844
|
+
if actual_index != self._index:
|
|
845
|
+
msg = (
|
|
846
|
+
f"Cannot recreate index '{self._index}' because it is an alias pointing to "
|
|
847
|
+
f"'{actual_index}'. Use recreate_index=False to delete all documents via "
|
|
848
|
+
f"delete_by_query, or operate directly on the concrete index."
|
|
849
|
+
)
|
|
850
|
+
raise DocumentStoreError(msg)
|
|
833
851
|
body = {
|
|
834
|
-
"mappings": index_info[
|
|
835
|
-
"settings": index_info[
|
|
852
|
+
"mappings": index_info[actual_index]["mappings"],
|
|
853
|
+
"settings": index_info[actual_index]["settings"],
|
|
836
854
|
}
|
|
837
855
|
body["settings"]["index"].pop("uuid", None)
|
|
838
856
|
body["settings"]["index"].pop("creation_date", None)
|
|
@@ -1817,7 +1835,8 @@ class OpenSearchDocumentStore:
|
|
|
1817
1835
|
|
|
1818
1836
|
# use index mapping to get all fields
|
|
1819
1837
|
mapping = self._client.indices.get_mapping(index=self._index)
|
|
1820
|
-
|
|
1838
|
+
actual_index = next(iter(mapping))
|
|
1839
|
+
index_mapping = mapping[actual_index]["mappings"]["properties"]
|
|
1821
1840
|
|
|
1822
1841
|
# normalize field names
|
|
1823
1842
|
normalized_metadata_fields = [_normalize_metadata_field_name(field) for field in metadata_fields]
|
|
@@ -1860,7 +1879,8 @@ class OpenSearchDocumentStore:
|
|
|
1860
1879
|
|
|
1861
1880
|
# use index mapping to get all fields
|
|
1862
1881
|
mapping = await self._async_client.indices.get_mapping(index=self._index)
|
|
1863
|
-
|
|
1882
|
+
actual_index = next(iter(mapping))
|
|
1883
|
+
index_mapping = mapping[actual_index]["mappings"]["properties"]
|
|
1864
1884
|
|
|
1865
1885
|
# normalize field names
|
|
1866
1886
|
normalized_metadata_fields = [_normalize_metadata_field_name(field) for field in metadata_fields]
|
|
@@ -1912,7 +1932,8 @@ class OpenSearchDocumentStore:
|
|
|
1912
1932
|
assert self._client is not None
|
|
1913
1933
|
|
|
1914
1934
|
mapping = self._client.indices.get_mapping(index=self._index)
|
|
1915
|
-
|
|
1935
|
+
actual_index = next(iter(mapping))
|
|
1936
|
+
index_mapping = mapping[actual_index]["mappings"]["properties"]
|
|
1916
1937
|
# remove all fields that are not metadata fields
|
|
1917
1938
|
index_mapping = {k: v for k, v in index_mapping.items() if k not in SPECIAL_FIELDS}
|
|
1918
1939
|
return index_mapping
|
|
@@ -1945,7 +1966,8 @@ class OpenSearchDocumentStore:
|
|
|
1945
1966
|
assert self._async_client is not None
|
|
1946
1967
|
|
|
1947
1968
|
mapping = await self._async_client.indices.get_mapping(index=self._index)
|
|
1948
|
-
|
|
1969
|
+
actual_index = next(iter(mapping))
|
|
1970
|
+
index_mapping = mapping[actual_index]["mappings"]["properties"]
|
|
1949
1971
|
# remove all fields that are not metadata fields
|
|
1950
1972
|
index_mapping = {k: v for k, v in index_mapping.items() if k not in SPECIAL_FIELDS}
|
|
1951
1973
|
return index_mapping
|
|
@@ -74,6 +74,7 @@ def test_to_dict(_mock_opensearch_client):
|
|
|
74
74
|
"filter_policy": "replace",
|
|
75
75
|
"custom_query": {"some": "custom query"},
|
|
76
76
|
"raise_on_failure": True,
|
|
77
|
+
"all_terms_must_match": False,
|
|
77
78
|
},
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -91,6 +92,7 @@ def test_from_dict(_mock_opensearch_client):
|
|
|
91
92
|
"fuzziness": "AUTO",
|
|
92
93
|
"top_k": 10,
|
|
93
94
|
"scale_score": True,
|
|
95
|
+
"all_terms_must_match": True,
|
|
94
96
|
"filter_policy": "replace",
|
|
95
97
|
"custom_query": {"some": "custom query"},
|
|
96
98
|
"raise_on_failure": False,
|
|
@@ -102,6 +104,7 @@ def test_from_dict(_mock_opensearch_client):
|
|
|
102
104
|
assert retriever._fuzziness == "AUTO"
|
|
103
105
|
assert retriever._top_k == 10
|
|
104
106
|
assert retriever._scale_score
|
|
107
|
+
assert retriever._all_terms_must_match is True
|
|
105
108
|
assert retriever._filter_policy == FilterPolicy.REPLACE
|
|
106
109
|
assert retriever._custom_query == {"some": "custom query"}
|
|
107
110
|
assert retriever._raise_on_failure is False
|
|
@@ -124,6 +127,7 @@ def test_from_dict(_mock_opensearch_client):
|
|
|
124
127
|
}
|
|
125
128
|
retriever = OpenSearchBM25Retriever.from_dict(data)
|
|
126
129
|
assert retriever._filter_policy == FilterPolicy.REPLACE
|
|
130
|
+
assert retriever._all_terms_must_match is False
|
|
127
131
|
|
|
128
132
|
|
|
129
133
|
@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
|
|
@@ -692,6 +692,69 @@ async def test_ensure_index_exists_async_no_create_when_disabled(_mock_sync_clie
|
|
|
692
692
|
mock_client.indices.get_mapping.assert_not_called()
|
|
693
693
|
|
|
694
694
|
|
|
695
|
+
@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
|
|
696
|
+
def test_delete_all_documents_recreate_raises_for_alias(_mock_opensearch_client):
|
|
697
|
+
"""delete_all_documents(recreate_index=True) raises DocumentStoreError when self._index is an alias."""
|
|
698
|
+
store = OpenSearchDocumentStore(hosts="testhost", index="my-alias", http_auth=("a", "b"))
|
|
699
|
+
mock_client = MagicMock()
|
|
700
|
+
store._client = mock_client
|
|
701
|
+
# indices.get() returns a key that differs from self._index — signals an alias
|
|
702
|
+
mock_client.indices.get.return_value = {"my-real-index-v1": {"mappings": {}, "settings": {"index": {}}}}
|
|
703
|
+
|
|
704
|
+
with pytest.raises(DocumentStoreError, match="is an alias"):
|
|
705
|
+
store.delete_all_documents(recreate_index=True)
|
|
706
|
+
|
|
707
|
+
mock_client.indices.delete.assert_not_called()
|
|
708
|
+
mock_client.indices.create.assert_not_called()
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
|
|
712
|
+
def test_delete_all_documents_recreate_works_for_concrete_index(_mock_opensearch_client):
|
|
713
|
+
"""delete_all_documents(recreate_index=True) proceeds normally when self._index is a concrete index."""
|
|
714
|
+
store = OpenSearchDocumentStore(hosts="testhost", index="my-index", http_auth=("a", "b"))
|
|
715
|
+
mock_client = MagicMock()
|
|
716
|
+
store._client = mock_client
|
|
717
|
+
mock_client.indices.get.return_value = {"my-index": {"mappings": {}, "settings": {"index": {}}}}
|
|
718
|
+
|
|
719
|
+
store.delete_all_documents(recreate_index=True)
|
|
720
|
+
|
|
721
|
+
mock_client.indices.delete.assert_called_once_with(index="my-index")
|
|
722
|
+
mock_client.indices.create.assert_called_once()
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
@pytest.mark.asyncio
|
|
726
|
+
@patch("haystack_integrations.document_stores.opensearch.document_store.AsyncOpenSearch")
|
|
727
|
+
@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
|
|
728
|
+
async def test_delete_all_documents_async_recreate_raises_for_alias(_mock_sync_client, _mock_async_client):
|
|
729
|
+
"""delete_all_documents_async(recreate_index=True) raises DocumentStoreError when self._index is an alias."""
|
|
730
|
+
store = OpenSearchDocumentStore(hosts="testhost", index="my-alias", http_auth=("a", "b"))
|
|
731
|
+
mock_client = AsyncMock()
|
|
732
|
+
store._async_client = mock_client
|
|
733
|
+
mock_client.indices.get = AsyncMock(return_value={"my-real-index-v1": {"mappings": {}, "settings": {"index": {}}}})
|
|
734
|
+
|
|
735
|
+
with pytest.raises(DocumentStoreError, match="is an alias"):
|
|
736
|
+
await store.delete_all_documents_async(recreate_index=True)
|
|
737
|
+
|
|
738
|
+
mock_client.indices.delete.assert_not_called()
|
|
739
|
+
mock_client.indices.create.assert_not_called()
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
@pytest.mark.asyncio
|
|
743
|
+
@patch("haystack_integrations.document_stores.opensearch.document_store.AsyncOpenSearch")
|
|
744
|
+
@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
|
|
745
|
+
async def test_delete_all_documents_async_recreate_works_for_concrete_index(_mock_sync_client, _mock_async_client):
|
|
746
|
+
"""delete_all_documents_async(recreate_index=True) proceeds normally when self._index is a concrete index."""
|
|
747
|
+
store = OpenSearchDocumentStore(hosts="testhost", index="my-index", http_auth=("a", "b"))
|
|
748
|
+
mock_client = AsyncMock()
|
|
749
|
+
store._async_client = mock_client
|
|
750
|
+
mock_client.indices.get = AsyncMock(return_value={"my-index": {"mappings": {}, "settings": {"index": {}}}})
|
|
751
|
+
|
|
752
|
+
await store.delete_all_documents_async(recreate_index=True)
|
|
753
|
+
|
|
754
|
+
mock_client.indices.delete.assert_called_once_with(index="my-index")
|
|
755
|
+
mock_client.indices.create.assert_called_once()
|
|
756
|
+
|
|
757
|
+
|
|
695
758
|
@pytest.mark.integration
|
|
696
759
|
class TestDocumentStore(
|
|
697
760
|
OpenSearchDocumentStoreTestMixin,
|
|
@@ -1649,3 +1712,100 @@ class TestDocumentStore(
|
|
|
1649
1712
|
assert results[0].content == "doc via alias"
|
|
1650
1713
|
finally:
|
|
1651
1714
|
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
1715
|
+
|
|
1716
|
+
def test_delete_all_documents_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
1717
|
+
"""delete_all_documents(recreate_index=True) raises DocumentStoreError when self._index is an alias."""
|
|
1718
|
+
alias_name = f"alias_del_{document_store._index}"
|
|
1719
|
+
client = document_store._client
|
|
1720
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
1721
|
+
try:
|
|
1722
|
+
alias_store = OpenSearchDocumentStore(
|
|
1723
|
+
hosts=["https://localhost:9200"],
|
|
1724
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
1725
|
+
verify_certs=False,
|
|
1726
|
+
index=alias_name,
|
|
1727
|
+
embedding_dim=768,
|
|
1728
|
+
)
|
|
1729
|
+
alias_store._ensure_initialized()
|
|
1730
|
+
|
|
1731
|
+
with pytest.raises(DocumentStoreError, match="is an alias"):
|
|
1732
|
+
alias_store.delete_all_documents(recreate_index=True)
|
|
1733
|
+
finally:
|
|
1734
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
1735
|
+
|
|
1736
|
+
def test_delete_all_documents_no_recreate_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
1737
|
+
"""delete_all_documents(recreate_index=False) removes all documents when self._index is an alias."""
|
|
1738
|
+
alias_name = f"alias_del_norecr_{document_store._index}"
|
|
1739
|
+
client = document_store._client
|
|
1740
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
1741
|
+
try:
|
|
1742
|
+
alias_store = OpenSearchDocumentStore(
|
|
1743
|
+
hosts=["https://localhost:9200"],
|
|
1744
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
1745
|
+
verify_certs=False,
|
|
1746
|
+
index=alias_name,
|
|
1747
|
+
embedding_dim=768,
|
|
1748
|
+
)
|
|
1749
|
+
alias_store._ensure_initialized()
|
|
1750
|
+
alias_store.write_documents([Document(content="a"), Document(content="b")])
|
|
1751
|
+
assert alias_store.count_documents() == 2
|
|
1752
|
+
|
|
1753
|
+
alias_store.delete_all_documents(recreate_index=False)
|
|
1754
|
+
|
|
1755
|
+
assert alias_store.count_documents() == 0
|
|
1756
|
+
assert alias_store.write_documents([Document(content="after delete")]) == 1
|
|
1757
|
+
finally:
|
|
1758
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
1759
|
+
|
|
1760
|
+
def test_count_unique_metadata_by_filter_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
1761
|
+
"""count_unique_metadata_by_filter reads the mapping via alias without KeyError."""
|
|
1762
|
+
alias_name = f"alias_cnt_{document_store._index}"
|
|
1763
|
+
client = document_store._client
|
|
1764
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
1765
|
+
try:
|
|
1766
|
+
alias_store = OpenSearchDocumentStore(
|
|
1767
|
+
hosts=["https://localhost:9200"],
|
|
1768
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
1769
|
+
verify_certs=False,
|
|
1770
|
+
index=alias_name,
|
|
1771
|
+
embedding_dim=768,
|
|
1772
|
+
)
|
|
1773
|
+
alias_store._ensure_initialized()
|
|
1774
|
+
alias_store.write_documents(
|
|
1775
|
+
[
|
|
1776
|
+
Document(content="a", meta={"category": "X"}),
|
|
1777
|
+
Document(content="b", meta={"category": "X"}),
|
|
1778
|
+
Document(content="c", meta={"category": "Y"}),
|
|
1779
|
+
]
|
|
1780
|
+
)
|
|
1781
|
+
|
|
1782
|
+
result = alias_store.count_unique_metadata_by_filter(
|
|
1783
|
+
filters={"field": "meta.category", "operator": "in", "value": ["X", "Y"]},
|
|
1784
|
+
metadata_fields=["category"],
|
|
1785
|
+
)
|
|
1786
|
+
assert result == {"category": 2}
|
|
1787
|
+
finally:
|
|
1788
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
1789
|
+
|
|
1790
|
+
def test_get_metadata_fields_info_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
1791
|
+
"""get_metadata_fields_info reads the mapping via alias without KeyError."""
|
|
1792
|
+
alias_name = f"alias_mfi_{document_store._index}"
|
|
1793
|
+
client = document_store._client
|
|
1794
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
1795
|
+
try:
|
|
1796
|
+
alias_store = OpenSearchDocumentStore(
|
|
1797
|
+
hosts=["https://localhost:9200"],
|
|
1798
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
1799
|
+
verify_certs=False,
|
|
1800
|
+
index=alias_name,
|
|
1801
|
+
embedding_dim=768,
|
|
1802
|
+
)
|
|
1803
|
+
alias_store._ensure_initialized()
|
|
1804
|
+
alias_store.write_documents([Document(content="doc", meta={"category": "A", "count": 1})])
|
|
1805
|
+
|
|
1806
|
+
fields_info = alias_store.get_metadata_fields_info()
|
|
1807
|
+
assert "category" in fields_info
|
|
1808
|
+
assert fields_info["category"]["type"] == "keyword"
|
|
1809
|
+
assert "count" in fields_info
|
|
1810
|
+
finally:
|
|
1811
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
@@ -653,3 +653,117 @@ class TestDocumentStoreAsync(
|
|
|
653
653
|
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
654
654
|
if alias_store._async_client:
|
|
655
655
|
await alias_store._async_client.close()
|
|
656
|
+
|
|
657
|
+
@pytest.mark.asyncio
|
|
658
|
+
async def test_delete_all_documents_async_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
659
|
+
"""delete_all_documents_async(recreate_index=True) raises DocumentStoreError when self._index is an alias."""
|
|
660
|
+
alias_name = f"alias_del_{document_store._index}"
|
|
661
|
+
client = document_store._client
|
|
662
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
663
|
+
alias_store = OpenSearchDocumentStore(
|
|
664
|
+
hosts=["https://localhost:9200"],
|
|
665
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
666
|
+
verify_certs=False,
|
|
667
|
+
index=alias_name,
|
|
668
|
+
embedding_dim=768,
|
|
669
|
+
)
|
|
670
|
+
try:
|
|
671
|
+
await alias_store._ensure_initialized_async()
|
|
672
|
+
|
|
673
|
+
with pytest.raises(DocumentStoreError, match="is an alias"):
|
|
674
|
+
await alias_store.delete_all_documents_async(recreate_index=True)
|
|
675
|
+
|
|
676
|
+
# delete_by_query path still works for aliases
|
|
677
|
+
await alias_store.write_documents_async([Document(content="x")])
|
|
678
|
+
await alias_store.delete_all_documents_async(recreate_index=False)
|
|
679
|
+
assert await alias_store.count_documents_async() == 0
|
|
680
|
+
finally:
|
|
681
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
682
|
+
if alias_store._async_client:
|
|
683
|
+
await alias_store._async_client.close()
|
|
684
|
+
|
|
685
|
+
@pytest.mark.asyncio
|
|
686
|
+
async def test_delete_all_documents_no_recreate_async_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
687
|
+
"""delete_all_documents_async(recreate_index=False) removes all documents when self._index is an alias."""
|
|
688
|
+
alias_name = f"alias_del_norecr_{document_store._index}"
|
|
689
|
+
client = document_store._client
|
|
690
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
691
|
+
alias_store = OpenSearchDocumentStore(
|
|
692
|
+
hosts=["https://localhost:9200"],
|
|
693
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
694
|
+
verify_certs=False,
|
|
695
|
+
index=alias_name,
|
|
696
|
+
embedding_dim=768,
|
|
697
|
+
)
|
|
698
|
+
try:
|
|
699
|
+
await alias_store._ensure_initialized_async()
|
|
700
|
+
await alias_store.write_documents_async([Document(content="a"), Document(content="b")])
|
|
701
|
+
assert await alias_store.count_documents_async() == 2
|
|
702
|
+
|
|
703
|
+
await alias_store.delete_all_documents_async(recreate_index=False)
|
|
704
|
+
|
|
705
|
+
assert await alias_store.count_documents_async() == 0
|
|
706
|
+
assert await alias_store.write_documents_async([Document(content="after delete")]) == 1
|
|
707
|
+
finally:
|
|
708
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
709
|
+
if alias_store._async_client:
|
|
710
|
+
await alias_store._async_client.close()
|
|
711
|
+
|
|
712
|
+
@pytest.mark.asyncio
|
|
713
|
+
async def test_count_unique_metadata_by_filter_async_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
714
|
+
"""count_unique_metadata_by_filter_async reads the mapping via alias without KeyError."""
|
|
715
|
+
alias_name = f"alias_cnt_{document_store._index}"
|
|
716
|
+
client = document_store._client
|
|
717
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
718
|
+
alias_store = OpenSearchDocumentStore(
|
|
719
|
+
hosts=["https://localhost:9200"],
|
|
720
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
721
|
+
verify_certs=False,
|
|
722
|
+
index=alias_name,
|
|
723
|
+
embedding_dim=768,
|
|
724
|
+
)
|
|
725
|
+
try:
|
|
726
|
+
await alias_store._ensure_initialized_async()
|
|
727
|
+
await alias_store.write_documents_async(
|
|
728
|
+
[
|
|
729
|
+
Document(content="a", meta={"category": "X"}),
|
|
730
|
+
Document(content="b", meta={"category": "X"}),
|
|
731
|
+
Document(content="c", meta={"category": "Y"}),
|
|
732
|
+
]
|
|
733
|
+
)
|
|
734
|
+
|
|
735
|
+
result = await alias_store.count_unique_metadata_by_filter_async(
|
|
736
|
+
filters={"field": "meta.category", "operator": "in", "value": ["X", "Y"]},
|
|
737
|
+
metadata_fields=["category"],
|
|
738
|
+
)
|
|
739
|
+
assert result == {"category": 2}
|
|
740
|
+
finally:
|
|
741
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
742
|
+
if alias_store._async_client:
|
|
743
|
+
await alias_store._async_client.close()
|
|
744
|
+
|
|
745
|
+
@pytest.mark.asyncio
|
|
746
|
+
async def test_get_metadata_fields_info_async_with_alias(self, document_store: OpenSearchDocumentStore):
|
|
747
|
+
"""get_metadata_fields_info_async reads the mapping via alias without KeyError."""
|
|
748
|
+
alias_name = f"alias_mfi_{document_store._index}"
|
|
749
|
+
client = document_store._client
|
|
750
|
+
client.indices.put_alias(index=document_store._index, name=alias_name)
|
|
751
|
+
alias_store = OpenSearchDocumentStore(
|
|
752
|
+
hosts=["https://localhost:9200"],
|
|
753
|
+
http_auth=("admin", "SecureHaystack!2026"),
|
|
754
|
+
verify_certs=False,
|
|
755
|
+
index=alias_name,
|
|
756
|
+
embedding_dim=768,
|
|
757
|
+
)
|
|
758
|
+
try:
|
|
759
|
+
await alias_store._ensure_initialized_async()
|
|
760
|
+
await alias_store.write_documents_async([Document(content="doc", meta={"category": "A", "count": 1})])
|
|
761
|
+
|
|
762
|
+
fields_info = await alias_store.get_metadata_fields_info_async()
|
|
763
|
+
assert "category" in fields_info
|
|
764
|
+
assert fields_info["category"]["type"] == "keyword"
|
|
765
|
+
assert "count" in fields_info
|
|
766
|
+
finally:
|
|
767
|
+
client.indices.delete_alias(index=document_store._index, name=alias_name)
|
|
768
|
+
if alias_store._async_client:
|
|
769
|
+
await alias_store._async_client.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_metadata_retriever_async.py
RENAMED
|
File without changes
|
{opensearch_haystack-8.1.0 → opensearch_haystack-8.1.2}/tests/test_open_search_hybrid_retriever.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|