Open n1k8-dev opened 1 month ago
On further analysis SqlAlchemy does not have a supporting function nin_. It does however have notin and notin_.
Changing the nin to notin in line 707 in pgvector.py fixed the problem.
I noticed the same issue in the latest version of langchain and langchain_postgres
Checked other resources
Example Code
result = vectorstore.similarity_search_with_score(query, k=25, filter={ "$and": [ { "type": "News" }, { "city": { "$in": [ "New York", "Chicago"] } }, { "topic": { "$nin": [ "Sports", "Politics"] } } ] } )
Error Message and Stack Trace (if applicable)
File "/Users/ng/workspace/dev/chatbot/venv/lib/python3.12/site-packages/langchain_community/vectorstores/pgvector.py", line 572, in similarity_search_with_score docs = self.similarity_search_with_score_by_vector( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ng/workspace/dev/chatbot/venv/lib/python3.12/site-packages/langchain_community/vectorstores/pgvector.py", line 597, in similarity_search_with_score_by_vector results = self.query_collection(embedding=embedding, k=k, filter=filter) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ng/workspace/dev/chatbot/venv/lib/python3.12/site-packages/langchain_community/vectorstores/pgvector.py", line 911, in query_collection filter_clauses = self._create_filter_clause(filter) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ng/workspace/dev/chatbot/venv/lib/python3.12/site-packages/langchain_community/vectorstores/pgvector.py", line 845, in _create_filterclause and = [self._create_filter_clause(el) for el in value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ng/workspace/dev/chatbot/venv/lib/python3.12/site-packages/langchain_community/vectorstores/pgvector.py", line 837, in _create_filter_clause return self._handle_field_filter(key, filters[key]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ng/workspace/dev/chatbot/app/engine/assistant.py", line 272, in _handle_field_filter return queriedfield.nin([str(val) for val in filtervalue]) ^^^^^^^^^^^^^^^^^^ File "/Users/ng/workspace/dev/chatbot/venv/lib/python3.12/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_'?
Description
I am trying to do a vector store similarity search with PGVector using a not in ($nin) filter of the metadata. This raises a AttributeError.
System Info
System Information
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found: