Skip to content

add unit tests for $in and $nin operators #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions langchain_postgres/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,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
Loading