Skip to content

Commit f724ab3

Browse files
authored
add unit tests for $in and $nin operators (#67)
Add unit tests for $in and $nin operators
1 parent e02d730 commit f724ab3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

langchain_postgres/vectorstores.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,11 @@ def _handle_field_filter(
11091109
f"Unsupported type: {type(val)} for value: {val}"
11101110
)
11111111

1112+
if isinstance(val, bool): # b/c bool is an instance of int
1113+
raise NotImplementedError(
1114+
f"Unsupported type: {type(val)} for value: {val}"
1115+
)
1116+
11121117
queried_field = self.EmbeddingStore.cmetadata[field].astext
11131118

11141119
if operator in {"$in"}:

tests/unit_tests/fixtures/filtering_test_cases.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,21 @@
203203
{"name": {"$in": ["adam", "bob"]}},
204204
[1, 2],
205205
),
206+
# With numeric fields
207+
(
208+
{"id": {"$in": [1, 2]}},
209+
[1, 2],
210+
),
206211
# Test nin
207212
(
208213
{"name": {"$nin": ["adam", "bob"]}},
209214
[3],
210215
),
216+
## with numeric fields
217+
(
218+
{"id": {"$nin": [1, 2]}},
219+
[3],
220+
),
211221
]
212222

213223
TYPE_5_FILTERING_TEST_CASES = [

0 commit comments

Comments
 (0)