faiss-haystack 2.0.0__tar.gz → 3.0.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 (16) hide show
  1. faiss_haystack-3.0.0/CHANGELOG.md +52 -0
  2. faiss_haystack-3.0.0/LICENSE.txt +201 -0
  3. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/PKG-INFO +9 -6
  4. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/README.md +3 -1
  5. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/pyproject.toml +7 -4
  6. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/src/haystack_integrations/components/retrievers/faiss/embedding_retriever.py +3 -2
  7. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/src/haystack_integrations/document_stores/faiss/document_store.py +52 -27
  8. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/tests/test_document_store.py +53 -1
  9. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/tests/test_embedding_retriever.py +6 -4
  10. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/.gitignore +0 -0
  11. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/pydoc/config_docusaurus.yml +0 -0
  12. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/src/haystack_integrations/components/retrievers/faiss/__init__.py +0 -0
  13. {faiss_haystack-2.0.0/src/haystack_integrations/components/retrievers/faiss → faiss_haystack-3.0.0/src/haystack_integrations/components/retrievers}/py.typed +0 -0
  14. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/src/haystack_integrations/document_stores/faiss/__init__.py +0 -0
  15. {faiss_haystack-2.0.0/src/haystack_integrations/document_stores/faiss → faiss_haystack-3.0.0/src/haystack_integrations/document_stores}/py.typed +0 -0
  16. {faiss_haystack-2.0.0 → faiss_haystack-3.0.0}/tests/__init__.py +0 -0
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ ## [integrations/faiss-v2.1.0] - 2026-09-01
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - Fix new issues raised by ruff 0.16.0 (#3670)
8
+ - `FAISSDocumentStore` with `search_term`, pagination and returning `(values, total_count)` (#3682)
9
+ - `FAISSDocumentStore` get_metadata_field_unique_values setting list of values to return to `Any` (#3704)
10
+ - `FAISSDocumentStore` adding filter to unique metadata values (#3753)
11
+ - Standardize license files (#3771)
12
+
13
+ ### 📚 Documentation
14
+
15
+ - Replace old haystack core imports with haystack_integrations paths (#3545)
16
+
17
+ ### 🧪 Testing
18
+
19
+ - Track test coverage for all integrations (#3065)
20
+ - Mark some tests as integration in Faiss and Qdrant (#3076)
21
+ - Faiss - add unit tests (#3213)
22
+ - `FAISSDocumentStore` removing duplicated tests already covered by haystack Mixin tests (#3778)
23
+
24
+ ### 🧹 Chores
25
+
26
+ - Improve consistency of integrations folder structure (#3430)
27
+ - Re-standardize READMEs (#3768)
28
+
29
+
30
+ ## [integrations/faiss-v2.0.0] - 2026-03-23
31
+
32
+ ### 🧪 Testing
33
+
34
+ - Test compatible integrations with python 3.14; update pyproject (#3001)
35
+ - `FaissDocumentStore` use Mixin tests (#3024)
36
+
37
+ ### ⚙️ CI
38
+
39
+ - Adding FAISS github workflow (#2879)
40
+
41
+ ### 🧹 Chores
42
+
43
+ - FAISS - small changes to improve consistency with the codebase (#2890)
44
+ - Standardize author mentions (#2897)
45
+ - Add ANN type annotations to faiss, fastembed, firecrawl, github, google_ai (#2988)
46
+ - Enforce ruff docstring rules (D102/D103/D205/D209/D213/D417/D419) in integrations 11-20 (#3009)
47
+
48
+ ### 🌀 Miscellaneous
49
+
50
+ - Add FAISS DocumentStore integration (#2844)
51
+
52
+ <!-- generated by git-cliff -->
@@ -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,26 +1,27 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: faiss-haystack
3
- Version: 2.0.0
3
+ Version: 3.0.0
4
4
  Summary: An integration of FAISS (library for efficient similarity search of dense vectors) with Haystack
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/faiss#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
7
7
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/faiss
8
8
  Author-email: deepset GmbH <info@deepset.ai>
9
9
  License-Expression: Apache-2.0
10
+ License-File: LICENSE.txt
10
11
  Classifier: Development Status :: 4 - Beta
11
12
  Classifier: License :: OSI Approved :: Apache Software License
12
13
  Classifier: Programming Language :: Python
13
- Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
18
19
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
20
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
- Requires-Python: >=3.10
21
+ Requires-Python: >=3.11
21
22
  Requires-Dist: faiss-cpu>=1.8.0
22
23
  Requires-Dist: haystack-ai>=2.26.1
23
- Requires-Dist: numpy<2,>=1.22; python_version < '3.13'
24
+ Requires-Dist: numpy<2,>=1.23.2; python_version < '3.13'
24
25
  Description-Content-Type: text/markdown
25
26
 
26
27
  # faiss-haystack
@@ -28,9 +29,11 @@ Description-Content-Type: text/markdown
28
29
  [![PyPI - Version](https://img.shields.io/pypi/v/faiss-haystack.svg)](https://pypi.org/project/faiss-haystack)
29
30
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/faiss-haystack.svg)](https://pypi.org/project/faiss-haystack)
30
31
 
31
- - [Integration page](https://haystack.deepset.ai/integrations/faiss-documentstore)
32
+ - [Integration page](https://haystack.deepset.ai/integrations/faiss)
32
33
  - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/faiss/CHANGELOG.md)
33
34
 
34
35
  ---
35
36
 
37
+ ## Contributing
38
+
36
39
  Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
@@ -3,9 +3,11 @@
3
3
  [![PyPI - Version](https://img.shields.io/pypi/v/faiss-haystack.svg)](https://pypi.org/project/faiss-haystack)
4
4
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/faiss-haystack.svg)](https://pypi.org/project/faiss-haystack)
5
5
 
6
- - [Integration page](https://haystack.deepset.ai/integrations/faiss-documentstore)
6
+ - [Integration page](https://haystack.deepset.ai/integrations/faiss)
7
7
  - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/faiss/CHANGELOG.md)
8
8
 
9
9
  ---
10
10
 
11
+ ## Contributing
12
+
11
13
  Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
@@ -7,7 +7,7 @@ name = "faiss-haystack"
7
7
  dynamic = ["version"]
8
8
  description = 'An integration of FAISS (library for efficient similarity search of dense vectors) with Haystack'
9
9
  readme = "README.md"
10
- requires-python = ">=3.10"
10
+ requires-python = ">=3.11"
11
11
  license = "Apache-2.0"
12
12
  keywords = []
13
13
  authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
@@ -15,18 +15,18 @@ classifiers = [
15
15
  "License :: OSI Approved :: Apache Software License",
16
16
  "Development Status :: 4 - Beta",
17
17
  "Programming Language :: Python",
18
- "Programming Language :: Python :: 3.10",
19
18
  "Programming Language :: Python :: 3.11",
20
19
  "Programming Language :: Python :: 3.12",
21
20
  "Programming Language :: Python :: 3.13",
22
21
  "Programming Language :: Python :: 3.14",
22
+ "Programming Language :: Python :: 3.15",
23
23
  "Programming Language :: Python :: Implementation :: CPython",
24
24
  "Programming Language :: Python :: Implementation :: PyPy",
25
25
  ]
26
26
  dependencies = [
27
27
  "haystack-ai>=2.26.1",
28
28
  "faiss-cpu>=1.8.0",
29
- "numpy>=1.22,<2; python_version < '3.13'",
29
+ "numpy>=1.23.2,<2; python_version < '3.13'",
30
30
  ]
31
31
 
32
32
  [project.urls]
@@ -68,7 +68,8 @@ dependencies = [
68
68
  unit = 'pytest -m "not integration" {args:tests}'
69
69
  integration = 'pytest -m "integration" {args:tests}'
70
70
  all = 'pytest {args:tests}'
71
- cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
71
+ unit-cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x -m "not integration" {args:tests}'
72
+ integration-cov-append-retry = 'pytest --cov=haystack_integrations --cov-append --reruns 3 --reruns-delay 30 -x -m "integration" {args:tests}'
72
73
 
73
74
  types = "mypy -p haystack_integrations.document_stores.faiss -p haystack_integrations.components.retrievers.faiss {args}"
74
75
 
@@ -139,6 +140,7 @@ ignore = [
139
140
  "PLR0912",
140
141
  "PLR0913",
141
142
  "PLR0915",
143
+ "PLR0917",
142
144
  # Ignore unused params
143
145
  "ARG002",
144
146
  # Allow assertions
@@ -162,6 +164,7 @@ ban-relative-imports = "parents"
162
164
  [tool.coverage.run]
163
165
  source = ["haystack_integrations"]
164
166
  branch = true
167
+ relative_files = true
165
168
  parallel = false
166
169
 
167
170
 
@@ -20,7 +20,9 @@ class FAISSEmbeddingRetriever:
20
20
  Example usage:
21
21
  ```python
22
22
  from haystack import Document, Pipeline
23
- from haystack.components.embedders import SentenceTransformersTextEmbedder, SentenceTransformersDocumentEmbedder
23
+ # Requires: pip install sentence-transformers-haystack
24
+ from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersTextEmbedder
25
+ from haystack_integrations.components.embedders.sentence_transformers import SentenceTransformersDocumentEmbedder
24
26
  from haystack.document_stores.types import DuplicatePolicy
25
27
 
26
28
  from haystack_integrations.document_stores.faiss import FAISSDocumentStore
@@ -35,7 +37,6 @@ class FAISSEmbeddingRetriever:
35
37
  ]
36
38
 
37
39
  document_embedder = SentenceTransformersDocumentEmbedder()
38
- document_embedder.warm_up()
39
40
  documents_with_embeddings = document_embedder.run(documents)["documents"]
40
41
 
41
42
  document_store.write_documents(documents_with_embeddings, policy=DuplicatePolicy.OVERWRITE)
@@ -3,14 +3,13 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  import json
6
- import logging
7
6
  from collections.abc import Iterable
8
7
  from dataclasses import replace
9
8
  from pathlib import Path
10
9
  from typing import Any
11
10
 
12
11
  import numpy as np
13
- from haystack import default_from_dict, default_to_dict
12
+ from haystack import default_from_dict, default_to_dict, logging
14
13
  from haystack.dataclasses import Document
15
14
  from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError
16
15
  from haystack.document_stores.types import DuplicatePolicy
@@ -458,11 +457,7 @@ class FAISSDocumentStore:
458
457
  """
459
458
  values = []
460
459
  for doc in self.documents.values():
461
- val = (
462
- FAISSDocumentStore._get_doc_value(doc, field_name)
463
- if not field_name.startswith("meta.")
464
- else doc.meta.get(field_name[5:])
465
- )
460
+ val = FAISSDocumentStore._get_doc_value(doc, field_name)
466
461
  if val is not None:
467
462
  values.append(val)
468
463
 
@@ -471,23 +466,51 @@ class FAISSDocumentStore:
471
466
 
472
467
  return {"min": min(values), "max": max(values)}
473
468
 
474
- def get_metadata_field_unique_values(self, field_name: str) -> list[Any]:
475
- """
476
- Returns all unique values for a specific metadata field.
477
-
478
- :param field_name: The name of the metadata field.
479
- :returns: A list of unique values for the specified field.
469
+ def get_metadata_field_unique_values(
470
+ self,
471
+ metadata_field: str,
472
+ search_term: str | None = None,
473
+ from_: int = 0,
474
+ size: int = 10,
475
+ filters: dict[str, Any] | None = None,
476
+ ) -> tuple[list[Any], int]:
477
+ """
478
+ Returns unique values for a metadata field, optionally filtered by a search term, with pagination.
479
+
480
+ :param metadata_field: The metadata field to get unique values for. Can include or omit the "meta." prefix.
481
+ :param search_term: Optional search term to filter values, matched as a case-insensitive substring
482
+ against the metadata field's value.
483
+ :param from_: The offset to start returning values from (for pagination).
484
+ :param size: The maximum number of unique values to return.
485
+ :param filters: Optional filters to restrict the documents considered.
486
+ :returns: A tuple containing list of unique values (in their original type) and total count of
487
+ unique values.
480
488
  """
481
- values = set()
482
- for doc in self.documents.values():
483
- val = (
484
- FAISSDocumentStore._get_doc_value(doc, field_name)
485
- if not field_name.startswith("meta.")
486
- else doc.meta.get(field_name[5:])
487
- )
489
+ values = []
490
+ for doc in self.filter_documents(filters=filters):
491
+ val = FAISSDocumentStore._get_doc_value(doc, metadata_field)
488
492
  if val is not None:
489
- values.add(val)
490
- return list(values)
493
+ values.append(val)
494
+
495
+ if search_term:
496
+ search_term_lower = search_term.lower()
497
+ values = [val for val in values if search_term_lower in str(val).lower()]
498
+
499
+ # Values of different types can be equal in Python (`1 == True`, `1 == 1.0`), so a plain set
500
+ # would silently merge them. Dedupe by (type, value) instead to keep them distinct.
501
+ seen: set[tuple[type, Any]] = set()
502
+ unique_values = []
503
+ for val in values:
504
+ dedup_key = (type(val), val)
505
+ if dedup_key not in seen:
506
+ seen.add(dedup_key)
507
+ unique_values.append(val)
508
+ sorted_values = sorted(unique_values, key=str)
509
+ total_count = len(sorted_values)
510
+ end = from_ + size
511
+ paginated_values = sorted_values[from_:end]
512
+
513
+ return paginated_values, total_count
491
514
 
492
515
  def count_unique_metadata_by_filter(self, filters: dict[str, Any], metadata_fields: list[str]) -> dict[str, int]:
493
516
  """
@@ -501,11 +524,13 @@ class FAISSDocumentStore:
501
524
  counts = {}
502
525
 
503
526
  for field in metadata_fields:
504
- unique_vals = set()
527
+ # Values of different types can be equal in Python (`1 == True`, `1 == 1.0`), so a plain
528
+ # set would silently merge them. Dedupe by (type, value) instead to keep them distinct.
529
+ unique_vals: set[tuple[type, Any]] = set()
505
530
  for doc in filtered_docs:
506
531
  val = FAISSDocumentStore._get_doc_value(doc, field)
507
532
  if val is not None:
508
- unique_vals.add(val)
533
+ unique_vals.add((type(val), val))
509
534
  counts[field] = len(unique_vals)
510
535
 
511
536
  return dict(counts)
@@ -573,7 +598,7 @@ class FAISSDocumentStore:
573
598
  # Verify sync
574
599
  if len(self.documents) != len(self.id_map):
575
600
  logger.warning(
576
- "Loaded %d documents but %d ID mappings. Index might be out of sync.",
577
- len(self.documents),
578
- len(self.id_map),
601
+ "Loaded {documents_count} documents but {mappings_count} ID mappings. Index might be out of sync.",
602
+ documents_count=len(self.documents),
603
+ mappings_count=len(self.id_map),
579
604
  )
@@ -4,6 +4,8 @@
4
4
 
5
5
  import pytest
6
6
  from haystack.dataclasses import Document
7
+ from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError
8
+ from haystack.document_stores.types import DuplicatePolicy
7
9
  from haystack.errors import FilterError
8
10
  from haystack.testing.document_store import (
9
11
  CountDocumentsByFilterTest,
@@ -22,6 +24,54 @@ from haystack.testing.document_store import (
22
24
  from haystack_integrations.document_stores.faiss import FAISSDocumentStore
23
25
 
24
26
 
27
+ class TestFAISSDocumentStoreUnit:
28
+ def test_create_new_index_with_invalid_factory_raises(self):
29
+ with pytest.raises(DocumentStoreError, match="Could not create FAISS index"):
30
+ FAISSDocumentStore(index_string="NotARealIndex", embedding_dim=3)
31
+
32
+ def test_get_index_or_raise_when_index_is_none(self):
33
+ ds = FAISSDocumentStore(embedding_dim=3)
34
+ ds.index = None
35
+ with pytest.raises(DocumentStoreError, match="FAISS index has not been initialized"):
36
+ ds._get_index_or_raise()
37
+
38
+ @pytest.mark.parametrize(
39
+ "bad_input",
40
+ [
41
+ "a string",
42
+ b"some bytes",
43
+ 123,
44
+ [Document(content="ok"), "not a document"],
45
+ ],
46
+ )
47
+ def test_write_documents_rejects_invalid_input(self, bad_input):
48
+ ds = FAISSDocumentStore(embedding_dim=3)
49
+ with pytest.raises(ValueError, match="iterable of objects of type Document"):
50
+ ds.write_documents(bad_input)
51
+
52
+ def test_write_documents_fail_policy_raises_on_duplicate(self):
53
+ ds = FAISSDocumentStore(embedding_dim=3)
54
+ ds.write_documents([Document(id="dup", content="first")])
55
+ with pytest.raises(DuplicateDocumentError, match="already exists"):
56
+ ds.write_documents([Document(id="dup", content="second")], policy=DuplicatePolicy.FAIL)
57
+
58
+ @pytest.mark.parametrize(
59
+ ("filters", "error_match"),
60
+ [
61
+ ({"operator": "OR"}, "Missing 'conditions' for OR operator"),
62
+ ({"operator": "AND"}, "Missing 'conditions' for AND operator"),
63
+ ({"operator": "NOT"}, "Missing 'conditions' for NOT operator"),
64
+ ({"operator": "==", "field": 42, "value": "x"}, "'field' in filter condition must be a string"),
65
+ ],
66
+ )
67
+ def test_check_condition_invalid_structure_raises_filter_error(self, filters, error_match):
68
+ ds = FAISSDocumentStore(embedding_dim=3)
69
+ ds.write_documents([Document(content="test", meta={"category": "A"})])
70
+ with pytest.raises(FilterError, match=error_match):
71
+ ds.filter_documents(filters=filters)
72
+
73
+
74
+ @pytest.mark.integration
25
75
  class TestFAISSDocumentStore(
26
76
  CountDocumentsTest,
27
77
  DeleteDocumentsTest,
@@ -60,7 +110,6 @@ class TestFAISSDocumentStore(
60
110
  assert ds_loaded.filter_documents()[0].embedding == [0.1, 0.2, 0.3]
61
111
 
62
112
  def test_persistence_no_embeddings(self, tmp_path):
63
-
64
113
  path = tmp_path / "persistent_index_no_embed"
65
114
  ds = FAISSDocumentStore(index_path=str(path), embedding_dim=3)
66
115
 
@@ -119,3 +168,6 @@ class TestFAISSDocumentStore(
119
168
  document_store.write_documents([Document(content="test", meta={"category": "A"})])
120
169
  with pytest.raises(FilterError, match="NOT operator expects at least one condition"):
121
170
  document_store.filter_documents(filters={"operator": "NOT", "conditions": []})
171
+
172
+ # get_metadata_field_unique_values behavior (search term, pagination, meta-prefix handling, non-string
173
+ # type preservation, filter restriction) is covered by the inherited GetMetadataFieldUniqueValuesTest mixin.
@@ -31,6 +31,12 @@ def populated_store(document_store):
31
31
  return document_store
32
32
 
33
33
 
34
+ def test_invalid_document_store_type():
35
+ with pytest.raises(ValueError, match="document_store must be an instance of FAISSDocumentStore"):
36
+ FAISSEmbeddingRetriever(document_store="not_a_store") # type: ignore[arg-type]
37
+
38
+
39
+ @pytest.mark.integration
34
40
  class TestFAISSEmbeddingRetriever:
35
41
  def test_run_with_query_embedding_only(self, populated_store):
36
42
  retriever = FAISSEmbeddingRetriever(document_store=populated_store, top_k=2)
@@ -112,10 +118,6 @@ class TestFAISSEmbeddingRetriever:
112
118
  assert len(result["documents"]) >= 1
113
119
  assert all(d.meta["category"] == "A" for d in result["documents"])
114
120
 
115
- def test_invalid_document_store_type(self):
116
- with pytest.raises(ValueError, match="document_store must be an instance of FAISSDocumentStore"):
117
- FAISSEmbeddingRetriever(document_store="not_a_store") # type: ignore[arg-type]
118
-
119
121
  def test_run_in_pipeline(self, populated_store):
120
122
  """End-to-end: FAISSEmbeddingRetriever wired into a Haystack Pipeline."""
121
123
  retriever = FAISSEmbeddingRetriever(document_store=populated_store, top_k=2)