mirror of
				https://github.com/deepset-ai/haystack.git
				synced 2025-11-04 11:49:23 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									e4c3817d01
								
							
						
					
					
						commit
						fc89f6ea74
					
				
							
								
								
									
										2
									
								
								.github/workflows/tests.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/tests.yml
									
									
									
									
										vendored
									
									
								
							@ -335,7 +335,7 @@ jobs:
 | 
			
		||||
    runs-on: ${{ matrix.os }}
 | 
			
		||||
    services:
 | 
			
		||||
      weaviate:
 | 
			
		||||
        image: semitechnologies/weaviate:1.16.0
 | 
			
		||||
        image: semitechnologies/weaviate:latest
 | 
			
		||||
        env:
 | 
			
		||||
          AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true"
 | 
			
		||||
          PERSISTENCE_DATA_PATH: "/var/lib/weaviate"
 | 
			
		||||
 | 
			
		||||
@ -985,28 +985,30 @@ class WeaviateDocumentStore(BaseDocumentStore):
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            # Retrieval with BM25 AND filtering
 | 
			
		||||
            if filters:
 | 
			
		||||
 | 
			
		||||
                # Once Weaviate starts supporting filters with BM25:
 | 
			
		||||
                filter_dict = LogicalFilterClause.parse(filters).convert_to_weaviate()
 | 
			
		||||
            if filters:  # pylint: disable=no-else-raise
 | 
			
		||||
                raise NotImplementedError(
 | 
			
		||||
                    "Weaviate currently does not support filters WITH inverted index text query (eg BM25)!"
 | 
			
		||||
                )
 | 
			
		||||
                # # 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 = (
 | 
			
		||||
                    weaviate.gql.get.GetBuilder(
 | 
			
		||||
                        class_name=index, properties=properties, connection=self.weaviate_client
 | 
			
		||||
                    )
 | 
			
		||||
                    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()
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
            # 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.
 | 
			
		||||
            # Currently the GetBuilder of the Weaviate-client (v3.6.0)
 | 
			
		||||
            # does not support the BM25 part of GQL building, so
 | 
			
		||||
 | 
			
		||||
@ -180,8 +180,9 @@ class TestWeaviateDocumentStore(DocumentStoreBaseTestAbstract):
 | 
			
		||||
        assert len(docs) == 3
 | 
			
		||||
 | 
			
		||||
        # BM25 retrieval WITH filters is not yet supported as of Weaviate v1.14.1
 | 
			
		||||
        # with pytest.raises(Exception):
 | 
			
		||||
        docs = ds.query(query_text, filters={"name": ["filename2"]})
 | 
			
		||||
        # Should be from 1.18: https://github.com/semi-technologies/weaviate/issues/2393
 | 
			
		||||
        # docs = ds.query(query_text, filters={"name": ["name_1"]})
 | 
			
		||||
        # assert len(docs) == 1
 | 
			
		||||
 | 
			
		||||
        docs = ds.query(filters={"name": ["name_0"]})
 | 
			
		||||
        assert len(docs) == 3
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user