pinecone-haystack 6.2.0__tar.gz → 6.4.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.
Files changed (21) hide show
  1. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/CHANGELOG.md +47 -0
  2. pinecone_haystack-6.4.0/LICENSE.txt +201 -0
  3. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/PKG-INFO +4 -3
  4. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/examples/example.py +4 -1
  5. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/pyproject.toml +2 -1
  6. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/components/retrievers/pinecone/embedding_retriever.py +15 -2
  7. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/document_stores/pinecone/document_store.py +59 -22
  8. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/tests/test_document_store.py +88 -58
  9. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/tests/test_document_store_async.py +89 -4
  10. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/tests/test_embedding_retriever.py +23 -1
  11. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/.gitignore +0 -0
  12. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/README.md +0 -0
  13. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/pydoc/config_docusaurus.yml +0 -0
  14. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/components/retrievers/pinecone/__init__.py +0 -0
  15. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/components/retrievers/py.typed +0 -0
  16. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/document_stores/pinecone/__init__.py +0 -0
  17. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/document_stores/pinecone/filters.py +0 -0
  18. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/src/haystack_integrations/document_stores/py.typed +0 -0
  19. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/tests/__init__.py +0 -0
  20. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/tests/conftest.py +0 -0
  21. {pinecone_haystack-6.2.0 → pinecone_haystack-6.4.0}/tests/test_filters.py +0 -0
