Open
Description
Discussed in #1548, originally posted by @harrison314.
Add support for the VECTOR(n)
type, which is available since MariaDB 11.7.
https://mariadb.com/kb/en/vector-overview/
I've solved it with a workaround:
internal static class MySqlExtensions
{
public static MySqlParameter AddWithVectorValue(this MySqlParameterCollection parameters, string name, ReadOnlySpan<float> vector)
{
byte[] buffer = new byte[vector.Length * 4];
for (int i = 0; i < vector.Length; i++)
{
BinaryPrimitives.WriteSingleLittleEndian(buffer.AsSpan(i * 4), vector[i]);
}
MySqlParameter p = parameters.Add(name, System.Data.DbType.Binary);
p.Value = buffer;
return p;
}
}
```</div>
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Support MariaDB `VECTOR` data type[/-][+]Support `VECTOR` data type[/+]bgrainger commentedon Feb 23, 2025
VECTOR
was also added in MySQL 9.0: https://dev.mysql.com/doc/relnotes/mysql/9.0/en/news-9-0-0.html#mysqld-9-0-0-vectorsbgrainger commentedon Feb 23, 2025
The underlying type should probably be
float[]
(notReadOnlySpan<float>
as that can't be boxed forMySqlParameter.Value
).Possibly could add
GetFieldValue<ReadOnlySpan<float>>
to get a view of the row that's been retrieved.Support VECTOR data type
bgrainger commentedon Feb 24, 2025
The VECTOR data type was added in Connector/NET 8.4.0.
bgrainger commentedon Feb 24, 2025
Preliminary tests with MariaDB 11.7 indicate that it doesn't use a dedicated on-the-wire type for
VECTOR(n)
, so all results come back as BLOBs. (Possibly waiting on https://jira.mariadb.org/browse/MDEV-35831.) This means thatMySqlDataReader.GetValue(n)
will returnbyte[]
and users will have to useBuffer.BlockCopy
orMemoryMarshal.Cast<>
to get afloat[]
.harrison314 commentedon Feb 24, 2025
I think it's enough to implement
float[]
, because the array will always be allocated anyway. I usedReadOnlySpan<float>
in my helper method because it is a generic type. But it may not be suitable for implementing methods in the MySQL connector.MemoryMarshal.Cast<>
may not work on all processors due to big and little endian.harrison314 commentedon May 1, 2025
Don't you plan to release at least a preview nuget with vector support in the near future?