Interface VectorTypeConverter<T>
- Type Parameters:
T- The persisted driver type for a given dialect (e.g. org.postgresql.util.PGobject/PGvector, String, byte[])
public interface VectorTypeConverter<T>
Dialect-specific converter for vector values to and from the persisted database type (JDBC/R2DBC).
Responsibilities:
- Provide the exact persisted driver type via
getPersistedType() (e.g. PGvector, String, byte[]).
- Declare the supported vector subtypes via supportedVectorTypes() (keep this list minimal).
- Identify the target database via databaseType().
Selection semantics:
- At runtime, Micronaut Data selects a converter based on the current DatabaseType.
- Implementations should avoid overlapping support for the same database type; ambiguous configurations may result in a selection error.
- For read paths, converters may be chosen using both the database type and the actual persisted type (see getPersistedType()).- Since:
- 5.0.0
- Author:
- Nemanja Mikic
-
Method Summary
Modifier and TypeMethodDescriptionConvert an entity-sideVectorinto the dialect-specific persisted type.Convert a dialect-specific persisted value into the entity-sideVector.The database type (dialect family) this converter targets.The exact persisted driver type this converter reads/writes.default booleanWhether this converter is designed for sparse vectors.The exact vector subtypes supported by this converter for the declared database type.
-
Method Details
-
convert
Convert an entity-sideVectorinto the dialect-specific persisted type. Contract: - The supplied vector should be an instance of one ofsupportedVectorTypes()or a compatible superclass. - The returned object MUST be an instance ofgetPersistedType().- Parameters:
vector- the vector value from the entity side (non-null)- Returns:
- the persisted value to bind to JDBC/R2DBC (non-null)
-
convert
Convert a dialect-specific persisted value into the entity-sideVector. Contract: - The supplied object SHOULD be an instance ofgetPersistedType()(or assignable). - ThetargetTypewill be one of the supported vector types orVector.class. - Converters SHOULD perform the necessary numeric conversions (e.g. float/double narrowing) consistently.- Parameters:
object- the persisted value (type returned bygetPersistedType(), non-null)targetType- the target entity type (typicallyVector.classor a concrete subtype)- Returns:
- the entity-side vector value (non-null)
-
supportedVectorTypes
The exact vector subtypes supported by this converter for the declared database type. Keep this set minimal to avoid ambiguity (e.g. prefer a single, precise subtype, orVector.classif generic).- Returns:
- the set of supported vector types (non-empty)
-
databaseType
DatabaseType databaseType()The database type (dialect family) this converter targets.- Returns:
- the database type
-
getPersistedType
-
isSparseSupported
default boolean isSparseSupported()Whether this converter is designed for sparse vectors. Used as a tiebreaker when multiple converters exist for the same database type. Implementations that handleSparseVectorpersisted paths should returntrue.- Returns:
trueif sparse vectors are supported/preferred by this converter
-