Open sunilsamsonsuresh opened 2 weeks ago
@sunilsamsonsuresh Hello there! 👋 I'm here to help you with any bugs, questions, or contributions you have in mind.
To fix the _to_mongodb_filter
function to handle multiple filter conditions without replacing the existing key-value pairs, you can modify the function to use the $and
operator. This way, each filter condition is added as a separate dictionary within an array, ensuring that multiple conditions are combined correctly.
Here is the updated _to_mongodb_filter
function:
def _to_mongodb_filter(standard_filters: MetadataFilters) -> Dict:
"""Convert from standard dataclass to filter dict."""
filters = []
for filter in standard_filters.legacy_filters():
filters.append({filter.key: filter.value})
return {"$and": filters} if filters else {}
This modification ensures that multiple filter conditions are combined using the $and
operator, allowing MongoDB to handle them correctly without overwriting existing key-value pairs [1][2].
To continue talking to Dosu, mention @dosu.
Bug Description
The code in _python3.10/site-packages/llama_index/vectorstores/mongodb/base.py
The below code only retains the last filter condition by replacing the existing key value pair.
Version
0.10.44
Steps to Reproduce
Apply multiple filters to reproduce this
Relevant Logs/Tracbacks
No response