Open GuidoK1 opened 4 months ago
You are right. I will create a fix.
Any updates on fix?
How is this fix going?
I was able to filter using search_kwargs={'pre_filter': ''}
:
users_authorized= [8646]
# filter only certain users and specific customers in a database
user_permissions = {"metadata.authorizedUsers": {"$in": users_authorized}}
customer_filter = {"metadata.customerId": 1}
combined_filter = {
"$and": [
user_permissions,
customer_filter
]
}
retriever = vector_store.as_retriever(
search_kwargs={'pre_filter': combined_filter}
)
In fact there is nothing in the docs describing how to use the filter.. had to debug to sort this out.
langchain==0.3.7 langchain-community==0.3.5 langchain-core==0.3.15 langchain-openai==0.2.6
pymongo.errors.OperationFailure: $filter is not supported for vector search yet., full error: {'ok': 0.0, 'errmsg': '$filter is not supported for vector search yet.', 'code': 115, 'codeName': 'CommandNotSupported'}
Received this error, may I know how did you solve it? Did u have to enable the pre filtering for the Azure Cosmos DB?
From azure's website, (https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/vector-search) You can now execute vector searches with any supported query filter such as $lt, $lte, $eq, $neq, $gte, $gt, $in, $nin, and $regex. Enable the "filtering vector search" feature in the "Preview Features" tab of your Azure Subscription.
Checked other resources
Example Code
Current implementation
Error Message and Stack Trace (if applicable)
No response
Description
As stated in the langchain documentation filtering in Azure Cosmos DB Mongo vCore should be supported: https://python.langchain.com/v0.2/docs/integrations/vectorstores/azure_cosmos_db/
Filtering works when I apply my MongoDB query directly using pyomongo as shown in the example. However, through langchain the same filters are not applied. I tried using the filter, pre_filter, search_kwargs and kwargs parameters, but to no avail.
Upon closer inspection of the source code, I see that no filter key is present in the query dictionary and see no kwargs, search_kwargs being passed, which could be the reason. https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/azure_cosmos_db.py
Any input on this issue?
System Info
System Information
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found: