def get_filter_clause(filters: MetadataFilters) -> str:
    """Convert metadata filters to Gel query filter clause."""
    subclauses = []
    for filter in filters.filters:
        if isinstance(filter, MetadataFilters):
            subclause = get_filter_clause(filter)
        elif isinstance(filter, MetadataFilter):
            formatted_value = (
                f'"{filter.value}"' if isinstance(filter.value, str) else filter.value
            )
            if filter.operator == FilterOperator.EQ.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") = {formatted_value}'
                )
            elif filter.operator == FilterOperator.GT.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") > {formatted_value}'
                )
            elif filter.operator == FilterOperator.LT.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") < {formatted_value}'
                )
            elif filter.operator == FilterOperator.NE.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") != {formatted_value}'
                )
            elif filter.operator == FilterOperator.GTE.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") >= {formatted_value}'
                )
            elif filter.operator == FilterOperator.LTE.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") <= {formatted_value}'
                )
            elif filter.operator == FilterOperator.IN.value:
                subclause = f'<str>json_get(.metadata, "{filter.key}") in array_unpack({formatted_value})'
            elif filter.operator == FilterOperator.NIN.value:
                subclause = f'<str>json_get(.metadata, "{filter.key}") not in array_unpack({formatted_value})'
            elif filter.operator == FilterOperator.ANY.value:
                subclause = f'any(<str>json_get(.metadata, "{filter.key}") = array_unpack({formatted_value}))'
            elif filter.operator == FilterOperator.ALL.value:
                subclause = f'all(<str>json_get(.metadata, "{filter.key}") = array_unpack({formatted_value}))'
            elif filter.operator == FilterOperator.TEXT_MATCH.value:
                subclause = (
                    f'<str>json_get(.metadata, "{filter.key}") like {formatted_value}'
                )
            elif filter.operator == FilterOperator.CONTAINS.value:
                subclause = f'contains(<str>json_get(.metadata, "{filter.key}"), {formatted_value})'
            elif filter.operator == FilterOperator.IS_EMPTY.value:
                subclause = f'not exists <str>json_get(.metadata, "{filter.key}")'
            else:
                raise ValueError(f"Unknown operator: {filter.operator}")

        subclauses.append(subclause)

    if filters.condition == FilterCondition.AND:
        filter_clause = " and ".join(subclauses)
        return "(" + filter_clause + ")" if len(subclauses) > 1 else filter_clause
    elif filters.condition == FilterCondition.OR:
        filter_clause = " or ".join(subclauses)
        return "(" + filter_clause + ")" if len(subclauses) > 1 else filter_clause
    else:
        raise ValueError(f"Unknown condition: {filters.condition}")
Convert metadata filters to Gel query filter clause.
llama-index-integrations/vector_stores/llama-index-vector-stores-gel/llama_index/vector_stores/gel/base.py