Skip to content

Commit

Permalink
add unit tests for $in and $nin operators (#67)
Browse files Browse the repository at this point in the history
Add unit tests for $in and $nin operators
  • Loading branch information
eyurtsev committed Jun 10, 2024
1 parent e02d730 commit f724ab3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions langchain_postgres/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,11 @@ def _handle_field_filter(
f"Unsupported type: {type(val)} for value: {val}"
)

if isinstance(val, bool): # b/c bool is an instance of int
raise NotImplementedError(
f"Unsupported type: {type(val)} for value: {val}"
)

queried_field = self.EmbeddingStore.cmetadata[field].astext

if operator in {"$in"}:
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/fixtures/filtering_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,21 @@
{"name": {"$in": ["adam", "bob"]}},
[1, 2],
),
# With numeric fields
(
{"id": {"$in": [1, 2]}},
[1, 2],
),
# Test nin
(
{"name": {"$nin": ["adam", "bob"]}},
[3],
),
## with numeric fields
(
{"id": {"$nin": [1, 2]}},
[3],
),
]

TYPE_5_FILTERING_TEST_CASES = [
Expand Down

0 comments on commit f724ab3

Please sign in to comment.