{"record":{"id":"6e83b8ce08f047e5","repo":"dotnet/efcore","slug":"a-vector-index-is-defined-for-entitytype-prope","errorCode":null,"errorMessage":"A vector index is defined for `{entityType}.{property}`, but this property has not been configured as a vector. Use 'IsVectorProperty()' in 'OnModelCreating' to configure the property as a vector.","messagePattern":"A vector index is defined for `(.+?)\\.(.+?)`, but this property has not been configured as a vector\\. Use 'IsVectorProperty\\(\\)' in 'OnModelCreating' to configure the property as a vector\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":624,"sourceCode":"    protected virtual void ValidateVectorIndex(\n        IIndex index,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        var entityType = index.DeclaringEntityType;\n\n        if (index.Properties.Count > 1)\n        {\n            throw new InvalidOperationException(\n                CosmosStrings.CompositeVectorIndex(\n                    entityType.DisplayName(),\n                    string.Join(\",\", index.Properties.Select(e => e.Name))));\n        }\n\n        if (index.Properties[0] is not IProperty firstVectorIndexProperty\n            || firstVectorIndexProperty.GetVectorDistanceFunction() == null\n            || firstVectorIndexProperty.GetVectorDimensions() == null)\n        {\n            throw new InvalidOperationException(\n                CosmosStrings.VectorIndexOnNonVector(\n                    entityType.DisplayName(),\n                    index.Properties[0].Name));\n        }\n    }\n\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    protected virtual void ValidateFullTextIndex(\n        IIndex index,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        if (index.Properties.Count > 1)\n        {","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L606-L642","documentation":"Thrown during model validation when an entity has a vector index whose single indexed property was not configured as a vector. CosmosModelValidator.ValidateVectorIndex checks that the property is an IProperty AND has both a vector distance function and vector dimensions set (the annotations applied by IsVectorProperty()). If any of those is missing the index is meaningless because Cosmos cannot build a vector index over a non-vector property.","triggerScenarios":"Calling HasVectorIndex on an entity for a property, but never calling IsVectorProperty(...) (with distance function + dimensions) on that same property in OnModelCreating. Also when an index is renamed/repurposed to a vector index while the property still holds a scalar mapping.","commonSituations":"Following a tutorial that shows HasVectorIndex but skips the IsVectorProperty call; copying vector config from another entity and forgetting the dimensions/distance-function arguments; upgrading EF Core Cosmos to a version that split vector index and vector property configuration.","solutions":["In OnModelCreating, call entityTypeBuilder.Property(p => p.Embedding).IsVectorProperty(distanceFunction, dimensions) on the property named in the error before/alongside HasVectorIndex.","Verify the property CLR type is a supported vector type (ReadOnlyMemory<float>, float[], ReadOnlyMemory<byte>, byte[], ReadOnlyMemory<sbyte>, sbyte[]).","Ensure dimensions is a positive int and distanceFunction is a valid Cosmos distance function string (e.g. 'cosine', 'dotproduct', 'euclidean')."],"exampleFix":"// before\nmodelBuilder.Entity<Doc>()\n    .HasIndex(d => d.Embedding)              // ordinary index\n    .HasVectorIndex();\n\n// after\nmodelBuilder.Entity<Doc>(b =>\n{\n    b.Property(d => d.Embedding)\n     .IsVectorProperty(DistanceFunction.Cosine, dimensions: 1536);\n    b.HasIndex(d => d.Embedding)\n     .HasVectorIndex();\n});","handlingStrategy":"validation","validationCode":"// Before UseCosmos / first query, assert the property is vector-configured.\nvar prop = modelBuilder.Model.FindEntityType(typeof(Doc))!\n    .FindProperty(nameof(Doc.Embedding))!;\nif (prop.GetVectorDistanceFunction() is null || prop.GetVectorDimensions() is null)\n    throw new InvalidOperationException(\"Configure IsVectorProperty before HasVectorIndex.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair HasVectorIndex with IsVectorProperty(distanceFunction, dimensions) in the same OnModelCreating block.","Add a model sanity-check unit test that iterates vector indexes and asserts their property has distance function + dimensions set.","Keep vector config centralized in one entity configuration class to avoid drift."],"tags":["cosmos","vector-search","model-validation","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}