{"record":{"id":"0aef4881e7d8fa55","repo":"dotnet/efcore","slug":"the-type-clrtype-is-being-used-as-a-vector-bu","errorCode":null,"errorMessage":"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.","messagePattern":"The type '(.+?)' 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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Metadata/Internal/CosmosVectorType.cs","lineNumber":33,"sourceCode":"{\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public static VectorDataType CreateDefaultVectorDataType(Type clrType)\n    {\n        var elementType = clrType.TryGetElementType(typeof(ReadOnlyMemory<>))?.UnwrapNullableType()\n            ?? clrType.TryGetElementType(typeof(IEnumerable<>))?.UnwrapNullableType();\n\n        return elementType == typeof(sbyte)\n            ? VectorDataType.Int8\n            : elementType == typeof(byte)\n                ? VectorDataType.Uint8\n                : elementType == typeof(float)\n                    ? VectorDataType.Float32\n                    : throw new InvalidOperationException(CosmosStrings.BadVectorDataType(clrType.ShortDisplayName()));\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":36,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Metadata/Internal/CosmosVectorType.cs#L15-L36","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\npublic double[] Embedding { get; set; }\nmodelBuilder.Entity<Item>().Property(i => i.Embedding)\n    .HasVectorDistanceFunction(CosmosVectorDistanceFunction.Cosine)\n    .HasVectorDimensions(1536);\n\n// after\npublic float[] Embedding { get; set; }","handlingStrategy":"type-guard","validationCode":"static bool IsSupportedVectorClrType(Type t) =>\n    t == typeof(float[]) || t == typeof(byte[]) || t == typeof(sbyte[])\n    || t == typeof(ReadOnlyMemory<float>) || t == typeof(ReadOnlyMemory<byte>) || t == typeof(ReadOnlyMemory<sbyte>);","typeGuard":"static bool IsSupportedVectorClrType(Type t) =>\n    t == typeof(float[]) || t == typeof(byte[]) || t == typeof(sbyte[])\n    || t == typeof(ReadOnlyMemory<float>) || t == typeof(ReadOnlyMemory<byte>) || t == typeof(ReadOnlyMemory<sbyte>);","tryCatchPattern":null,"preventionTips":["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."],"tags":["cosmos","ef-core","metadata","vectors"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}