diff --git a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/_filters.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/_filters.py index f0264098a..f397231ec 100644 --- a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/_filters.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/_filters.py @@ -5,7 +5,7 @@ from pandas import DataFrame import weaviate -from weaviate.collections.classes.filters import _FilterAnd, _FilterOr +from weaviate.collections.classes.filters import Filter def convert_filters(filters: Dict[str, Any]) -> Dict[str, Any]: @@ -17,7 +17,7 @@ def convert_filters(filters: Dict[str, Any]) -> Dict[str, Any]: raise FilterError(msg) if "field" in filters: - return _FilterAnd(_parse_comparison_condition(filters)) + return Filter.all_of([_parse_comparison_condition(filters)]) return _parse_logical_condition(filters) @@ -55,8 +55,8 @@ def _invert_condition(filters: Dict[str, Any]) -> Dict[str, Any]: LOGICAL_OPERATORS = { - "AND": _FilterAnd, - "OR": _FilterOr, + "AND": Filter.all_of, + "OR": Filter.any_of, } @@ -76,7 +76,7 @@ def _parse_logical_condition(condition: Dict[str, Any]) -> Dict[str, Any]: operands.append(_parse_logical_condition(c)) else: operands.append(_parse_comparison_condition(c)) - return LOGICAL_OPERATORS[operator](*operands) + return LOGICAL_OPERATORS[operator](operands) elif operator == "NOT": inverted_conditions = _invert_condition(condition) return _parse_logical_condition(inverted_conditions) @@ -210,7 +210,7 @@ def _not_in(field: str, value: Any) -> Dict[str, Any]: msg = f"{field}'s value must be a list when using 'in' or 'not in' comparators" raise FilterError(msg) operands = [weaviate.classes.query.Filter.by_property(field).not_equal(v) for v in value] - return _FilterAnd(*operands) + return Filter.all_of(operands) COMPARISON_OPERATORS = { @@ -257,4 +257,4 @@ def _match_no_document(field: str) -> Dict[str, Any]: """ operands = [weaviate.classes.query.Filter.by_property(field).is_none(val) for val in [False, True]] - return _FilterAnd(*operands) + return Filter.all_of(operands) diff --git a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py index 5beaeef8e..d001d3ecf 100644 --- a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 import base64 +import datetime import json from dataclasses import asdict from typing import Any, Dict, List, Optional, Tuple, Union @@ -13,7 +14,6 @@ import weaviate from weaviate.collections.classes.data import DataObject -from weaviate.collections.classes.internal import Object from weaviate.config import AdditionalConfig from weaviate.embedded import EmbeddedOptions from weaviate.util import generate_uuid5 @@ -202,7 +202,7 @@ def _to_document(self, data: DataObject) -> Document: """ document_data = data.properties document_data["id"] = document_data.pop("_original_id") - document_data["embedding"] = data.vector if data.vector else None + document_data["embedding"] = data.vector["default"] if data.vector else None if (blob_data := document_data.get("blob_data")) is not None: document_data["blob"] = { @@ -214,6 +214,10 @@ def _to_document(self, data: DataObject) -> Document: document_data.pop("blob_data", None) document_data.pop("blob_mime_type", None) + for key, value in document_data.items(): + if isinstance(value, datetime.datetime): + document_data[key] = value.strftime("%Y-%m-%dT%H:%M:%SZ") + return Document.from_dict(document_data) def _query_paginated(self, properties: List[str]): diff --git a/integrations/weaviate/tests/test_document_store.py b/integrations/weaviate/tests/test_document_store.py index 6e78d1da6..a35d4d817 100644 --- a/integrations/weaviate/tests/test_document_store.py +++ b/integrations/weaviate/tests/test_document_store.py @@ -368,7 +368,7 @@ def test_to_document(self, document_store, test_files_path): "score": None, "key": "value", }, - vector=[1, 2, 3], + vector={"default": [1, 2, 3]}, ) doc = document_store._to_document(data)