Attribute Error raised when using "$nin" operator in filter #13

Closed
opened 2026-02-16 05:16:03 -05:00 by yindo · 2 comments
Owner

Originally created by @xidian237 on GitHub (May 14, 2024).

Hi Expert,
I notice that we support the $ini operator:
image

But currently an Attribute Error raised in my case:
docs = db.similarity_search(query="this is a doc", k=2, filter={'info': {'$nin': [1, 2, 3]}})
`Traceback (most recent call last):
File "F:\WorkProject\medicines_recommend.venv\Lib\site-packages\sqlalchemy\sql\elements.py", line 1496, in getattr
return getattr(self.comparator, key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Comparator' object has no attribute 'nin_'. Did you mean: 'in_'?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "F:\WorkProject\medicines_recommend.venv\Lib\site-packages\langchain_postgres\vectorstores.py", line 909, in __query_collection
filter_clauses = self._create_filter_clause(filter)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\WorkProject\medicines_recommend.venv\Lib\site-packages\langchain_postgres\vectorstores.py", line 835, in create_filter_clause
return self.handle_field_filter(key, filters[key])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\WorkProject\medicines_recommend.venv\Lib\site-packages\langchain_postgres\vectorstores.py", line 705, in handle_field_filter
return queried_field.nin
([str(val) for val in filter_value])
^^^^^^^^^^^^^^^^^^
File "F:\WorkProject\medicines_recommend.venv\Lib\site-packages\sqlalchemy\sql\elements.py", line 1498, in getattr
raise AttributeError(
AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object has an attribute 'nin
'. Did you mean: 'in
'?
python-BaseException`

Actually, I find here is the entry interface:
elif operator in {"$nin"}: return queried_field.nin_([str(val) for val in filter_value])
but there is no "nin_" in .venv/Lib/site-packages/sqlalchemy/sql/operators.py, however, they provide the "not_in"
def not_in(self, other: Any) -> ColumnOperators:

Originally created by @xidian237 on GitHub (May 14, 2024). Hi Expert, I notice that we support the $ini operator: ![image](https://github.com/langchain-ai/langchain-postgres/assets/17851643/d8bb8dc2-3246-4524-9c85-971359938c56) But currently an Attribute Error raised in my case: `docs = db.similarity_search(query="this is a doc", k=2, filter={'info': {'$nin': [1, 2, 3]}})` `Traceback (most recent call last): File "F:\WorkProject\medicines_recommend\.venv\Lib\site-packages\sqlalchemy\sql\elements.py", line 1496, in __getattr__ return getattr(self.comparator, key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Comparator' object has no attribute 'nin_'. Did you mean: 'in_'? The above exception was the direct cause of the following exception: Traceback (most recent call last): File "F:\WorkProject\medicines_recommend\.venv\Lib\site-packages\langchain_postgres\vectorstores.py", line 909, in __query_collection filter_clauses = self._create_filter_clause(filter) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\WorkProject\medicines_recommend\.venv\Lib\site-packages\langchain_postgres\vectorstores.py", line 835, in _create_filter_clause return self._handle_field_filter(key, filters[key]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\WorkProject\medicines_recommend\.venv\Lib\site-packages\langchain_postgres\vectorstores.py", line 705, in _handle_field_filter return queried_field.nin_([str(val) for val in filter_value]) ^^^^^^^^^^^^^^^^^^ File "F:\WorkProject\medicines_recommend\.venv\Lib\site-packages\sqlalchemy\sql\elements.py", line 1498, in __getattr__ raise AttributeError( AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object has an attribute 'nin_'. Did you mean: 'in_'? python-BaseException` Actually, I find here is the entry interface: ` elif operator in {"$nin"}: return queried_field.nin_([str(val) for val in filter_value])` but there is no "nin_" in .venv/Lib/site-packages/sqlalchemy/sql/operators.py, however, they provide the "not_in" `def not_in(self, other: Any) -> ColumnOperators:`
yindo closed this issue 2026-02-16 05:16:03 -05:00
Author
Owner

@xidian237 commented on GitHub (May 14, 2024):

Python: 3.11.9
langchain-postgres 0.0.3
pgvector 0.2.5

@xidian237 commented on GitHub (May 14, 2024): Python: 3.11.9 langchain-postgres 0.0.3 pgvector 0.2.5
Author
Owner

@eyurtsev commented on GitHub (May 17, 2024):

Address by this PR https://github.com/langchain-ai/langchain-postgres/pull/40

@eyurtsev commented on GitHub (May 17, 2024): Address by this PR https://github.com/langchain-ai/langchain-postgres/pull/40
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#13