From 9912f541dd2374b7e1828234e4f0c5cf64eb0b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gotelli=20Ferenaz?= Date: Fri, 17 May 2024 23:26:18 -0300 Subject: [PATCH] vectorstore[patch]: Fix in exists operator. Was working as null (#51) So... yeah I f***ed up. But this is the fix. The $exists was working as the $null, but the rename implies also changing how the bool value is interpreted: $exists: True (there is a tag, I don't care the value) $exists: False (no tag in there) ref: https://github.com/langchain-ai/langchain-postgres/pull/40 --- 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 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], ), ]