Skip to content

Commit

Permalink
Add support for IS_EMPTY metadata filters to Weaviate Vector Store in…
Browse files Browse the repository at this point in the history
…tegration (#17128)

* Add support for IS_EMPTY to Weaviate Vector Store integration

* Bump lama-index-vector-stores-weaviate version to 1.2.2
  • Loading branch information
andrewisplinghoff authored Dec 3, 2024
1 parent dad0246 commit 867f5e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def _transform_weaviate_filter_operator(operator: str) -> str:
return "contains_any"
elif operator == "all":
return "contains_all"
elif operator == "is_empty":
return "is_none"
else:
raise ValueError(f"Filter operator {operator} not supported")

Expand All @@ -78,12 +80,17 @@ def _to_weaviate_filter(
if isinstance(filter, MetadataFilters):
filters_list.append(_to_weaviate_filter(filter))
continue
filters_list.append(
getattr(
wvc.query.Filter.by_property(filter.key),
_transform_weaviate_filter_operator(filter.operator),
)(filter.value)

property_filter = getattr(
wvc.query.Filter.by_property(filter.key),
_transform_weaviate_filter_operator(filter.operator),
)
value = filter.value
# IS_EMPTY does not take a value (expected to be set to None), but when using IsNull with Weaviate, a
# boolean is expected (True meaning the value actually being null / not set / empty)
if filter.operator == "is_empty":
value = True
filters_list.append(property_filter(value))
else:
return {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-vector-stores-weaviate"
readme = "README.md"
version = "1.2.1"
version = "1.2.2"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ def test_to_weaviate_filter_with_various_operators():
assert filter.operator == "LessThanEqual"
assert filter.value == 1

filters = MetadataFilters(
filters=[MetadataFilter(key="a", value=None, operator=FilterOperator.IS_EMPTY)]
)
filter = _to_weaviate_filter(filters)
assert filter.target == "a"
assert filter.operator == "IsNull"
assert filter.value is True


def test_to_weaviate_filter_with_multiple_filters():
filters = MetadataFilters(
Expand Down

0 comments on commit 867f5e2

Please sign in to comment.