@@ -1,5 +1,52 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/pinecone-v6.3.0] - 2026-07-22
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - Replace in-place dataclass mutations in anthropic, llama_cpp, olama, pinecone tests (#3551)
8
+
9
+ ### 🚜 Refactor
10
+
11
+ - Align Pinecone closing methods to standard (#3629)
12
+
13
+ ### 📚 Documentation
14
+
15
+ - Replace old haystack core imports with haystack_integrations paths (#3545)
16
+
17
+
18
+ ## [integrations/pinecone-v6.2.0] - 2026-05-08
19
+
20
+ ### 🐛 Bug Fixes
21
+
22
+ - Replace in-place dataclass mutations in document stores (#3114)
23
+
24
+ ### 🚜 Refactor
25
+
26
+ - *(pinecone)* Make get_metadata_field_min_max more consistent; use async DocumentStore mixin tests (#3231)
27
+
28
+ ### 📚 Documentation
29
+
30
+ - Simplify pydoc configs (#2855)
31
+
32
+ ### 🧪 Testing
33
+
34
+ - Replacing each `DocumentStore` specific tests and used the generalised ones from `haystack.testing.document_store` (#2812)
35
+ - Test compatible integrations with python 3.14; update pyproject (#3001)
36
+ - `PineconeDocumentStore` use Mixin tests (#3020)
37
+ - Track test coverage for all integrations (#3065)
38
+ - Pinecone - add unit tests (#3218)
39
+ - Pinecone - remove namespaces when tests ends (#3248)
40
+
41
+ ### 🧹 Chores
42
+
43
+ - Exposing `PineconeDocumentStore` `show_progress` bar parameter and disabling it for tests (#2799)
44
+ - Remove unused allow-direct-references (#2866)
45
+ - Add ANN ruff ruleset to optimum, paddleocr, pgvector, pinecone, pyversity, qdrant, ragas, snowflake (#2992)
46
+ - Enforce ruff docstring rules in integrations 31-40 (openrouter, opensearch, optimum, paddleocr, pgvector, pinecone, pyversity, qdrant, ragas, snowflake) (#3011)
47
+ - Pinecone - fix types for Pinecone 9 (#3277)
48
+
49
+
3
50
  ## [integrations/pinecone-v6.1.2] - 2026-01-28
4
51
 
5
52
  ### 🐛 Bug Fixes
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023-present deepset GmbH
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,11 +1,12 @@
1
- Metadata-Version: 2.4
2
- Name: pinecone_haystack
3
- Version: 6.2.0
1
+ Metadata-Version: 2.5
2
+ Name: pinecone-haystack
3
+ Version: 6.4.0
4
4
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/pinecone#readme
5
5
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
6
6
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/pinecone
7
7
  Author-email: deepset GmbH <info@deepset.ai>
8
8
  License-Expression: Apache-2.0
9
+ License-File: LICENSE.txt
9
10
  Classifier: Development Status :: 4 - Beta
10
11
  Classifier: License :: OSI Approved :: Apache Software License
11
12
  Classifier: Programming Language :: Python
@@ -12,11 +12,14 @@ import glob
12
12
 
13
13
  from haystack import Pipeline
14
14
  from haystack.components.converters import MarkdownToDocument
15
- from haystack.components.embedders import SentenceTransformersDocumentEmbedder, SentenceTransformersTextEmbedder
16
15
  from haystack.components.preprocessors import DocumentSplitter
17
16
  from haystack.components.writers import DocumentWriter
18
17
  from haystack.utils import Secret
19
18
 
19
+ from haystack_integrations.components.embedders.sentence_transformers import (
20
+ SentenceTransformersDocumentEmbedder,
21
+ SentenceTransformersTextEmbedder,
22
+ )
20
23
  from haystack_integrations.components.retrievers.pinecone import PineconeEmbeddingRetriever
21
24
  from haystack_integrations.document_stores.pinecone import PineconeDocumentStore
22
25
 
@@ -3,7 +3,7 @@ requires = ["hatchling", "hatch-vcs"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
- name = "pinecone_haystack"
6
+ name = "pinecone-haystack"
7
7
  dynamic = ["version"]
8
8
  description = ''
9
9
  readme = "README.md"
@@ -140,6 +140,7 @@ ignore = [
140
140
  "PLR0912",
141
141
  "PLR0913",
142
142
  "PLR0915",
143
+ "PLR0917",
143
144
  # Ignore assertions
144
145
  "S101",
145
146
  ]
@@ -22,7 +22,9 @@ class PineconeEmbeddingRetriever:
22
22
  from haystack.document_stores.types import DuplicatePolicy
23
23
  from haystack import Document
24
24
  from haystack import Pipeline
25
- from haystack.components.embedders import SentenceTransformersTextEmbedder, SentenceTransformersDocumentEmbedder
25
+ # Requires: pip install sentence-transformers-haystack
26
+ from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersTextEmbedder
27
+ from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersDocumentEmbedder
26
28
  from haystack_integrations.components.retrievers.pinecone import PineconeEmbeddingRetriever
27
29
  from haystack_integrations.document_stores.pinecone import PineconeDocumentStore
28
30
 
@@ -34,7 +36,6 @@ class PineconeEmbeddingRetriever:
34
36
  Document(content="In certain places, you can witness the phenomenon of bioluminescent waves.")]
35
37
 
36
38
  document_embedder = SentenceTransformersDocumentEmbedder()
37
- document_embedder.warm_up()
38
39
  documents_with_embeddings = document_embedder.run(documents)
39
40
 
40
41
  document_store.write_documents(documents_with_embeddings.get("documents"), policy=DuplicatePolicy.OVERWRITE)
@@ -114,6 +115,18 @@ class PineconeEmbeddingRetriever:
114
115
  data["init_parameters"]["filter_policy"] = FilterPolicy.from_str(filter_policy)
115
116
  return default_from_dict(cls, data)
116
117
 
118
+ def close(self) -> None:
119
+ """
120
+ Release the synchronous resources of the underlying Document Store.
121
+ """
122
+ self.document_store.close()
123
+
124
+ async def close_async(self) -> None:
125
+ """
126
+ Release the asynchronous resources of the underlying Document Store.
127
+ """
128
+ await self.document_store.close_async()
129
+
117
130
  @component.output_types(documents=list[Document])
118
131
  def run(
119
132
  self,
@@ -2,6 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
+ from contextlib import suppress
5
6
  from copy import copy
6
7
  from dataclasses import replace
7
8
  from typing import Any, Literal
@@ -151,18 +152,20 @@ class PineconeDocumentStore:
151
152
 
152
153
  def close(self) -> None:
153
154
  """
154
- Close the associated synchronous resources.
155
+ Release the associated synchronous resources.
155
156
  """
156
- if self._index:
157
- self._index.close()
157
+ if self._index is not None:
158
+ with suppress(Exception):
159
+ self._index.close()
158
160
  self._index = None
159
161
 
160
162
  async def close_async(self) -> None:
161
163
  """
162
- Close the associated asynchronous resources. To be invoked manually when the Document Store is no longer needed.
164
+ Release the associated asynchronous resources.
163
165
  """
164
- if self._async_index:
165
- await self._async_index.close()
166
+ if self._async_index is not None:
167
+ with suppress(Exception):
168
+ await self._async_index.close()
166
169
  self._async_index = None
167
170
 
168
171
  @staticmethod
@@ -888,25 +891,37 @@ class PineconeDocumentStore:
888
891
  @staticmethod
889
892
  def _get_metadata_field_unique_values_impl(
890
893
  documents: list[Document], metadata_field: str, search_term: str | None, from_: int, size: int
891
- ) -> tuple[list[str], int]:
894
+ ) -> tuple[list[Any], int]:
892
895
  """Helper method to get unique values for a metadata field with search and pagination."""
893
- unique_values: set[str] = set()
896
+ field_name = metadata_field.removeprefix("meta.")
897
+ # Values of different types can be equal in Python (`1 == True`, `1 == 1.0`), so a plain set
898
+ # would silently merge them. Dedupe by (type, value) instead to keep them distinct.
899
+ seen: set[tuple[type, Any]] = set()
900
+ unique_values: list[Any] = []
901
+
902
+ def _add(value: Any) -> None:
903
+ dedup_key = (type(value), value)
904
+ if dedup_key not in seen:
905
+ seen.add(dedup_key)
906
+ unique_values.append(value)
907
+
894
908
  for doc in documents:
895
- if doc.meta and metadata_field in doc.meta:
896
- value = doc.meta[metadata_field]
909
+ if doc.meta and field_name in doc.meta:
910
+ value = doc.meta[field_name]
897
911
  # Handle list values
898
912
  if isinstance(value, list):
899
- unique_values.update(str(v) for v in value)
913
+ for item in value:
914
+ _add(item)
900
915
  else:
901
- unique_values.add(str(value))
916
+ _add(value)
902
917
 
903
918
  # Convert to sorted list
904
- unique_values_list = sorted(unique_values)
919
+ unique_values_list = sorted(unique_values, key=str)
905
920
 
906
921
  # Apply search term filter if provided
907
922
  if search_term:
908
923
  search_term_lower = search_term.lower()
909
- unique_values_list = [v for v in unique_values_list if search_term_lower in v.lower()]
924
+ unique_values_list = [v for v in unique_values_list if search_term_lower in str(v).lower()]
910
925
 
911
926
  total_count = len(unique_values_list)
912
927
 
@@ -1066,37 +1081,59 @@ class PineconeDocumentStore:
1066
1081
  return self._get_metadata_field_min_max_impl(documents, metadata_field)
1067
1082
 
1068
1083
  def get_metadata_field_unique_values(
1069
- self, metadata_field: str, search_term: str | None = None, from_: int = 0, size: int = 10
1070
- ) -> tuple[list[str], int]:
1084
+ self,
1085
+ metadata_field: str,
1086
+ search_term: str | None = None,
1087
+ from_: int = 0,
1088
+ size: int = 10,
1089
+ filters: dict[str, Any] | None = None,
1090
+ ) -> tuple[list[Any], int]:
1071
1091
  """
1072
1092
  Retrieves unique values for a metadata field with optional search and pagination.
1073
1093
 
1074
1094
  Note: This method fetches documents and extracts unique values in Python.
1075
1095
  Subject to Pinecone's TOP_K_LIMIT of 1000 documents.
1076
1096
 
1097
+ Note: Pinecone stores numeric metadata values as `float` (see `_convert_meta_to_int`), so an
1098
+ int written for an arbitrary field may come back as a numerically equal float rather than int.
1099
+ Values of different types are otherwise kept distinct even when they compare equal in Python
1100
+ (e.g. the int `1` and the bool `True` are returned as two separate values).
1101
+
1077
1102
  :param metadata_field: The metadata field name to get unique values for.
1078
1103
  :param search_term: Optional search term to filter values (case-insensitive substring match).
1079
1104
  :param from_: Starting offset for pagination (default: 0).
1080
1105
  :param size: Number of values to return (default: 10).
1081
- :returns: Tuple of (list of unique values, total count of matching values).
1106
+ :param filters: Optional filters to restrict the documents considered.
1107
+ :returns: Tuple of (list of unique values in their original type, total count of matching values).
1082
1108
  """
1083
- documents = self.filter_documents(filters=None)
1109
+ documents = self.filter_documents(filters=filters)
1084
1110
  return self._get_metadata_field_unique_values_impl(documents, metadata_field, search_term, from_, size)
1085
1111
 
1086
1112
  async def get_metadata_field_unique_values_async(
1087
- self, metadata_field: str, search_term: str | None = None, from_: int = 0, size: int = 10
1088
- ) -> tuple[list[str], int]:
1113
+ self,
1114
+ metadata_field: str,
1115
+ search_term: str | None = None,
1116
+ from_: int = 0,
1117
+ size: int = 10,
1118
+ filters: dict[str, Any] | None = None,
1119
+ ) -> tuple[list[Any], int]:
1089
1120
  """
1090
1121
  Asynchronously retrieves unique values for a metadata field with optional search and pagination.
1091
1122
 
1092
1123
  Note: This method fetches documents and extracts unique values in Python.
1093
1124
  Subject to Pinecone's TOP_K_LIMIT of 1000 documents.
1094
1125
 
1126
+ Note: Pinecone stores numeric metadata values as `float` (see `_convert_meta_to_int`), so an
1127
+ int written for an arbitrary field may come back as a numerically equal float rather than int.
1128
+ Values of different types are otherwise kept distinct even when they compare equal in Python
1129
+ (e.g. the int `1` and the bool `True` are returned as two separate values).
1130
+
1095
1131
  :param metadata_field: The metadata field name to get unique values for.
1096
1132
  :param search_term: Optional search term to filter values (case-insensitive substring match).
1097
1133
  :param from_: Starting offset for pagination (default: 0).
1098
1134
  :param size: Number of values to return (default: 10).
1099
- :returns: Tuple of (list of unique values, total count of matching values).
1135
+ :param filters: Optional filters to restrict the documents considered.
1136
+ :returns: Tuple of (list of unique values in their original type, total count of matching values).
1100
1137
  """
1101
- documents = await self.filter_documents_async(filters=None)
1138
+ documents = await self.filter_documents_async(filters=filters)
1102
1139
  return self._get_metadata_field_unique_values_impl(documents, metadata_field, search_term, from_, size)
@@ -4,7 +4,8 @@
4
4
 
5
5
  import os
6
6
  import time
7
- from unittest.mock import patch
7
+ from dataclasses import replace
8
+ from unittest.mock import MagicMock, patch
8
9
 
9
10
  import numpy as np
10
11
  import pytest
@@ -127,7 +128,31 @@ def test_to_from_dict(mock_pinecone, monkeypatch):
127
128
  assert document_store.dimension == 60
128
129
  assert document_store.metric == "euclidean"
129
130
  assert document_store.spec == {"serverless": {"region": "us-east-1", "cloud": "aws"}}
130
- assert document_store.show_progress is True
131
+
132
+
133
+ def test_close():
134
+ document_store = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
135
+ mock_index = MagicMock()
136
+ document_store._index = mock_index
137
+
138
+ document_store.close()
139
+
140
+ mock_index.close.assert_called_once()
141
+ assert document_store._index is None
142
+
143
+ document_store.close()
144
+ mock_index.close.assert_called_once()
145
+
146
+
147
+ def test_close_is_exception_safe():
148
+ document_store = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
149
+ mock_index = MagicMock()
150
+ mock_index.close.side_effect = RuntimeError("boom")
151
+ document_store._index = mock_index
152
+
153
+ document_store.close()
154
+
155
+ assert document_store._index is None
131
156
 
132
157
 
133
158
  def test_init_fails_wo_api_key(monkeypatch):
@@ -314,6 +339,32 @@ def test_get_metadata_field_unique_values_impl_pagination_search_and_lists():
314
339
  assert values == ["python"]
315
340
 
316
341
 
342
+ def test_get_metadata_field_unique_values_impl_preserves_non_string_types():
343
+ docs = [
344
+ Document(content="a", meta={"priority": 1}),
345
+ Document(content="b", meta={"priority": 2}),
346
+ Document(content="c", meta={"priority": 1}),
347
+ ]
348
+
349
+ values, total = PineconeDocumentStore._get_metadata_field_unique_values_impl(
350
+ docs, "priority", search_term=None, from_=0, size=10
351
+ )
352
+ assert total == 2
353
+ assert set(values) == {1, 2}
354
+
355
+
356
+ def test_get_metadata_field_unique_values_impl_strips_meta_prefix():
357
+ docs = [
358
+ Document(content="a", meta={"category": "news"}),
359
+ Document(content="b", meta={"category": "sports"}),
360
+ ]
361
+ values, total = PineconeDocumentStore._get_metadata_field_unique_values_impl(
362
+ docs, "meta.category", search_term=None, from_=0, size=10
363
+ )
364
+ assert total == 2
365
+ assert values == ["news", "sports"]
366
+
367
+
317
368
  def test_prepare_documents_for_writing_edge_cases(caplog):
318
369
  ds = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
319
370
 
@@ -340,22 +391,6 @@ def test_prepare_documents_for_writing_edge_cases(caplog):
340
391
  assert "sparse_embedding" in caplog.text
341
392
 
342
393
 
343
- @pytest.mark.asyncio
344
- async def test_validation_errors_on_empty_query_and_non_dict_meta():
345
- ds = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
346
- filters = {"field": "meta.category", "operator": "==", "value": "A"}
347
-
348
- with pytest.raises(ValueError, match="query_embedding must be a non-empty list"):
349
- ds._embedding_retrieval(query_embedding=[])
350
- with pytest.raises(ValueError, match="query_embedding must be a non-empty list"):
351
- await ds._embedding_retrieval_async(query_embedding=[])
352
-
353
- with pytest.raises(ValueError, match="meta must be a dictionary"):
354
- ds.update_by_filter(filters=filters, meta="not-a-dict")
355
- with pytest.raises(ValueError, match="meta must be a dictionary"):
356
- await ds.update_by_filter_async(filters=filters, meta="not-a-dict")
357
-
358
-
359
394
  @pytest.mark.integration
360
395
  @pytest.mark.skipif(not os.environ.get("PINECONE_API_KEY"), reason="PINECONE_API_KEY not set")
361
396
  def test_serverless_index_creation_from_scratch(delete_sleep_time):
@@ -417,6 +452,38 @@ class TestDocumentStore(
417
452
  docs = [Document(id="1")]
418
453
  assert document_store.write_documents(docs) == 1
419
454
 
455
+ def test_get_metadata_field_unique_values_distinct_types(self, document_store: PineconeDocumentStore):
456
+ """
457
+ Override: the base mixin test stores int, float, str and bool under the *same* metadata field
458
+ name and expects all four back as distinct values. Pinecone stores numeric metadata values as
459
+ `float` (see `_convert_meta_to_int`), so an int written for an arbitrary field may come back as
460
+ a numerically equal float instead - collapsing with a genuine float under the same field name
461
+ regardless of which other values share that field.
462
+
463
+ This adapts the same intent - int, float, str and bool must come back as distinct, unmangled
464
+ types via get_metadata_field_unique_values() - using one field per type instead of one shared
465
+ field, which is what Pinecone can actually support.
466
+ """
467
+ docs = [
468
+ Document(content="Doc 1", meta={"priority_int": 1}),
469
+ Document(content="Doc 2", meta={"priority_str": "1"}),
470
+ Document(content="Doc 3", meta={"priority_float": 1.5}),
471
+ Document(content="Doc 4", meta={"priority_bool": True}),
472
+ ]
473
+ document_store.write_documents(docs)
474
+
475
+ int_values, int_count = document_store.get_metadata_field_unique_values(metadata_field="priority_int")
476
+ str_values, str_count = document_store.get_metadata_field_unique_values(metadata_field="priority_str")
477
+ float_values, float_count = document_store.get_metadata_field_unique_values(metadata_field="priority_float")
478
+ bool_values, bool_count = document_store.get_metadata_field_unique_values(metadata_field="priority_bool")
479
+
480
+ assert (int_count, str_count, float_count, bool_count) == (1, 1, 1, 1)
481
+ assert str_values == ["1"] and type(str_values[0]) is str
482
+ assert float_values == [1.5] and type(float_values[0]) is float
483
+ assert bool_values == [True] and type(bool_values[0]) is bool
484
+ # Pinecone may return a whole-number int as a numerically equal float (see docstring note above).
485
+ assert int_values[0] == 1 and type(int_values[0]) in (int, float)
486
+
420
487
  @pytest.mark.xfail(
421
488
  run=True, reason="Pinecone supports overwriting by default, but it takes a while for it to take effect"
422
489
  )
@@ -452,7 +519,7 @@ class TestDocumentStore(
452
519
  assert "Most similar document" in [result.content for result in results]
453
520
  assert "2nd best document" in [result.content for result in results]
454
521
 
455
- def test_close(self, document_store: PineconeDocumentStore):
522
+ def test_close_and_reopen(self, document_store: PineconeDocumentStore):
456
523
  document_store._initialize_index()
457
524
  assert document_store._index is not None
458
525
 
@@ -461,7 +528,6 @@ class TestDocumentStore(
461
528
 
462
529
  document_store._initialize_index()
463
530
  assert document_store._index is not None
464
- # test that the index is still usable after closing and reopening
465
531
  assert document_store.count_documents() == 0
466
532
 
467
533
  def test_sentence_window_retriever(self, document_store: PineconeDocumentStore):
@@ -475,9 +541,9 @@ class TestDocumentStore(
475
541
 
476
542
  for idx, doc in enumerate(docs["documents"]):
477
543
  if idx == 2:
478
- doc.embedding = [0.1] * 768
544
+ docs["documents"][idx] = replace(doc, embedding=[0.1] * 768)
479
545
  continue
480
- doc.embedding = np.random.rand(768).tolist()
546
+ docs["documents"][idx] = replace(doc, embedding=np.random.rand(768).tolist())
481
547
  document_store.write_documents(docs["documents"])
482
548
 
483
549
  # query
@@ -534,42 +600,6 @@ class TestDocumentStore(
534
600
  # Non-existent field
535
601
  assert document_store.get_metadata_field_min_max("nonexistent") == {"min": None, "max": None}
536
602
 
537
- def test_get_metadata_field_unique_values(self, document_store: PineconeDocumentStore):
538
- docs = [
539
- Document(content="Doc 1", meta={"category": "Alpha"}),
540
- Document(content="Doc 2", meta={"category": "Beta"}),
541
- Document(content="Doc 3", meta={"category": "Gamma"}),
542
- Document(content="Doc 4", meta={"category": "Alpha"}),
543
- Document(content="Doc 5", meta={"category": "Delta"}),
544
- Document(content="Doc 6", meta={"category": "Beta"}),
545
- ]
546
- document_store.write_documents(docs)
547
-
548
- # Get all unique values
549
- values, total = document_store.get_metadata_field_unique_values("category", from_=0, size=10)
550
- assert total == 4 # Alpha, Beta, Delta, Gamma
551
- assert len(values) == 4
552
- assert set(values) == {"Alpha", "Beta", "Delta", "Gamma"}
553
-
554
- # Test pagination
555
- values, total = document_store.get_metadata_field_unique_values("category", from_=0, size=2)
556
- assert total == 4
557
- assert len(values) == 2 # First 2 values (alphabetically sorted)
558
-
559
- values, total = document_store.get_metadata_field_unique_values("category", from_=2, size=2)
560
- assert total == 4
561
- assert len(values) == 2 # Next 2 values
562
-
563
- # Test search term
564
- values, total = document_store.get_metadata_field_unique_values("category", search_term="ta", size=10)
565
- assert total == 2 # Beta and Delta contain "ta"
566
- assert set(values) == {"Beta", "Delta"}
567
-
568
- # Test case-insensitive search
569
- values, total = document_store.get_metadata_field_unique_values("category", search_term="ALPHA", size=10)
570
- assert total == 1
571
- assert values == ["Alpha"]
572
-
573
603
  def test_get_metadata_field_unique_values_with_lists(self, document_store: PineconeDocumentStore):
574
604
  docs = [
575
605
  Document(content="Doc 1", meta={"tags": ["python", "java"]}),
@@ -4,6 +4,7 @@
4
4
 
5
5
  import os
6
6
  from dataclasses import replace
7
+ from unittest.mock import AsyncMock
7
8
 
8
9
  import numpy as np
9
10
  import pytest
@@ -25,11 +26,55 @@ from haystack.testing.document_store_async import (
25
26
  UpdateByFilterAsyncTest,
26
27
  WriteDocumentsAsyncTest,
27
28
  )
29
+ from haystack.utils import Secret
28
30
 
29
31
  from haystack_integrations.components.retrievers.pinecone import PineconeEmbeddingRetriever
30
32
  from haystack_integrations.document_stores.pinecone import PineconeDocumentStore
31
33
 
32
34
 
35
+ @pytest.mark.asyncio
36
+ async def test_close_async():
37
+ document_store = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
38
+ mock_index = AsyncMock()
39
+ document_store._async_index = mock_index
40
+
41
+ await document_store.close_async()
42
+
43
+ mock_index.close.assert_awaited_once()
44
+ assert document_store._async_index is None
45
+
46
+ await document_store.close_async()
47
+ mock_index.close.assert_awaited_once()
48
+
49
+
50
+ @pytest.mark.asyncio
51
+ async def test_close_async_is_exception_safe():
52
+ document_store = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
53
+ mock_index = AsyncMock()
54
+ mock_index.close.side_effect = RuntimeError("boom")
55
+ document_store._async_index = mock_index
56
+
57
+ await document_store.close_async()
58
+
59
+ assert document_store._async_index is None
60
+
61
+
62
+ @pytest.mark.asyncio
63
+ async def test_validation_errors_on_empty_query_and_non_dict_meta():
64
+ ds = PineconeDocumentStore(api_key=Secret.from_token("fake-api-key"))
65
+ filters = {"field": "meta.category", "operator": "==", "value": "A"}
66
+
67
+ with pytest.raises(ValueError, match="query_embedding must be a non-empty list"):
68
+ ds._embedding_retrieval(query_embedding=[])
69
+ with pytest.raises(ValueError, match="query_embedding must be a non-empty list"):
70
+ await ds._embedding_retrieval_async(query_embedding=[])
71
+
72
+ with pytest.raises(ValueError, match="meta must be a dictionary"):
73
+ ds.update_by_filter(filters=filters, meta="not-a-dict")
74
+ with pytest.raises(ValueError, match="meta must be a dictionary"):
75
+ await ds.update_by_filter_async(filters=filters, meta="not-a-dict")
76
+
77
+
33
78
  @pytest.mark.integration
34
79
  @pytest.mark.asyncio
35
80
  @pytest.mark.skipif(not os.environ.get("PINECONE_API_KEY"), reason="PINECONE_API_KEY not set")
@@ -81,6 +126,47 @@ class TestDocumentStoreAsync(
81
126
  docs = [Document(id="1")]
82
127
  assert await document_store.write_documents_async(docs) == 1
83
128
 
129
+ @pytest.mark.asyncio
130
+ async def test_get_metadata_field_unique_values_distinct_types_async(self, document_store: PineconeDocumentStore):
131
+ """
132
+ Override: the base mixin test stores int, float, str and bool under the *same* metadata field
133
+ name and expects all four back as distinct values. Pinecone stores numeric metadata values as
134
+ `float` (see `_convert_meta_to_int`), so an int written for an arbitrary field may come back as
135
+ a numerically equal float instead - collapsing with a genuine float under the same field name
136
+ regardless of which other values share that field.
137
+
138
+ This adapts the same intent - int, float, str and bool must come back as distinct, unmangled
139
+ types via get_metadata_field_unique_values_async() - using one field per type instead of one
140
+ shared field, which is what Pinecone can actually support.
141
+ """
142
+ docs = [
143
+ Document(content="Doc 1", meta={"priority_int": 1}),
144
+ Document(content="Doc 2", meta={"priority_str": "1"}),
145
+ Document(content="Doc 3", meta={"priority_float": 1.5}),
146
+ Document(content="Doc 4", meta={"priority_bool": True}),
147
+ ]
148
+ await document_store.write_documents_async(docs)
149
+
150
+ int_values, int_count = await document_store.get_metadata_field_unique_values_async(
151
+ metadata_field="priority_int"
152
+ )
153
+ str_values, str_count = await document_store.get_metadata_field_unique_values_async(
154
+ metadata_field="priority_str"
155
+ )
156
+ float_values, float_count = await document_store.get_metadata_field_unique_values_async(
157
+ metadata_field="priority_float"
158
+ )
159
+ bool_values, bool_count = await document_store.get_metadata_field_unique_values_async(
160
+ metadata_field="priority_bool"
161
+ )
162
+
163
+ assert (int_count, str_count, float_count, bool_count) == (1, 1, 1, 1)
164
+ assert str_values == ["1"] and type(str_values[0]) is str
165
+ assert float_values == [1.5] and type(float_values[0]) is float
166
+ assert bool_values == [True] and type(bool_values[0]) is bool
167
+ # Pinecone may return a whole-number int as a numerically equal float (see docstring note above).
168
+ assert int_values[0] == 1 and type(int_values[0]) in (int, float)
169
+
84
170
  @pytest.mark.skip(reason="Pinecone only supports UPSERT operations")
85
171
  async def test_write_documents_duplicate_fail_async(self, document_store: PineconeDocumentStore): ...
86
172
 
@@ -114,7 +200,7 @@ class TestDocumentStoreAsync(
114
200
  assert "Most similar document" in [result.content for result in results]
115
201
  assert "2nd best document" in [result.content for result in results]
116
202
 
117
- async def test_close(self, document_store_async: PineconeDocumentStore):
203
+ async def test_close_async_and_reopen(self, document_store_async: PineconeDocumentStore):
118
204
  await document_store_async._initialize_async_index()
119
205
  assert document_store_async._async_index is not None
120
206
 
@@ -123,7 +209,6 @@ class TestDocumentStoreAsync(
123
209
 
124
210
  await document_store_async._initialize_async_index()
125
211
  assert document_store_async._async_index is not None
126
- # test that the index is still usable after closing and reopening
127
212
  assert await document_store_async.count_documents_async() == 0
128
213
 
129
214
  async def test_sentence_window_retriever(self, document_store_async: PineconeDocumentStore):
@@ -137,9 +222,9 @@ class TestDocumentStoreAsync(
137
222
 
138
223
  for idx, doc in enumerate(docs["documents"]):
139
224
  if idx == 2:
140
- doc.embedding = [0.1] * 768
225
+ docs["documents"][idx] = replace(doc, embedding=[0.1] * 768)
141
226
  continue
142
- doc.embedding = np.random.rand(768).tolist()
227
+ docs["documents"][idx] = replace(doc, embedding=np.random.rand(768).tolist())
143
228
  await document_store_async.write_documents_async(docs["documents"])
144
229
 
145
230
  # query
@@ -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
@@ -33,6 +33,28 @@ def test_init_raises_for_non_pinecone_document_store():
33
33
  PineconeEmbeddingRetriever(document_store="not-a-document-store")
34
34
 
35
35
 
36
+ def test_close():
37
+ mock_store = Mock(spec=PineconeDocumentStore)
38
+ retriever = PineconeEmbeddingRetriever(document_store=mock_store)
39
+
40
+ retriever.close()
41
+
42
+ mock_store.close.assert_called_once_with()
43
+ assert retriever.document_store is mock_store
44
+
45
+
46
+ @pytest.mark.asyncio
47
+ async def test_close_async():
48
+ mock_store = Mock(spec=PineconeDocumentStore)
49
+ mock_store.close_async = AsyncMock()
50
+ retriever = PineconeEmbeddingRetriever(document_store=mock_store)
51
+
52
+ await retriever.close_async()
53
+
54
+ mock_store.close_async.assert_awaited_once_with()
55
+ assert retriever.document_store is mock_store
56
+
57
+
36
58
  @patch("haystack_integrations.document_stores.pinecone.document_store.Pinecone")
37
59
  def test_to_dict(mock_pinecone, monkeypatch):
38
60
  monkeypatch.setenv("PINECONE_API_KEY", "env-api-key")