def _query_item(item, query_id, query_namespace):
    """
    Check if the given cobra collection item matches the query arguments.

    Parameters
    ----------
    item: cobra.Reaction or cobra.Metabolite
    query_id: str
        The identifier to compare. The comparison is made case insensitively.
    query_namespace: str
        The miriam namespace identifier in which the given metabolite is
        registered. See https://www.ebi.ac.uk/miriam/main/collections
        The comparison is made case insensitively.

    Returns
    -------
    bool
        True if the given id exists in the default namespace, or in the model
        annotations by the queried namespace, otherwise False.
    """
    # Try the default identifiers (without confirming the namespace)
    if query_id.lower() == item.id.lower():
        return True

    # Otherwise, try to find a case insensitive match for the namespace key
    for namespace in item.annotation:
        if query_namespace.lower() == namespace.lower():
            annotation = item.annotation[namespace]
            # Compare the identifier case insensitively as well
            # Annotations may contain a single id or a list of ids
            if isinstance(annotation, list):
                if query_id.lower() in [i.lower() for i in annotation]:
                    return True
            else:
                if query_id.lower() == annotation.lower():
                    return True
    return False