Repository: microsoft/semantic-kernel
File: dotnet/src/VectorData/SqliteVec/SqliteMapper.cs (C#)

Code before:
        if (includeVectors)
        {
            foreach (var property in model.VectorProperties)
            {
                int ordinal = reader.GetOrdinal(property.StorageName);

                if (reader.IsDBNull(ordinal))
                {
                    continue;
                }

                // SqliteVec provides the vector data as a byte[], which we need to convert to a float[].
                // In modern .NET, we allocate a float[] of the right size, reinterpret-cast it into byte[],
                // and then read the data into that via Stream.
                // In .NET Framework, which doesn't have Span APIs on Stream, we just create a copy (inefficient).
#if NET8_0_OR_GREATER
                using var stream = reader.GetStream(ordinal);

                var length = stream.Length;
                if (length % 4 != 0)
                {
                    throw new InvalidOperationException($"Retrieved value for vector property '{property.StorageName}' which is not a valid byte array length (expected multiple of 4, got {stream.Length}).");
                }

                var floats = new float[length / 4];
                var bytes = MemoryMarshal.Cast<float, byte>((Span<float>)floats);
                stream.ReadExactly(bytes);
#else
                var floats = MemoryMarshal.Cast<byte, float>((byte[])reader[ordinal]).ToArray();
#endif

                property.SetValueAsObject(
                    record,
                    (Nullable.GetUnderlyingType(property.Type) ?? property.Type) switch
                    {
                        var t when t == typeof(ReadOnlyMemory<float>) => new ReadOnlyMemory<float>(floats),
                        var t when t == typeof(Embedding<float>) => new Embedding<float>(floats),
                        var t when t == typeof(float[]) => floats,

                        _ => throw new UnreachableException()
                    });
            }
        }

        return record;
    }

    private static object? GetPropertyValue(DbDataReader reader, string propertyName, Type propertyType)
    {
        int ordinal = reader.GetOrdinal(propertyName);


Review comment (suggestion):
Makes sense - this is a result of C# 14's first-class spans feature.

Recommend using AsSpan() here; I'm not aware of any perf difference between that and casting, but it's slightly more idiomatic simple in any case:

```suggestion
                var bytes = MemoryMarshal.Cast<float, byte>(floats.AsSpan());
```

Code after:
        if (includeVectors)
        {
            foreach (var property in model.VectorProperties)
            {
                int ordinal = reader.GetOrdinal(property.StorageName);

                if (reader.IsDBNull(ordinal))
                {
                    continue;
                }

                // SqliteVec provides the vector data as a byte[], which we need to convert to a float[].
                // In modern .NET, we allocate a float[] of the right size, reinterpret-cast it into byte[],
                // and then read the data into that via Stream.
                // In .NET Framework, which doesn't have Span APIs on Stream, we just create a copy (inefficient).
#if NET8_0_OR_GREATER
                using var stream = reader.GetStream(ordinal);

                var length = stream.Length;
                if (length % 4 != 0)
                {
                    throw new InvalidOperationException($"Retrieved value for vector property '{property.StorageName}' which is not a valid byte array length (expected multiple of 4, got {stream.Length}).");
                }

                var floats = new float[length / 4];
                var bytes = MemoryMarshal.Cast<float, byte>(floats.AsSpan());
                stream.ReadExactly(bytes);
#else
                var floats = MemoryMarshal.Cast<byte, float>((byte[])reader[ordinal]).ToArray();
#endif

                property.SetValueAsObject(
                    record,
                    (Nullable.GetUnderlyingType(property.Type) ?? property.Type) switch
                    {
                        var t when t == typeof(ReadOnlyMemory<float>) => new ReadOnlyMemory<float>(floats),
                        var t when t == typeof(Embedding<float>) => new Embedding<float>(floats),
                        var t when t == typeof(float[]) => floats,

                        _ => throw new UnreachableException()
                    });
            }
        }

        return record;
    }

    private static object? GetPropertyValue(DbDataReader reader, string propertyName, Type propertyType)
    {
        int ordinal = reader.GetOrdinal(propertyName);