{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L606-L642","documentation":"Thrown by ValidateVectorIndex when the single property of a vector index is not an IProperty, or has not been configured as a vector (missing GetVectorDistanceFunction() or GetVectorDimensions()). A property must be marked as a vector via IsVectorProperty(distanceFunction, dimensions) before it can be the target of a vector index.","triggerScenarios":"Calling HasIndex(e => e.Embedding).IsVectorIndex(...) on a property that was never configured with IsVectorProperty(...), so VectorDistanceFunction/VectorDimensions are null.","commonSituations":"Declaring the index before configuring the vector property; forgetting the IsVectorProperty call; renaming the vector property without updating the index.","solutions":["Configure the property as a vector first: modelBuilder.Entity<E>().Property(e => e.Embedding).IsVectorProperty(DistanceFunction.Cosine, 1536).","Ensure the vector index references the same property that was configured with IsVectorProperty.","Set both distance function and dimensions, since the validator requires both to be non-null."],"exampleFix":"// before\nmodelBuilder.Entity<Doc>()\n    .HasIndex(d => d.Embedding)\n    .IsVectorIndex(VectorIndexType.DiskANN);\n\n// after\nmodelBuilder.Entity<Doc>()\n    .Property(d => d.Embedding)\n    .IsVectorProperty(DistanceFunction.Cosine, 1536);\nmodelBuilder.Entity<Doc>()\n    .HasIndex(d => d.Embedding)\n    .IsVectorIndex(VectorIndexType.DiskANN);","handlingStrategy":"validation","validationCode":"using var ctx = new MyContext();\nforeach (var e in ctx.Model.GetEntityTypes())\n{\n    foreach (var idx in e.GetDeclaredIndexes().Where(i => i.GetVectorIndexType() is not null))\n    {\n        foreach (var p in idx.Properties.OfType<Microsoft.EntityFrameworkCore.Metadata.IProperty>())\n        {\n            Debug.Assert(p.GetVectorDistanceFunction() is not null && p.GetVectorDimensions() is not null,\n                $\"{e.Name}.{p.Name} is in a vector index but was not configured with IsVectorProperty()\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try { ctx.Model.GetModel(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"has not been configured as a vector\"))\n{\n    logger.LogError(ex, \"Vector index targets a property that is not a vector\");\n    throw;\n}","preventionTips":["Always configure IsVectorProperty(distanceFunction, dimensions) on the property before adding a vector index over it.","Set both distance function and dimensions; the validator requires both.","When renaming a vector property, update both the IsVectorProperty and HasIndex declarations."],"tags":["cosmos","configuration","model-validation","vector-index"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}