From dd5dcc859752ec0f4b07af450e36cdcfaad78b6f Mon Sep 17 00:00:00 2001 From: MartinGotelli Date: Fri, 17 May 2024 16:43:48 -0300 Subject: [PATCH] Fix in exists operator. Was working as null --- langchain_postgres/vectorstores.py | 2 +- tests/unit_tests/fixtures/filtering_test_cases.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/langchain_postgres/vectorstores.py b/langchain_postgres/vectorstores.py index 2061a920..89b78fba 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 0fb7e3f4..514a10f1 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], ), ]