OracleVectorToFloatArrayPropertyHandler

A property handler that maps the Oracle VECTOR type into a float array property.

A property handler that maps the Oracle VECTOR type into a float array property.

Overview

Name Description
Class OracleVectorToFloatArrayPropertyHandler
Namespace RepoDb.PropertyHandlers.Oracle
Package RepoDb.Oracle
Implements IPropertyHandler<object, float[]>
Column type The Oracle VECTOR type
Property type float[]

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver (an OracleVector, a float[], a double[], or a JSON array string such as [1.5,2.5]) into a float[]. null, DBNull, a null vector and an empty string are returned as null.
Set Property to database Converts the float[] into an OracleVector (FLOAT32), to be written into the VECTOR column. A null array is written as null.

Exceptions

Exception Thrown When
ArgumentException The type of the value returned by the driver is not supported.

Usability

Bind the handler to the property that maps to a VECTOR column.

Attribute

public class Embedding
{
    public int Id { get; set; }

    [Map("vector"), PropertyHandler(typeof(OracleVectorToFloatArrayPropertyHandler))]
    public float[] Vector { get; set; }
}

Once bound, the library invokes the handler automatically when the property is read or written.

using (var connection = new OracleConnection(connectionString))
{
    connection.Insert(new Embedding { Id = 1, Vector = new float[] { 1.5f, 2.5f, 3.5f } });
    var embedding = connection.Query<Embedding>(e => e.Id == 1).First();
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Embedding>()
    .PropertyHandler<OracleVectorToFloatArrayPropertyHandler>(e => e.Vector);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Embedding, OracleVectorToFloatArrayPropertyHandler>(e => e.Vector, new OracleVectorToFloatArrayPropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type float[]:

PropertyHandlerMapper.Add<float[], OracleVectorToFloatArrayPropertyHandler>(new OracleVectorToFloatArrayPropertyHandler(), true);

A type level mapping is process-wide: it is applied to every float[] property of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless every float[] property maps to a VECTOR column.

See Also