dotnet/efcore · error · InvalidOperationException
The requested configuration is not stored in the…
Error message
The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'.
What it means
CosmosIndexExtensions.GetVectorIndexType throws InvalidOperationException(CoreStrings.RuntimeModelMissingData) when the supplied index is a RuntimeIndex - i.e. it comes from the read-optimized model that EF builds for fast startup. Vector index annotations (CosmosAnnotationNames.VectorIndexType) are only stored on the design-time model because they are configuration metadata, not runtime data. The exception is by design and tells you to read the value from the design-time model instead.
Solutions
- Read the index from the design-time model: use DbContext.GetService<IDesignTimeModel>().Model and call GetVectorIndexType on indexes obtained from it.
- If you only need the value at design time (migration, model snapshot, scaffolding), keep that code path off the runtime model entirely.
- If the call site is on the hot path, reconsider whether you actually need this metadata at runtime - if not, cache it from the design-time model at startup.
- Add an 'index is RuntimeIndex' check before the call to give a clearer error in custom tooling.
Example fix
// before - throws on the runtime model
var type = dbContext.Model
.FindEntityType(typeof(Doc))!
.GetIndexes().First()
.GetVectorIndexType();
// after - read from the design-time model
var designModel = dbContext.GetService<IDesignTimeModel>().Model;
var type = designModel
.FindEntityType(typeof(Doc))!
.GetIndexes().First()
.GetVectorIndexType(); Defensive patterns
Strategy: type-guard
Validate before calling
// Route to the design-time model whenever you need to read Cosmos configuration metadata.
IModel GetDesignTimeModel(DbContext db) => db.GetService<IDesignTimeModel>().Model;
var vectorType = GetDesignTimeModel(dbContext)
.FindEntityType(typeof(Doc))!.GetIndexes().First().GetVectorIndexType(); Type guard
static bool IsRuntimeIndex(IIndex index) => index is RuntimeIndex;
// Use before calling GetVectorIndexType to choose the right model source.
if (IsRuntimeIndex(index)) throw new InvalidOperationException("Use IDesignTimeModel for vector index metadata."); Prevention
- Never read Cosmos-specific annotations off DbContext.Model for runtime use.
- Centralize metadata reads behind a helper that always uses IDesignTimeModel.
- Tag call sites that need design-time metadata so they are easy to audit on upgrade.
- If a hot path needs the value, cache it from the design-time model at startup.
When it happens
Trigger: Calling GetVectorIndexType() on an IIndex obtained from the runtime model (e.g. from DbContext.Model, or from an entity type returned by ModelSource's cached runtime model); iterating IModel.GetEntityTypes().SelectMany(e => e.GetIndexes()) on the runtime model and querying vector index type; using a compiled-model scenario where only the runtime model is loaded.
Common situations: After EF Core 6+ split design-time vs runtime models, code that used to read annotations directly off DbContext.Model now hits this; tooling or migration code that walks the model and reads Cosmos annotations; production hot-path code that mistakenly reads configuration metadata it does not need.
Related errors
- The value ' ' provided for argument ' ' must be a valid…
- The value ' ' provided for argument ' ' must be a valid…
- A vector index is defined for
- A vector index on ' ' is defined over properties ` `. A…
- An Azure Cosmos DB container name is defined on entity type
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/060f88b8772a294a.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Cosmos/Extensions/CosmosIndexExtensions.cs:26
/// <summary>
/// Index extension methods for Azure Cosmos DB-specific metadata.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
public static class CosmosIndexExtensions
{
/// <summary>
/// Returns the vector index type to use, such as "flat", "diskANN", or "quantizedFlat".
/// See <see href="https://aka.ms/ef-cosmos-vectors">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.
/// </summary>
/// <param name="index">The index.</param>
/// <returns>The index type to use, or <see langword="null" /> if none is set.</returns>
public static VectorIndexType? GetVectorIndexType(this IReadOnlyIndex index)
=> (index is RuntimeIndex)
? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)
: (VectorIndexType?)index[CosmosAnnotationNames.VectorIndexType];
/// <summary>
/// Sets the vector index type to use, such as "flat", "diskANN", or "quantizedFlat".
/// See <see href="https://aka.ms/ef-cosmos-vectors">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="indexType">The index type to use.</param>
public static void SetVectorIndexType(this IMutableIndex index, VectorIndexType? indexType)
=> index.SetOrRemoveAnnotation(CosmosAnnotationNames.VectorIndexType, indexType);
/// <summary>
/// Sets the vector index type to use, such as "flat", "diskANN", or "quantizedFlat".
/// See <see href="https://aka.ms/ef-cosmos-vectors">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="indexType">The index type to use.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>View on GitHub (pinned to 3a2006ef56)