Skip to content

Commit

Permalink
updates due to latest client changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm207 committed Mar 5, 2024
1 parent 207f427 commit 9a30bdd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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)


Expand Down Expand Up @@ -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,
}


Expand All @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"] = {
Expand All @@ -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]):
Expand Down
2 changes: 1 addition & 1 deletion integrations/weaviate/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9a30bdd

Please sign in to comment.