Repository: microsoft/semantic-kernel
File: dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchCollectionCreateMapping.cs (C#)

Code before:
    /// <exception cref="InvalidOperationException">Thrown if a distance function is chosen that isn't supported by Azure AI Search.</exception>
    public static VectorSearchAlgorithmMetric GetSDKDistanceAlgorithm(VectorPropertyModel vectorProperty)
        => vectorProperty.DistanceFunction switch
        {
            DistanceFunction.CosineSimilarity or null => VectorSearchAlgorithmMetric.Cosine,
            DistanceFunction.DotProductSimilarity => VectorSearchAlgorithmMetric.DotProduct,
            DistanceFunction.EuclideanDistance => VectorSearchAlgorithmMetric.Euclidean,
            _ => throw new InvalidOperationException($"Distance function '{vectorProperty.DistanceFunction}' for {nameof(VectorStoreVectorProperty)} '{vectorProperty.ModelName}' is not supported by the Azure AI Search VectorStore.")
        };

    /// <summary>
    /// Maps the given property type to the corresponding <see cref="SearchFieldDataType"/>.
    /// </summary>
    /// <param name="propertyType">The property type to map.</param>
    /// <returns>The <see cref="SearchFieldDataType"/> that corresponds to the given property type.</returns>"
    /// <exception cref="InvalidOperationException">Thrown if the given type is not supported.</exception>
    public static SearchFieldDataType GetSDKFieldDataType(Type propertyType)
        => (Nullable.GetUnderlyingType(propertyType) ?? propertyType) switch
        {
            Type t when t == typeof(string) => SearchFieldDataType.String,
            Type t when t == typeof(bool) => SearchFieldDataType.Boolean,
            Type t when t == typeof(int) => SearchFieldDataType.Int32,
            Type t when t == typeof(long) => SearchFieldDataType.Int64,
            Type t when t == typeof(float) => SearchFieldDataType.Double,
            Type t when t == typeof(double) => SearchFieldDataType.Double,
            Type t when t == typeof(DateTime) => SearchFieldDataType.DateTimeOffset,
            Type t when t == typeof(DateTimeOffset) => SearchFieldDataType.DateTimeOffset,

            Type t when t == typeof(string[]) => SearchFieldDataType.Collection(SearchFieldDataType.String),
            Type t when t == typeof(List<string>) => SearchFieldDataType.Collection(SearchFieldDataType.String),
            Type t when t == typeof(bool[]) => SearchFieldDataType.Collection(SearchFieldDataType.Boolean),
            Type t when t == typeof(List<bool>) => SearchFieldDataType.Collection(SearchFieldDataType.Boolean),
            Type t when t == typeof(int[]) => SearchFieldDataType.Collection(SearchFieldDataType.Int32),
            Type t when t == typeof(List<int>) => SearchFieldDataType.Collection(SearchFieldDataType.Int32),
            Type t when t == typeof(long[]) => SearchFieldDataType.Collection(SearchFieldDataType.Int64),
            Type t when t == typeof(List<long>) => SearchFieldDataType.Collection(SearchFieldDataType.Int64),
            Type t when t == typeof(float[]) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(List<float>) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(double[]) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(List<double>) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(DateTime[]) => SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset),
            Type t when t == typeof(List<DateTime>) => SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset),
            Type t when t == typeof(DateTimeOffset[]) => SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset),
            Type t when t == typeof(List<DateTimeOffset>) => SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset),

            _ => throw new InvalidOperationException($"Data type '{propertyType}' for {nameof(VectorStoreDataProperty)} is not supported by the Azure AI Search VectorStore.")
        };
}


Review comment (suggestion):
BTW the model builder does not allow for `DateTime` and simply throws:

https://github.com/microsoft/semantic-kernel/blob/cf5b5e5ab56e2274876198526dcea746fbb4ab5e/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchModelBuilder.cs#L52-L59

Code after:
    /// <exception cref="InvalidOperationException">Thrown if a distance function is chosen that isn't supported by Azure AI Search.</exception>
    public static VectorSearchAlgorithmMetric GetSDKDistanceAlgorithm(VectorPropertyModel vectorProperty)
        => vectorProperty.DistanceFunction switch
        {
            DistanceFunction.CosineSimilarity or null => VectorSearchAlgorithmMetric.Cosine,
            DistanceFunction.DotProductSimilarity => VectorSearchAlgorithmMetric.DotProduct,
            DistanceFunction.EuclideanDistance => VectorSearchAlgorithmMetric.Euclidean,
            _ => throw new InvalidOperationException($"Distance function '{vectorProperty.DistanceFunction}' for {nameof(VectorStoreVectorProperty)} '{vectorProperty.ModelName}' is not supported by the Azure AI Search VectorStore.")
        };

    /// <summary>
    /// Maps the given property type to the corresponding <see cref="SearchFieldDataType"/>.
    /// </summary>
    /// <param name="propertyType">The property type to map.</param>
    /// <returns>The <see cref="SearchFieldDataType"/> that corresponds to the given property type.</returns>"
    /// <exception cref="InvalidOperationException">Thrown if the given type is not supported.</exception>
    public static SearchFieldDataType GetSDKFieldDataType(Type propertyType)
        => (Nullable.GetUnderlyingType(propertyType) ?? propertyType) switch
        {
            Type t when t == typeof(string) => SearchFieldDataType.String,
            Type t when t == typeof(bool) => SearchFieldDataType.Boolean,
            Type t when t == typeof(int) => SearchFieldDataType.Int32,
            Type t when t == typeof(long) => SearchFieldDataType.Int64,
            // We don't map float to SearchFieldDataType.Single, because Azure AI Search doesn't support it.
            // Half is also listed by the SDK, but currently not supported.
            Type t when t == typeof(float) => SearchFieldDataType.Double,
            Type t when t == typeof(double) => SearchFieldDataType.Double,
            Type t when t == typeof(DateTimeOffset) => SearchFieldDataType.DateTimeOffset,

            Type t when t == typeof(string[]) => SearchFieldDataType.Collection(SearchFieldDataType.String),
            Type t when t == typeof(List<string>) => SearchFieldDataType.Collection(SearchFieldDataType.String),
            Type t when t == typeof(bool[]) => SearchFieldDataType.Collection(SearchFieldDataType.Boolean),
            Type t when t == typeof(List<bool>) => SearchFieldDataType.Collection(SearchFieldDataType.Boolean),
            Type t when t == typeof(int[]) => SearchFieldDataType.Collection(SearchFieldDataType.Int32),
            Type t when t == typeof(List<int>) => SearchFieldDataType.Collection(SearchFieldDataType.Int32),
            Type t when t == typeof(long[]) => SearchFieldDataType.Collection(SearchFieldDataType.Int64),
            Type t when t == typeof(List<long>) => SearchFieldDataType.Collection(SearchFieldDataType.Int64),
            Type t when t == typeof(float[]) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(List<float>) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(double[]) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(List<double>) => SearchFieldDataType.Collection(SearchFieldDataType.Double),
            Type t when t == typeof(DateTimeOffset[]) => SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset),
            Type t when t == typeof(List<DateTimeOffset>) => SearchFieldDataType.Collection(SearchFieldDataType.DateTimeOffset),

            _ => throw new InvalidOperationException($"Data type '{propertyType}' for {nameof(VectorStoreDataProperty)} is not supported by the Azure AI Search VectorStore.")
        };
}