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

[Bug]: #14438

Open
sunilsamsonsuresh opened this issue Jun 27, 2024 · 1 comment
Open

[Bug]: #14438

sunilsamsonsuresh opened this issue Jun 27, 2024 · 1 comment
Labels
bug Something isn't working stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed triage Issue needs to be triaged/prioritized

Comments

@sunilsamsonsuresh
Copy link
Contributor

Bug Description

The code in
python3.10/site-packages/llama_index/vector_stores/mongodb/base.py

The below code only retains the last filter condition by replacing the existing key value pair.

def _to_mongodb_filter(standard_filters: MetadataFilters) -> Dict:
    """Convert from standard dataclass to filter dict."""
    filters = {}
    for filter in standard_filters.legacy_filters():
        filters[filter.key] = filter.value
    return filters

Version

0.10.44

Steps to Reproduce

Apply multiple filters to reproduce this

country_filter = MetadataFilters(
    filters=[
        ExactMatchFilter(key="metadata.country_code", value=f'{country_code}'),
        ExactMatchFilter(key="metadata.country_code", value='Global'),
    ],
    condition='or'
)

Relevant Logs/Tracbacks

No response

@sunilsamsonsuresh sunilsamsonsuresh added bug Something isn't working triage Issue needs to be triaged/prioritized labels Jun 27, 2024
Copy link

dosubot bot commented Jun 27, 2024

@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.

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

1 participant