def METHOD_NAME(self, user: User, annotation_ids):
    """
    Check which of the given annotation IDs the given user has flagged.
    :param user: The user to check for a flag.
    :param annotation_ids: The IDs of the annotations to check.
    :returns The subset of the IDs that the given user has flagged.
    """
    # SQLAlchemy doesn't behave in the way we might expect when handed an
    # `in_` condition with an empty sequence
    if not annotation_ids or not user:
        return set()
    query = self._session.query(Flag.annotation_id).filter(
        Flag.annotation_id.in_(annotation_ids), Flag.user == user
    )
    flagged_ids = {f.annotation_id for f in query}
    # Fill out the cache, so we can make use of it in flagged()
    for annotation_id in annotation_ids:
        self._flagged_cache[(user.id, annotation_id)] = annotation_id in flagged_ids
    return {f.annotation_id for f in query}