PGVector filtering operator $nin causes Error #21694
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
🔌: postgres
Related to postgres integrations
Ɑ: vector store
Related to vector store module
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_filter_clause
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 queried_field.nin([str(val) for val in filter_value])
^^^^^^^^^^^^^^^^^^
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:
The text was updated successfully, but these errors were encountered: