def extract_properties(data: dict[str, Any]) -> dict[str, Any]:
    """
    Extracts the 'properties' dictionary from the input dictionary,
    merges its key-value pairs into the top-level dictionary, and returns a new dictionary.

    Args:
        data (dict[str, Any]): The original dictionary possibly containing a 'properties' key.

    Returns:
        dict[str, Any]: A new dictionary with 'properties' merged into the top-level.

    Raises:
        TypeError: If 'properties' exists but is not a dictionary.
        KeyError: If there are key collisions between 'properties' and the top-level keys.
    """
    if not isinstance(data, dict):
        raise TypeError(f"Input must be a dictionary. Received: {type(data).__name__}")

    properties = data.get("properties")
    if properties is None:
        return data

    if not isinstance(properties, dict):
        raise TypeError("'properties' must be a dictionary.")

    if overlapping_keys := (set(data) - {"properties"}) & set(properties):
        raise KeyError(
            f"Key collision detected for keys: {', '.join(overlapping_keys)}. Cannot merge 'properties'."
        )

    merged_data = {**{k: v for k, v in data.items() if k != "properties"}, **properties}

    return merged_data

    Extracts the 'properties' dictionary from the input dictionary,
    merges its key-value pairs into the top-level dictionary, and returns a new dictionary.

    Args:
        data (dict[str, Any]): The original dictionary possibly containing a 'properties' key.

    Returns:
        dict[str, Any]: A new dictionary with 'properties' merged into the top-level.

    Raises:
        TypeError: If 'properties' exists but is not a dictionary.
        KeyError: If there are key collisions between 'properties' and the top-level keys.
    
ai/integrations/llama_index/src/unitycatalog/ai/llama_index/toolkit.py