dotnet/efcore · error · InvalidOperationException
The type '{clrType}' is being used as a vector, but the vect
Error message
The type '{clrType}' is being used as a vector, but the vector data type cannot be inferred. Only 'ReadOnlyMemory<byte>, ReadOnlyMemory<sbyte>, ReadOnlyMemory<float>, byte[], sbyte[], and float[] are supported. What it means
Thrown by CosmosVectorType.CreateDefaultVectorDataType when the property CLR type is not ReadOnlyMemory<byte/sbyte/float> or one of the array forms byte[]/sbyte[]/float[]. CreateDefaultVectorDataType unwraps ReadOnlyMemory<> or IEnumerable<> element types and only accepts sbyte/byte/float; anything else (double, long, a custom struct, decimal) throws. The message lists the supported types.
Source
Thrown at src/EFCore.Cosmos/Metadata/Internal/CosmosVectorType.cs:33
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static VectorDataType CreateDefaultVectorDataType(Type clrType)
{
var elementType = clrType.TryGetElementType(typeof(ReadOnlyMemory<>))?.UnwrapNullableType()
?? clrType.TryGetElementType(typeof(IEnumerable<>))?.UnwrapNullableType();
return elementType == typeof(sbyte)
? VectorDataType.Int8
: elementType == typeof(byte)
? VectorDataType.Uint8
: elementType == typeof(float)
? VectorDataType.Float32
: throw new InvalidOperationException(CosmosStrings.BadVectorDataType(clrType.ShortDisplayName()));
}
}
View on GitHub (pinned to dbf9771522)
Solutions
- Change the vector property CLR type to one of ReadOnlyMemory<float>, float[], ReadOnlyMemory<byte>, byte[], ReadOnlyMemory<sbyte>, or sbyte[].
- If the source data is double/decimal, convert it to float[] before assigning to the entity property.
Example fix
// before
public double[] Embedding { get; set; }
modelBuilder.Entity<Item>().Property(i => i.Embedding)
.HasVectorDistanceFunction(CosmosVectorDistanceFunction.Cosine)
.HasVectorDimensions(1536);
// after
public float[] Embedding { get; set; } Defensive patterns
Strategy: type-guard
Validate before calling
static bool IsSupportedVectorClrType(Type t) =>
t == typeof(float[]) || t == typeof(byte[]) || t == typeof(sbyte[])
|| t == typeof(ReadOnlyMemory<float>) || t == typeof(ReadOnlyMemory<byte>) || t == typeof(ReadOnlyMemory<sbyte>); Type guard
static bool IsSupportedVectorClrType(Type t) =>
t == typeof(float[]) || t == typeof(byte[]) || t == typeof(sbyte[])
|| t == typeof(ReadOnlyMemory<float>) || t == typeof(ReadOnlyMemory<byte>) || t == typeof(ReadOnlyMemory<sbyte>); Prevention
- Standardize all vector properties on float[] (or ReadOnlyMemory<float>).
- Convert embedding vectors from double/decimal to float at the boundary before assigning to the entity.
When it happens
Trigger: Configuring a vector property with HasVectorDistanceFunction / HasVectorDimensions on a property whose CLR type is e.g. double[], long[], Vector<float>, or a custom struct, then triggering model validation (which calls CreateDefaultVectorDataType).
Common situations: Bringing embeddings stored as double[] from another system. Using a numeric type that the model author assumed was supported. Wrapping vectors in a custom struct for domain clarity.
Related errors
- 'Except' cannot be called on the builder returned by 'HasAut
- The type '{givenType}' cannot be mapped as a dictionary beca
- The value '{value}' provided for argument '{argumentName}' m
- Cosmos-specific methods can only be used when the context is
- The '{methodName}' method is not supported because the query
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/0aef4881e7d8fa55.
Report an issue: GitHub.