diff --git a/langchain_postgres/vectorstores.py b/langchain_postgres/vectorstores.py index 2061a92..89b78fb 100644 --- a/langchain_postgres/vectorstores.py +++ b/langchain_postgres/vectorstores.py @@ -720,7 +720,7 @@ def _handle_field_filter( self.EmbeddingStore.cmetadata, field, ) - return ~condition if filter_value else condition + return condition if filter_value else ~condition else: raise NotImplementedError() diff --git a/tests/unit_tests/fixtures/filtering_test_cases.py b/tests/unit_tests/fixtures/filtering_test_cases.py index 0fb7e3f..514a10f 100644 --- a/tests/unit_tests/fixtures/filtering_test_cases.py +++ b/tests/unit_tests/fixtures/filtering_test_cases.py @@ -226,19 +226,19 @@ TYPE_6_FILTERING_TEST_CASES = [ # These involve the special operator $exists ( - {"happiness": {"$exists": True}}, + {"happiness": {"$exists": False}}, [], ), ( - {"happiness": {"$exists": False}}, + {"happiness": {"$exists": True}}, [1, 2, 3], ), ( - {"sadness": {"$exists": True}}, + {"sadness": {"$exists": False}}, [3], ), ( - {"sadness": {"$exists": False}}, + {"sadness": {"$exists": True}}, [1, 2], ), ]