Skip to content

Conversation

@Knalltuete5000
Copy link

@Knalltuete5000 Knalltuete5000 commented Jun 21, 2025

This will add support for the vector datatype to be able to map float[], Memory<float> or ReadOnlyMemory<float> to the vector column type. This pr will not implement any functions like Distance since the function is only available on mariadb (See note in the mysql documentation) and the function definition is different on both databases.

To configure the this the following via attributes is possible

    [Column(TypeName = "vector")]  // defines the column type
    [MaxLength(384)]  // defines the dimensions for the vector
    public ReadOnlyMemory<float> Embedding { get; set; }

The vector datatype is supported on mysql >= 9.0 and mariadb >= 11.7.

For this PR to worke the current main-branch of the MySqlConnector is required. This adds support to read the vector column from the database. float[], Memory<float> or ReadOnlyMemorycan be directly mapped to a mysql database, mariadb a special typemapper is used to map from a byte[]to eitherfloat[], MemoryorReadOnlyMemory`.

Closes #1999

* Add indicator if vectors are supported on the database
  * Enable support for mariadb 11.7 and greater
  * Enable support for mysql 9.0 and greater
* Add vector to the SqlGenerator
Adjust the abstract class MySqlTypeMapping to define
the StoreTypePostfix for the mapping
* Add mappers to support reading and writing vectors
  * For MySql: Add the MySqlVectorTypeMapping to use
    float[], Memory<float> or ReadOnlyMemory<float> as
    the base types for vectors
  * For MariaDb: Add the MySqlVectorByteTypeMapping to
    use float[], Memory<float> or ReadOnlyMemory<float>
    as the base types for vectors. These must be converted
    from a byte[]
* Register the type mappings dependent on the server type
  used
* Add float[] to the DataTypes to represent a vector
* Add Memory<float> to the DataTypes to represent a vector
* Add ReadOnlyMemory<float> to the DataTypes to represent a vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vector Support

1 participant