{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Metadata/Internal/CosmosVectorType.cs#L15-L36","documentation":"Thrown by CosmosVectorType.CreateDefaultVectorDataType when the CLR type's element type is not sbyte, byte, or float. The factory unwraps ReadOnlyMemory<T> or IEnumerable<T> and maps only those three element types (Int8, Uint8, Float32); anything else cannot be expressed as a Cosmos vector data type.","triggerScenarios":"Configuring IsVectorProperty on a property whose CLR type is e.g. double[], long[], ReadOnlyMemory<double>, Vector128, a custom struct, or List<decimal>. ValidateVectorProperty calls this factory when both distance function and dimensions are set.","commonSituations":"Using a higher-precision numeric type for embeddings; copying embedding DTOs from another SDK; using System.Numerics vector types directly.","solutions":["Change the embedding property CLR type to one of: ReadOnlyMemory<byte>, byte[], ReadOnlyMemory<sbyte>, sbyte[], ReadOnlyMemory<float>, float[].","If your upstream model produces doubles/longs, cast to float before storing and back after reading.","Re-validate the model to confirm the data type is now inferred (VectorDataType.Int8/Uint8/Float32)."],"exampleFix":"// before\npublic class Doc { public ReadOnlyMemory<double> Embedding { get; set; } }\n\n// after\npublic class Doc { public ReadOnlyMemory<float> Embedding { get; set; } }","handlingStrategy":"type-guard","validationCode":"// Reject unsupported vector CLR types at startup.\nstatic bool IsSupportedVectorType(Type t)\n    => t == typeof(ReadOnlyMemory<byte>) || t == typeof(byte[])\n    || t == typeof(ReadOnlyMemory<sbyte>) || t == typeof(sbyte[])\n    || t == typeof(ReadOnlyMemory<float>) || t == typeof(float[]);\nforeach (var et in modelBuilder.Model.GetEntityTypes())\nforeach (var p in et.GetProperties())\n    if (p.GetVectorDistanceFunction() is not null && !IsSupportedVectorType(p.ClrType))\n        throw new InvalidOperationException($\"{p.Name} uses an unsupported vector CLR type {p.ClrType}.\");","typeGuard":"static bool IsSupportedVectorType(Type t) =>\n    t == typeof(ReadOnlyMemory<byte>) || t == typeof(byte[]) ||\n    t == typeof(ReadOnlyMemory<sbyte>) || t == typeof(sbyte[]) ||\n    t == typeof(ReadOnlyMemory<float>) || t == typeof(float[]);","tryCatchPattern":null,"preventionTips":["Standardize embedding properties on ReadOnlyMemory<float>.","Cast double/long embeddings to float before assignment.","Add a startup type check on all vector-configured properties."],"tags":["cosmos","vector-search","type-mapping","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}