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]: Metadata fields with value 0 being stored as null in Azure AI Search index #17981

Open
QuentinMahieu opened this issue Mar 3, 2025 · 1 comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@QuentinMahieu
Copy link

QuentinMahieu commented Mar 3, 2025

Bug Description

When creating metadata fields for AzureAiSearchVectorStore using MetadataIndexFieldType.INT32, the following code evaluates a 0 as false and stores 0 as null instead of keeping the original integer in base.py:

    def _default_index_mapping(
        self, enriched_doc: Dict[str, str], metadata: Dict[str, Any]
    ) -> Dict[str, str]:
        index_doc: Dict[str, str] = {}

        for field in self._field_mapping:
            index_doc[self._field_mapping[field]] = enriched_doc[field]

        for metadata_field_name, (
            index_field_name,
            _,
        ) in self._metadata_to_index_field_map.items():
            metadata_value = metadata.get(metadata_field_name)
            # ERROR IS HERE
            if metadata_value: --> Should be: if metadata_value is not None:
                index_doc[index_field_name] = metadata_value

        return index_doc  

Version

0.12.12

Steps to Reproduce

Try to store any metadata field equal to 0 using AzureAISearchVectorStore as vector store

Relevant Logs/Tracbacks

@QuentinMahieu QuentinMahieu added bug Something isn't working triage Issue needs to be triaged/prioritized labels Mar 3, 2025
Copy link

dosubot bot commented Mar 3, 2025

@QuentinMahieu Hello there! I'm here to help you with any bugs or questions you have. Let's tackle this together.

The issue you're encountering is due to the conditional check if metadata_value: in the _default_index_mapping function. This check evaluates to False for any value that is considered "falsy" in Python, including 0. As a result, metadata fields with a value of 0 are being stored as null.

To fix this, you should modify the condition to explicitly check for None instead of using a general truthiness check. Change the line:

if metadata_value:

to:

if metadata_value is not None:

This change will ensure that 0 is correctly stored as an integer value rather than being converted to null [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@QuentinMahieu QuentinMahieu changed the title [Bug]: Metadata fields with value 0 being stored as null in Azure AI Search [Bug]: Metadata fields with value 0 being stored as null in Azure AI Search index Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

1 participant