{"record":{"id":"060f88b8772a294a","repo":"dotnet/efcore","slug":"the-requested-configuration-is-not-stored-in-the-r","errorCode":null,"errorMessage":"The requested configuration is not stored in the read-optimized model, please use 'DbContext.GetService<IDesignTimeModel>().Model'.","messagePattern":"The requested configuration is not stored in the read-optimized model, please use 'DbContext\\.GetService<IDesignTimeModel>\\(\\)\\.Model'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Extensions/CosmosIndexExtensions.cs","lineNumber":26,"sourceCode":"\n/// <summary>\n///     Index extension methods for Azure Cosmos DB-specific metadata.\n/// </summary>\n/// <remarks>\n///     See <see href=\"https://aka.ms/efcore-docs-modeling\">Modeling entity types and relationships</see>, and\n///     <see href=\"https://aka.ms/efcore-docs-cosmos\">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.\n/// </remarks>\npublic static class CosmosIndexExtensions\n{\n    /// <summary>\n    ///     Returns the vector index type to use, such as \"flat\", \"diskANN\", or \"quantizedFlat\".\n    ///     See <see href=\"https://aka.ms/ef-cosmos-vectors\">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.\n    /// </summary>\n    /// <param name=\"index\">The index.</param>\n    /// <returns>The index type to use, or <see langword=\"null\" /> if none is set.</returns>\n    public static VectorIndexType? GetVectorIndexType(this IReadOnlyIndex index)\n        => (index is RuntimeIndex)\n            ? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)\n            : (VectorIndexType?)index[CosmosAnnotationNames.VectorIndexType];\n\n    /// <summary>\n    ///     Sets the vector index type to use, such as \"flat\", \"diskANN\", or \"quantizedFlat\".\n    ///     See <see href=\"https://aka.ms/ef-cosmos-vectors\">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.\n    /// </summary>\n    /// <param name=\"index\">The index.</param>\n    /// <param name=\"indexType\">The index type to use.</param>\n    public static void SetVectorIndexType(this IMutableIndex index, VectorIndexType? indexType)\n        => index.SetOrRemoveAnnotation(CosmosAnnotationNames.VectorIndexType, indexType);\n\n    /// <summary>\n    ///     Sets the vector index type to use, such as \"flat\", \"diskANN\", or \"quantizedFlat\".\n    ///     See <see href=\"https://aka.ms/ef-cosmos-vectors\">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.\n    /// </summary>\n    /// <param name=\"index\">The index.</param>\n    /// <param name=\"indexType\">The index type to use.</param>\n    /// <param name=\"fromDataAnnotation\">Indicates whether the configuration was specified using a data annotation.</param>","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Extensions/CosmosIndexExtensions.cs#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before - throws on the runtime model\nvar type = dbContext.Model\n    .FindEntityType(typeof(Doc))!\n    .GetIndexes().First()\n    .GetVectorIndexType();\n\n// after - read from the design-time model\nvar designModel = dbContext.GetService<IDesignTimeModel>().Model;\nvar type = designModel\n    .FindEntityType(typeof(Doc))!\n    .GetIndexes().First()\n    .GetVectorIndexType();","handlingStrategy":"type-guard","validationCode":"// Route to the design-time model whenever you need to read Cosmos configuration metadata.\nIModel GetDesignTimeModel(DbContext db) => db.GetService<IDesignTimeModel>().Model;\n\nvar vectorType = GetDesignTimeModel(dbContext)\n    .FindEntityType(typeof(Doc))!.GetIndexes().First().GetVectorIndexType();","typeGuard":"static bool IsRuntimeIndex(IIndex index) => index is RuntimeIndex;\n\n// Use before calling GetVectorIndexType to choose the right model source.\nif (IsRuntimeIndex(index)) throw new InvalidOperationException(\"Use IDesignTimeModel for vector index metadata.\");","tryCatchPattern":null,"preventionTips":["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."],"tags":["ef-core","cosmos","metadata","runtime-model","vector-search"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}