Adding filtering support for Weaviate when used for BM25 querying (#4385)

This commit is contained in:
Zoltan Fedor 2023-03-29 10:51:22 -04:00 committed by GitHub
parent e00f1461bc
commit 32091d66cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 23 deletions

View File

@ -999,29 +999,16 @@ class WeaviateDocumentStore(KeywordDocumentStore):
# Default Retrieval via BM25 using the user's query on `self.content_field`
else:
logger.warning(
"As of v1.14.1 Weaviate's BM25 retrieval is still in experimental phase, "
"so use it with care! To turn on the BM25 experimental feature in Weaviate "
"you need to start it with the `ENABLE_EXPERIMENTAL_BM25='true'` "
"environmental variable."
)
# Retrieval with BM25 AND filtering
if filters: # pylint: disable=no-else-raise
raise NotImplementedError(
"Weaviate currently does not support filters WITH inverted index text query (eg BM25)!"
if filters:
filter_dict = LogicalFilterClause.parse(filters).convert_to_weaviate()
gql_query = (
gql.get.GetBuilder(class_name=index, properties=properties, connection=self.weaviate_client)
.with_limit(top_k)
.with_bm25({"query": query, "properties": self.content_field})
.with_where(filter_dict)
.build()
)
# # 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 = (

View File

@ -86,8 +86,7 @@ def test_retrieval_without_filters(retriever_with_docs: BaseRetriever, document_
("embedding", "elasticsearch"),
("embedding", "memory"),
("bm25", "elasticsearch"),
# TODO - add once Weaviate starts supporting filters with BM25 in Weaviate v1.18+
# ("bm25", "weaviate"),
("bm25", "weaviate"),
("es_filter_only", "elasticsearch"),
],
indirect=True,