Hi @YD,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
You have already set up your vector store correctly, but CosmosDB may not be fully applying the filters as expected, which can sometimes happen with certain CosmosDB MongoDB API configurations.
You can try with the troubleshooting steps in order to resolve the issue.
- Enable Pre-Filtering (if available): Verify if pre-filtering is available as a preview feature in your CosmosDB settings on Azure, and enable it if possible. This can help in cases where pre-filtering functionality needs to be explicitly activated for use in certain query structures.
- Verify Filter Syntax: CosmosDB for MongoDB might interpret filters differently than native MongoDB. Try simplifying the filter syntax to ensure compatibility. Avoid using operators like $eq directly in CosmosDB queries, as CosmosDB sometimes does not interpret MongoDB operators as expected when used through APIs.
"filter": {"metadata.username": username}
- Direct Testing with CosmosDB: Test a simple filter query directly on the CosmosDB portal to confirm it retrieves the expected data. Once confirmed, you can apply the same syntax in LangChain.
- Use Post-Filtering as a Fallback: If the above adjustments don’t work, retrieve a broader result set without filters and apply the filter afterward as a fallback. This may not be as efficient but will ensure data accuracy.
- LangChain and CosmosDB Version Compatibility: Ensure you’re using compatible versions of LangChain and the CosmosDB SDK, as filter functionality could be affected by updates or specific versions.
Please refer to the below mentioned links for more information.
https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/rag
https://learn.microsoft.com/en-us/azure/cosmos-db/vector-database#retrieval-augmented-generation
https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/vector-search
I hope, This response will address your query and helped you to overcome on your challenges.
If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.