{"record":{"id":"96f7491aa4a92a05","repo":"dotnet/efcore","slug":"a-vector-index-on-entitytype-is-defined-over-p-96f749","errorCode":null,"errorMessage":"A vector index on '{entityType}' is defined over properties `{properties}`. A vector index can only target a single property.","messagePattern":"A vector index on '(.+?)' is defined over properties `(.+?)`\\. A vector index can only target a single property\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs","lineNumber":185,"sourceCode":"    {\n        var (parameters, wrapper) = parametersTuple;\n        var partitionKeyPaths = parameters.PartitionKeyStoreNames.Select(e => \"/\" + e).ToList();\n\n        var vectorIndexes = new Collection<VectorIndexPath>();\n        var fullTextIndexPaths = new Collection<FullTextIndexPath>();\n        var includedPaths = new Collection<IncludedPath>();\n        var conventionIncludedPaths = new Collection<IncludedPath>();\n        var compositeIndexes = new Collection<Collection<CompositePath>>();\n        var seenIncludedPaths = new HashSet<string>();\n        var seenCompositeIndexes = new HashSet<string>();\n        foreach (var index in parameters.Indexes)\n        {\n            var vectorIndexType = index.GetVectorIndexType();\n            if (vectorIndexType != null)\n            {\n                if (index.Properties.Count > 1)\n                {\n                    throw new InvalidOperationException(\n                        CosmosStrings.CompositeVectorIndex(\n                            index.DeclaringEntityType.DisplayName(),\n                            string.Join(\",\", index.Properties.Select(e => e.Name))));\n                }\n\n                vectorIndexes.Add(\n                    new VectorIndexPath { Path = GetJsonPropertyPathFromRoot(index.Properties[0]), Type = vectorIndexType.Value });\n                continue;\n            }\n\n            if (index.IsFullTextIndex() == true)\n            {\n                if (index.Properties.Count > 1)\n                {\n                    throw new InvalidOperationException(\n                        CosmosStrings.CompositeFullTextIndex(\n                            index.DeclaringEntityType.DisplayName(),\n                            string.Join(\",\", index.Properties.Select(e => e.Name))));","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs#L167-L203","documentation":"Azure Cosmos DB vector indexes can only be defined over a single property path. During container creation (CosmosClientWrapper.cs:183-189), EF Core iterates all indexes and rejects any index whose GetVectorIndexType() is non-null and whose Properties.Count exceeds 1. A composite vector index has no meaning in the Cosmos indexing policy schema.","triggerScenarios":"Configuring an index with multiple properties and marking it as a vector index, e.g. modelBuilder.Entity<T>().HasIndex([x => x.Embedding, x => x.Other]).ForCosmos().IsVectorIndex(VectorIndexType.DiskANN). This fires at container-creation time (EnsureCreatedAsync/EnsureCreated), not at model validation.","commonSituations":"Copy-pasting a composite index definition and adding IsVectorIndex() to it. Accidentally including a second property (like a partition key) in a vector index definition. Migrating from relational where composite indexes are common.","solutions":["Define the vector index on a single property: modelBuilder.Entity<T>().HasIndex(x => x.Embedding).ForCosmos().IsVectorIndex(VectorIndexType.DiskANN).","If you need a separate index for another property, declare it as its own single-property index.","Re-run EnsureCreatedAsync (or recreate the container) after fixing the model."],"exampleFix":"// before\nmodelBuilder.Entity<Article>()\n    .HasIndex(a => new { a.Embedding, a.Category })\n    .ForCosmos()\n    .IsVectorIndex(VectorIndexType.DiskANN);\n\n// after\nmodelBuilder.Entity<Article>()\n    .HasIndex(a => a.Embedding)\n    .ForCosmos()\n    .IsVectorIndex(VectorIndexType.DiskANN);","handlingStrategy":"validation","validationCode":"// Validate at model finalization that no vector index spans multiple properties.\nforeach (var entityType in model.GetEntityTypes())\n{\n    foreach (var index in entityType.GetIndexes())\n    {\n        if (index.GetVectorIndexType() is not null && index.Properties.Count > 1)\n            throw new InvalidOperationException($\"Vector index on {entityType.DisplayName()} has multiple properties.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define vector indexes on a single property using HasIndex(x => x.Property), never an anonymous composite.","Review all ForCosmos().IsVectorIndex() calls during code review.","Add a model-validation test that checks vector indexes have exactly one property."],"tags":["cosmos","vector-search","index-configuration","container-creation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}