def select_attributes(marqo_doc: Dict[str, Any], attributes_to_retrieve_set: Set[str]) -> Dict[str, Any]:
    """
    Unstructured index and Semi-structured index retrieve all fixed fields (numeric, boolean, string arrays, etc.)
    from Vespa when attributes_to_retrieve is specified. After converting the Vespa doc to Marqo doc, it needs to
    filter out attributes not in the attributes_to_retrieve list.

    Please note that numeric map fields are flattened for unstructured or semi-structured indexes.
    Therefore, when filtering on attributes_to_retrieve, we need to also include flattened map fields
    with the specified attributes as prefixes. We keep this behaviour only for compatibility reasons.
    """
    return {k: v for k, v in marqo_doc.items() if k in attributes_to_retrieve_set or
            '.' in k and k.split('.', maxsplit=1)[0] in attributes_to_retrieve_set}

    Unstructured index and Semi-structured index retrieve all fixed fields (numeric, boolean, string arrays, etc.)
    from Vespa when attributes_to_retrieve is specified. After converting the Vespa doc to Marqo doc, it needs to
    filter out attributes not in the attributes_to_retrieve list.

    Please note that numeric map fields are flattened for unstructured or semi-structured indexes.
    Therefore, when filtering on attributes_to_retrieve, we need to also include flattened map fields
    with the specified attributes as prefixes. We keep this behaviour only for compatibility reasons.
    
src/marqo/tensor_search/tensor_search.py