fix: revert Weaviate query with filters and improve tests (#3646)

* revert weaviate query with filters and improve tests

* pylint

* upgrade weaviate container

* use latest docker tag

* fix text

* fix text
This commit is contained in:
Sara Zan 2022-12-06 14:48:58 +01:00 committed by GitHub
parent e4c3817d01
commit fc89f6ea74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 19 deletions

View File

@ -335,7 +335,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
services: services:
weaviate: weaviate:
image: semitechnologies/weaviate:1.16.0 image: semitechnologies/weaviate:latest
env: env:
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true" AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true"
PERSISTENCE_DATA_PATH: "/var/lib/weaviate" PERSISTENCE_DATA_PATH: "/var/lib/weaviate"

View File

@ -985,28 +985,30 @@ class WeaviateDocumentStore(BaseDocumentStore):
) )
# Retrieval with BM25 AND filtering # Retrieval with BM25 AND filtering
if filters: if filters: # pylint: disable=no-else-raise
raise NotImplementedError(
# Once Weaviate starts supporting filters with BM25: "Weaviate currently does not support filters WITH inverted index text query (eg BM25)!"
filter_dict = LogicalFilterClause.parse(filters).convert_to_weaviate() )
# # Once Weaviate starts supporting filters with BM25:
# filter_dict = LogicalFilterClause.parse(filters).convert_to_weaviate()
# gql_query = (
# weaviate.gql.get.GetBuilder(
# class_name=index, properties=properties, connection=self.weaviate_client
# )
# .with_near_vector({"vector": [0, 0]})
# .with_where(filter_dict)
# .with_limit(top_k)
# .build()
# )
else:
# BM25 retrieval without filtering
gql_query = ( gql_query = (
weaviate.gql.get.GetBuilder( gql.get.GetBuilder(class_name=index, properties=properties, connection=self.weaviate_client)
class_name=index, properties=properties, connection=self.weaviate_client
)
.with_near_vector({"vector": [0, 0]}) .with_near_vector({"vector": [0, 0]})
.with_where(filter_dict)
.with_limit(top_k) .with_limit(top_k)
.build() .build()
) )
# BM25 retrieval without filtering
gql_query = (
gql.get.GetBuilder(class_name=index, properties=properties, connection=self.weaviate_client)
.with_near_vector({"vector": [0, 0]})
.with_limit(top_k)
.build()
)
# Build the BM25 part of the GQL manually. # Build the BM25 part of the GQL manually.
# Currently the GetBuilder of the Weaviate-client (v3.6.0) # Currently the GetBuilder of the Weaviate-client (v3.6.0)
# does not support the BM25 part of GQL building, so # does not support the BM25 part of GQL building, so

View File

@ -180,8 +180,9 @@ class TestWeaviateDocumentStore(DocumentStoreBaseTestAbstract):
assert len(docs) == 3 assert len(docs) == 3
# BM25 retrieval WITH filters is not yet supported as of Weaviate v1.14.1 # BM25 retrieval WITH filters is not yet supported as of Weaviate v1.14.1
# with pytest.raises(Exception): # Should be from 1.18: https://github.com/semi-technologies/weaviate/issues/2393
docs = ds.query(query_text, filters={"name": ["filename2"]}) # docs = ds.query(query_text, filters={"name": ["name_1"]})
# assert len(docs) == 1
docs = ds.query(filters={"name": ["name_0"]}) docs = ds.query(filters={"name": ["name_0"]})
assert len(docs) == 3 assert len(docs) == 3