dotnet/efcore · error · InvalidOperationException
A vector index is defined for `{entityType}.{property}`, but
Error message
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. What it means
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.
Source
Thrown at src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs:624
protected virtual void ValidateVectorIndex(
IIndex index,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
var entityType = index.DeclaringEntityType;
if (index.Properties.Count > 1)
{
throw new InvalidOperationException(
CosmosStrings.CompositeVectorIndex(
entityType.DisplayName(),
string.Join(",", index.Properties.Select(e => e.Name))));
}
if (index.Properties[0] is not IProperty firstVectorIndexProperty
|| firstVectorIndexProperty.GetVectorDistanceFunction() == null
|| firstVectorIndexProperty.GetVectorDimensions() == null)
{
throw new InvalidOperationException(
CosmosStrings.VectorIndexOnNonVector(
entityType.DisplayName(),
index.Properties[0].Name));
}
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual void ValidateFullTextIndex(
IIndex index,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
if (index.Properties.Count > 1)
{View on GitHub (pinned to dbf9771522)
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.
Example fix
// before
modelBuilder.Entity<Doc>()
.HasIndex(d => d.Embedding)
.IsVectorIndex(VectorIndexType.DiskANN);
// after
modelBuilder.Entity<Doc>()
.Property(d => d.Embedding)
.IsVectorProperty(DistanceFunction.Cosine, 1536);
modelBuilder.Entity<Doc>()
.HasIndex(d => d.Embedding)
.IsVectorIndex(VectorIndexType.DiskANN); Defensive patterns
Strategy: validation
Validate before calling
using var ctx = new MyContext();
foreach (var e in ctx.Model.GetEntityTypes())
{
foreach (var idx in e.GetDeclaredIndexes().Where(i => i.GetVectorIndexType() is not null))
{
foreach (var p in idx.Properties.OfType<Microsoft.EntityFrameworkCore.Metadata.IProperty>())
{
Debug.Assert(p.GetVectorDistanceFunction() is not null && p.GetVectorDimensions() is not null,
$"{e.Name}.{p.Name} is in a vector index but was not configured with IsVectorProperty()");
}
}
} Try / catch
try { ctx.Model.GetModel(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("has not been configured as a vector"))
{
logger.LogError(ex, "Vector index targets a property that is not a vector");
throw;
} Prevention
- 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.
When it happens
Trigger: Calling HasIndex(e => e.Embedding).IsVectorIndex(...) on a property that was never configured with IsVectorProperty(...), so VectorDistanceFunction/VectorDimensions are null.
Common situations: Declaring the index before configuring the vector property; forgetting the IsVectorProperty call; renaming the vector property without updating the index.
Related errors
- A vector index on '{entityType}' is defined over properties
- The time to live for analytical store was configured to '{tt
- The default time to live was configured to '{ttl1}' on '{ent
- The provisioned throughput was configured to '{throughput1}'
- The provisioned throughput was configured as manual on '{man
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/6e83b8ce08f047e5.
Report an issue: GitHub.