From daf3f10bf78a84e3a23308395a1b720097f7c0dd Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 16:31:21 +0100 Subject: [PATCH 01/18] adding FAISS github workflow --- .github/workflows/faiss.yml | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/faiss.yml diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml new file mode 100644 index 0000000000..ffb142c8bd --- /dev/null +++ b/.github/workflows/faiss.yml @@ -0,0 +1,74 @@ +# This workflow comes from https://github.com/ofek/hatch-mypyc +# https://github.com/ofek/hatch-mypyc/blob/5a198c0ba8660494d02716cfc9d79ce4adfb1442/.github/workflows/test.yml +name: Test / faiss + +on: + schedule: + - cron: "0 0 * * *" + pull_request: + paths: + - "integrations/faiss/**" + - "!integrations/faiss/*.md" + - ".github/workflows/faiss.yml" + +concurrency: + group: faiss-${{ github.head_ref }} + cancel-in-progress: true + +env: + PYTHONUNBUFFERED: "1" + FORCE_COLOR: "1" + +defaults: + run: + working-directory: integrations/faiss + +jobs: + run: + name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # FAISS wheels are most reliable on Linux in CI. + os: [ubuntu-latest] + python-version: ["3.10", "3.13"] + + steps: + - uses: actions/checkout@v6 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Hatch + uses: pypa/hatch@install + + - name: Lint + if: matrix.python-version == '3.10' && runner.os == 'Linux' + run: hatch run fmt-check && hatch run test:types + + - name: Run tests + run: hatch run test:cov-retry + + - name: Run unit tests with lowest direct dependencies + run: | + hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt + hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt + hatch run test:unit + + - name: Nightly - run unit tests with Haystack main branch + if: github.event_name == 'schedule' + run: | + hatch env prune + hatch -e test env run -- uv pip install git+https://github.com/deepset-ai/haystack.git@main + hatch run test:unit + + - name: Send event to Datadog for nightly failures + if: failure() && github.event_name == 'schedule' + uses: ./.github/actions/send_failure + with: + title: | + Core integrations nightly tests failure: ${{ github.workflow }} + api-key: ${{ secrets.CORE_DATADOG_API_KEY }} From 09e553f7ac8e4dc259c3a332fbe7495f7df50000 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 16:33:38 +0100 Subject: [PATCH 02/18] adding win and mac to matrix --- .github/workflows/faiss.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index ffb142c8bd..0993b5ff74 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -31,7 +31,7 @@ jobs: fail-fast: false matrix: # FAISS wheels are most reliable on Linux in CI. - os: [ubuntu-latest] + os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.10", "3.13"] steps: From 206a50f5bd73c2e7e8e9d6fe31db62d983e40b05 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 16:34:29 +0100 Subject: [PATCH 03/18] reformatting files --- .../components/retrievers/faiss/embedding_retriever.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/faiss/src/haystack_integrations/components/retrievers/faiss/embedding_retriever.py b/integrations/faiss/src/haystack_integrations/components/retrievers/faiss/embedding_retriever.py index fb918cf383..fde48d7bf1 100644 --- a/integrations/faiss/src/haystack_integrations/components/retrievers/faiss/embedding_retriever.py +++ b/integrations/faiss/src/haystack_integrations/components/retrievers/faiss/embedding_retriever.py @@ -50,7 +50,7 @@ class FAISSEmbeddingRetriever: assert res["retriever"]["documents"][0].content == "There are over 7,000 languages spoken around the world today." ``` - """ # noqa: E501 + """ # noqa: E501 def __init__( self, From 4a280984c8b238c1c82380ed31ba6a51cc9bd965 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 16:36:35 +0100 Subject: [PATCH 04/18] adding py.typed --- .../haystack_integrations/components/retrievers/faiss/py.typed | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 integrations/faiss/src/haystack_integrations/components/retrievers/faiss/py.typed diff --git a/integrations/faiss/src/haystack_integrations/components/retrievers/faiss/py.typed b/integrations/faiss/src/haystack_integrations/components/retrievers/faiss/py.typed new file mode 100644 index 0000000000..e69de29bb2 From 7d181252f8bf8c3ef118ff2d39f4fba280cd5bae Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 16:50:21 +0100 Subject: [PATCH 05/18] adding safeguard to check for index before operations that need the index --- .../document_stores/faiss/document_store.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py b/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py index fc78f19cd6..2252c98508 100644 --- a/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py +++ b/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py @@ -9,7 +9,7 @@ from pathlib import Path from typing import Any -import faiss +import faiss # type: ignore[import-untyped] import numpy as np from haystack import default_from_dict, default_to_dict from haystack.dataclasses import Document @@ -68,6 +68,13 @@ def _create_new_index(self): msg = f"Could not create FAISS index with factory string '{self.index_string}': {e}" raise DocumentStoreError(msg) from e + def _get_index_or_raise(self) -> Any: + """Return the FAISS index or raise if it is unexpectedly missing.""" + if self.index is None: + msg = "FAISS index has not been initialized." + raise DocumentStoreError(msg) + return self.index + def count_documents(self) -> int: """ Returns the number of documents in the store. @@ -175,7 +182,8 @@ def write_documents(self, documents: list[Document], policy: DuplicatePolicy = D if vectors_to_add: vectors = np.array(vectors_to_add, dtype="float32") ids = np.array(ids_to_add_to_index, dtype="int64") - self.index.add_with_ids(vectors, ids) + index = self._get_index_or_raise() + index.add_with_ids(vectors, ids) return docs_written @@ -197,9 +205,10 @@ def delete_documents(self, document_ids: list[str]) -> None: del self.id_map[int_id] ids_to_remove_from_index.append(int_id) - if ids_to_remove_from_index and self.index.ntotal > 0: + index = self._get_index_or_raise() + if ids_to_remove_from_index and index.ntotal > 0: ids_array = np.array(ids_to_remove_from_index, dtype="int64") - self.index.remove_ids(ids_array) + index.remove_ids(ids_array) def delete_all_documents(self) -> None: """ @@ -301,6 +310,9 @@ def _check_condition(self, doc: Document, condition: dict[str, Any]) -> bool: msg = "Missing 'field' in filter condition" raise FilterError(msg) field = condition.get("field") + if not isinstance(field, str): + msg = "'field' in filter condition must be a string" + raise FilterError(msg) if "value" not in condition: msg = "Missing 'value' in filter condition" raise FilterError(msg) @@ -507,7 +519,7 @@ def save(self, index_path: str | Path) -> None: Saves the index and documents to disk. """ path = Path(index_path) - faiss.write_index(self.index, str(path.with_suffix(".faiss"))) + faiss.write_index(self._get_index_or_raise(), str(path.with_suffix(".faiss"))) # Save documents and ID mapping data = { From ff58aba382de8ed95caa4179123228efbaf5fb08 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 16:59:15 +0100 Subject: [PATCH 06/18] pinning numpy --- integrations/faiss/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 5646508a95..044ce9bd92 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", - "numpy", + "numpy==1.3.0", ] [project.urls] From 835abecad6be3c72155570c275ff1d1ded64be4f Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 17:12:16 +0100 Subject: [PATCH 07/18] pinning numpy --- integrations/faiss/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 044ce9bd92..79cf73ed31 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", - "numpy==1.3.0", + "numpy==2.0.0", ] [project.urls] From 76e7ca9cb6f0cac6e7c24013ea53016568618a85 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 17:14:54 +0100 Subject: [PATCH 08/18] pinning numpy --- .github/workflows/faiss.yml | 2 +- integrations/faiss/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index 0993b5ff74..3676c1fd7f 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -31,7 +31,7 @@ jobs: fail-fast: false matrix: # FAISS wheels are most reliable on Linux in CI. - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest] #[ubuntu-latest, windows-latest, macos-latest] python-version: ["3.10", "3.13"] steps: diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 79cf73ed31..717747c9f3 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", - "numpy==2.0.0", + "numpy>2", ] [project.urls] From 53a8df1ce82d1409116bf183f596a14a35262baf Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 17:18:05 +0100 Subject: [PATCH 09/18] removing numpy, making dependent on faiss-cpu --- integrations/faiss/pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 717747c9f3..5d0006ded7 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,7 +24,6 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", - "numpy>2", ] [project.urls] From 64cd7171000839cd39fae895f41c4ae2fadef0d3 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 23:26:50 +0100 Subject: [PATCH 10/18] trying to fix lowest direct dependencies run --- .github/workflows/faiss.yml | 1 + integrations/faiss/pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index 3676c1fd7f..8e609687dd 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -53,6 +53,7 @@ jobs: run: hatch run test:cov-retry - name: Run unit tests with lowest direct dependencies + if: matrix.python-version == '3.10' && runner.os == 'Linux' run: | hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 5d0006ded7..3bfe564f49 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,6 +24,7 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", + "numpy<2; python_version < '3.13'", ] [project.urls] From b9ea99cfd78f35327275d23ec6166dec2b4e4dc8 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Thu, 26 Feb 2026 23:28:32 +0100 Subject: [PATCH 11/18] temporary disable lowest direct dependencies run --- .github/workflows/faiss.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index 8e609687dd..d688f7193e 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -52,12 +52,12 @@ jobs: - name: Run tests run: hatch run test:cov-retry - - name: Run unit tests with lowest direct dependencies - if: matrix.python-version == '3.10' && runner.os == 'Linux' - run: | - hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt - hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt - hatch run test:unit + #- name: Run unit tests with lowest direct dependencies + # if: matrix.python-version == '3.10' && runner.os == 'Linux' + # run: | + # hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt + # hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt + # hatch run test:unit - name: Nightly - run unit tests with Haystack main branch if: github.event_name == 'schedule' From c31d2f8435cfdb1483d77714a54eb4b41de245dc Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 12:02:21 +0100 Subject: [PATCH 12/18] debugging: unit tests with lowest direct dependencies --- .github/workflows/faiss.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index d688f7193e..8e609687dd 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -52,12 +52,12 @@ jobs: - name: Run tests run: hatch run test:cov-retry - #- name: Run unit tests with lowest direct dependencies - # if: matrix.python-version == '3.10' && runner.os == 'Linux' - # run: | - # hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt - # hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt - # hatch run test:unit + - name: Run unit tests with lowest direct dependencies + if: matrix.python-version == '3.10' && runner.os == 'Linux' + run: | + hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt + hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt + hatch run test:unit - name: Nightly - run unit tests with Haystack main branch if: github.event_name == 'schedule' From a0756ae4d8029f090d3f7106728bad7666073a83 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 12:22:44 +0100 Subject: [PATCH 13/18] debugging: unit tests with lowest direct dependencies --- integrations/faiss/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 3bfe564f49..211d42c17d 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", - "numpy<2; python_version < '3.13'", + "numpy>=1.21.6,<2; python_version < '3.13'", ] [project.urls] From f4e6c9debd7ca7749fb66cffa21594771bef6bd8 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 12:29:01 +0100 Subject: [PATCH 14/18] debugging: unit tests with lowest direct dependencies --- .github/workflows/faiss.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index 8e609687dd..9d831677a3 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -55,6 +55,7 @@ jobs: - name: Run unit tests with lowest direct dependencies if: matrix.python-version == '3.10' && runner.os == 'Linux' run: | + hatch env prune hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt hatch run test:unit From 1c8d4b58a15d1561f0899d2f3f2238f37e7b7e4c Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 12:40:49 +0100 Subject: [PATCH 15/18] debugging: unit tests with lowest direct dependencies --- .github/workflows/faiss.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index 9d831677a3..58ff857213 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -18,6 +18,7 @@ concurrency: env: PYTHONUNBUFFERED: "1" FORCE_COLOR: "1" + HATCH_PYTHON: "python" defaults: run: From c088a48c7ccca1174075be740df9f3bc9b617715 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 12:41:51 +0100 Subject: [PATCH 16/18] debugging: unit tests with lowest direct dependencies - pinning virtualenv --- .github/workflows/faiss.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/faiss.yml b/.github/workflows/faiss.yml index 58ff857213..f78bf2b586 100644 --- a/.github/workflows/faiss.yml +++ b/.github/workflows/faiss.yml @@ -18,7 +18,6 @@ concurrency: env: PYTHONUNBUFFERED: "1" FORCE_COLOR: "1" - HATCH_PYTHON: "python" defaults: run: @@ -44,7 +43,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Hatch - uses: pypa/hatch@install + run: pip install hatch "virtualenv<21.0.0" - name: Lint if: matrix.python-version == '3.10' && runner.os == 'Linux' From c003271c347cc2c18eca0d5fc7d938f103999a41 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 12:45:40 +0100 Subject: [PATCH 17/18] debugging: unit tests with lowest direct dependencies - pinning virtualenv --- integrations/faiss/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/faiss/pyproject.toml b/integrations/faiss/pyproject.toml index 211d42c17d..016f26822f 100644 --- a/integrations/faiss/pyproject.toml +++ b/integrations/faiss/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ dependencies = [ "haystack-ai>=2.24.0", "faiss-cpu>=1.8.0", - "numpy>=1.21.6,<2; python_version < '3.13'", + "numpy>=1.22,<2; python_version < '3.13'", ] [project.urls] From 421896b0b5d7a5dd6723e57059e46cb5490b30b0 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Fri, 27 Feb 2026 14:03:37 +0100 Subject: [PATCH 18/18] adding execptions to docstrings --- .../document_stores/faiss/document_store.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py b/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py index 2252c98508..050a4929aa 100644 --- a/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py +++ b/integrations/faiss/src/haystack_integrations/document_stores/faiss/document_store.py @@ -40,6 +40,8 @@ def __init__( :param index_path: Path to save/load the index and documents. If None, the store is in-memory only. :param index_string: The FAISS index factory string. Default is "Flat". :param embedding_dim: The dimension of the embeddings. Default is 768. + :raises DocumentStoreError: If the FAISS index cannot be initialized. + :raises ValueError: If `index_path` points to a missing `.faiss` file when loading persisted data. """ self.index_path = index_path self.embedding_dim = embedding_dim @@ -87,6 +89,7 @@ def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Docume :param filters: A dictionary of filters to apply. :return: A list of matching Documents. + :raises FilterError: If the filter structure is invalid. """ if not filters: return list(self.documents.values()) @@ -127,6 +130,9 @@ def write_documents(self, documents: list[Document], policy: DuplicatePolicy = D :param documents: The list of documents to write. :param policy: The policy to handle duplicate documents. :return: The number of documents written. + :raises ValueError: If `documents` is not an iterable of `Document` objects. + :raises DuplicateDocumentError: If a duplicate document is found and `policy` is `DuplicatePolicy.FAIL`. + :raises DocumentStoreError: If the FAISS index is unexpectedly unavailable when adding embeddings. """ if not isinstance(documents, Iterable) or isinstance(documents, (str, bytes)): msg = "param 'documents' must contain an iterable of objects of type Document." @@ -190,6 +196,8 @@ def write_documents(self, documents: list[Document], policy: DuplicatePolicy = D def delete_documents(self, document_ids: list[str]) -> None: """ Deletes documents from the store. + + :raises DocumentStoreError: If the FAISS index is unexpectedly unavailable when removing embeddings. """ if not document_ids: return @@ -230,6 +238,7 @@ def search( :param top_k: The number of results to return. :param filters: Filters to apply. :return: A list of matching Documents. + :raises FilterError: If the filter structure is invalid. """ if not self.index or self.index.ntotal == 0: return [] @@ -382,6 +391,8 @@ def delete_by_filter(self, filters: dict[str, Any]) -> int: :param filters: A dictionary of filters to apply to find documents to delete. :returns: The number of documents deleted. + :raises FilterError: If the filter structure is invalid. + :raises DocumentStoreError: If the FAISS index is unexpectedly unavailable when removing embeddings. """ docs_to_delete = self.filter_documents(filters) ids = [doc.id for doc in docs_to_delete] @@ -394,6 +405,7 @@ def count_documents_by_filter(self, filters: dict[str, Any]) -> int: :param filters: A dictionary of filters to apply. :returns: The number of matching documents. + :raises FilterError: If the filter structure is invalid. """ return len(self.filter_documents(filters)) @@ -407,6 +419,7 @@ def update_by_filter(self, filters: dict[str, Any], meta: dict[str, Any]) -> int :param filters: A dictionary of filters to apply to find documents to update. :param meta: A dictionary of metadata key-value pairs to update in the matching documents. :returns: The number of documents updated. + :raises FilterError: If the filter structure is invalid. """ docs_to_update = self.filter_documents(filters) for doc in docs_to_update: @@ -517,6 +530,8 @@ def from_dict(cls, data: dict[str, Any]) -> "FAISSDocumentStore": def save(self, index_path: str | Path) -> None: """ Saves the index and documents to disk. + + :raises DocumentStoreError: If the FAISS index is unexpectedly unavailable. """ path = Path(index_path) faiss.write_index(self._get_index_or_raise(), str(path.with_suffix(".faiss"))) @@ -535,6 +550,8 @@ def save(self, index_path: str | Path) -> None: def load(self, index_path: str | Path) -> None: """ Loads the index and documents from disk. + + :raises ValueError: If the `.faiss` file does not exist. """ path = Path(index_path) if not path.with_suffix(".faiss").exists():