Skip to content
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

added operator filter for supabase #29475

Merged
merged 3 commits into from
Jan 29, 2025
Merged

Conversation

Anash3
Copy link
Contributor

@Anash3 Anash3 commented Jan 29, 2025

Description
This PR adds support for MongoDB-style $in operator filtering in the Supabase vectorstore implementation. Currently, filtering with $in operators returns no results, even when matching documents exist. This change properly translates MongoDB-style filters to PostgreSQL syntax, enabling efficient multi-document filtering.
Changes

Modified similarity_search_by_vector_with_relevance_scores to handle MongoDB-style $in operators
Added automatic conversion of $in filters to PostgreSQL IN clauses
Preserved original vector type handling and numpy array conversion
Maintained compatibility with existing postgrest filters
Added support for the same filtering in similarity_search_by_vector_returning_embeddings

Issue
Closes #27932

Implementation Notes
No changes to public API or function signatures
Backwards compatible - behavior unchanged for non-$in filters
More efficient than multiple individual queries for multi-ID searches
Preserves all existing functionality including numpy array conversion for vector types

Dependencies
None

Additional Notes
The implementation handles proper SQL escaping for filter values
Maintains consistent behavior with other vectorstore implementations that support MongoDB-style operators
Future extensions could support additional MongoDB-style operators ($gt, $lt, etc.)

Copy link

vercel bot commented Jan 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Jan 29, 2025 2:19pm

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. community Related to langchain-community Ɑ: vector store Related to vector store module labels Jan 29, 2025
@Anash3 Anash3 force-pushed the fix/superbase branch 2 times, most recently from 33c48df to 3a8a0c3 Compare January 29, 2025 14:06
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jan 29, 2025
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Jan 29, 2025
@ccurme ccurme enabled auto-merge (squash) January 29, 2025 14:20
@ccurme ccurme merged commit 12bcc85 into langchain-ai:master Jan 29, 2025
19 checks passed
@Kevin-McIsaac
Copy link

I'm using the match_documents function in the [langchain documentation] (https://python.langchain.com/docs/integrations/vectorstores/supabase/)

which uses the where clause
where metadata @> filter

Using a simple filter works

vector_store_sync.similarity_search(
                    "What is the maximum loan amount",
                    filter = {"policy_id": '47c346b7-134c-4c5b-8b5f-a79d9d8d079d'},
                )

works as expected but with the $in notation

vector_store_sync.similarity_search(
                    "What is the maximum loan amount",
                    filter = {"'policy_id'": {"$in": ['47c346b7-134c-4c5b-8b5f-a79d9d8d079d']}}
                )

I get the error
APIError: {'code': 'PGRST100', 'details': 'unexpected "(" expecting "-", "->>", "->" or delimiter (.)', 'hint': None, 'message': '"failed to parse logic tree ((metadata->>\'policy_id\' IN (\'47c346b7-134c-4c5b-8b5f-a79d9d8d079d\')))" (line 1, column 31)'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community lgtm PR looks good. Use to confirm that a PR is ready for merging. size:S This PR changes 10-29 lines, ignoring generated files. Ɑ: vector store Related to vector store module
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Supabase vectorstore does not support $in in a filter to match to a list of ids
3 participants