Skip to content

Add support for JSON, composite, include and exclude Cosmos indexes - #38360

Merged
AndriySvyryd merged 1 commit into
mainfrom
Issue38067
Jun 9, 2026
Merged

AndriySvyryd merged 1 commit into
mainfrom
Issue38067

Conversation

@AndriySvyryd

@AndriySvyryd AndriySvyryd commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Add support for chaining into complex collections in indexes
Add support for keys spanning non-collection complex properties

Fixes #38067
Fixes #17303

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the EF Core Cosmos provider to support richer indexing scenarios (including indexes through complex types/complex collections, composite indexes, and container-level automatic indexing include/exclude behavior), and updates validation and tests accordingly.

Changes:

  • Add Cosmos container automatic-indexing configuration (HasAutomaticIndexing(...) + Except(...)) and flow these settings into container creation.
  • Generate Cosmos indexing-policy paths for scalar properties nested in complex types and complex collections (including escaping/quoting as needed), and emit composite/vector/full-text index policy entries.
  • Update Cosmos model validation and expand functional/unit test coverage (including compiled-model baselines) for the new indexing behavior.

Reviewed changes

Copilot reviewed 32 out of 33 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/EFCore.Cosmos.Tests/Storage/Internal/CosmosClientWrapperTest.cs Adds unit coverage for JSON path generation/escaping for scalar, complex, and complex-collection segments.
test/EFCore.Cosmos.Tests/Metadata/CosmosEntityTypeExtensionsTest.cs Adds unit coverage for the new automatic-indexing builder behavior and convention APIs.
test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs Updates/expands validator tests for composite, vector, full-text, include/exclude, and container consistency scenarios.
test/EFCore.Cosmos.FunctionalTests/TestUtilities/CosmosTestStore.cs Plumbs automatic-indexing enabled/exceptions into test container creation.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/CompiledModelCosmosTest.cs Adds compiled-model test for index types and ensures design-time-only annotations are stripped.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Cosmos_model_with_index_types/IndexedDataUnsafeAccessors.cs New compiled-model baseline output for the added indexing test model.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Cosmos_model_with_index_types/IndexedDataEntityType.cs New compiled-model baseline output representing entity/index metadata.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Cosmos_model_with_index_types/DbContextModelBuilder.cs New compiled-model baseline output for runtime model builder.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Cosmos_model_with_index_types/DbContextModel.cs New compiled-model baseline output for runtime model initialization.
test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/Cosmos_model_with_index_types/DbContextAssemblyAttributes.cs New compiled-model baseline assembly attribute for Cosmos runtime model.
test/EFCore.Cosmos.FunctionalTests/Query/Translations/VectorSearchTranslationsCosmosTest.cs Adds a roundtrip test for vector index configuration through a complex collection.
test/EFCore.Cosmos.FunctionalTests/Query/Translations/FullTextSearchTranslationsCosmosTest.cs Adds a roundtrip test for full-text index configuration through a complex collection.
test/EFCore.Cosmos.FunctionalTests/Query/Associations/ComplexProperties/ComplexPropertiesProjectionCosmosTest.cs Adds TODO markers for known “select entire document” behavior (tracking an existing issue).
test/EFCore.Cosmos.FunctionalTests/Query/AdHocComplexTypeQueryCosmosTest.cs Updates complex-type tests to reflect newly-supported index scenarios and adds discriminator-in-id coverage.
test/EFCore.Cosmos.FunctionalTests/ModelBuilding/CosmosModelBuilderGenericTest.cs Updates expectations for owned-type index traversal (now rejected with a more specific message).
test/EFCore.Cosmos.FunctionalTests/CosmosSessionTokensTest.cs Stabilizes session token assertions by separating create vs delete phases.
test/EFCore.Cosmos.FunctionalTests/CosmosApiConsistencyTest.cs Registers the new fluent API builder type for API consistency checks.
src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs Flows automatic indexing enabled/exceptions from model into container-creation parameters.
src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs Implements indexing-policy emission (included/excluded paths, composite indexes) and robust JSON path building from root (incl. complex/collection segments).
src/EFCore.Cosmos/Storage/Internal/ContainerProperties.cs Extends container-creation parameter record with automatic-indexing enabled/exceptions.
src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitorBase.cs Ensures property reads navigate into complex JSON objects when a scalar property is declared on a complex type.
src/EFCore.Cosmos/Properties/CosmosStrings.resx Adds/updates Cosmos provider error messages for automatic-indexing consistency and owned-type index traversal.
src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs Updates generated string accessors/summaries to match new/changed resources.
src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs Adds new annotation names for automatic-indexing enabled/exceptions.
src/EFCore.Cosmos/Metadata/Conventions/CosmosRuntimeModelConvention.cs Strips automatic-indexing annotations from runtime model (design-time-only).
src/EFCore.Cosmos/Metadata/Builders/CosmosAutomaticIndexingBuilder.cs Introduces fluent builder enabling Except(...) chaining for indexing-policy excluded paths.
src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs Adds container-level validation for automatic-indexing settings and rejects regular indexes declared on owned types.
src/EFCore.Cosmos/Extensions/CosmosIndexExtensions.cs Fixes convention annotation setter return type for full-text index flag.
src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs Adds extensions for getting/setting automatic-indexing enabled/exceptions (incl. convention APIs).
src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs Adds HasAutomaticIndexing(...) fluent API and convention builder helpers.
src/EFCore.Cosmos/Extensions/CosmosComplexCollectionTypePropertyBuilderExtensions.cs Enables full-text/vector configuration APIs for properties inside complex collections.
src/EFCore.Cosmos/EFCore.Cosmos.baseline.json Updates API baseline for new public surface (automatic-indexing builder + new extension methods).
src/EFCore.Cosmos/Design/Internal/CosmosCSharpRuntimeAnnotationCodeGenerator.cs Ensures automatic-indexing annotations aren’t emitted into the runtime model during design-time code generation.
Files not reviewed (1)
  • src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs: Language not supported

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review June 4, 2026 19:16
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner June 4, 2026 19:16
Copilot AI review requested due to automatic review settings June 4, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 6 comments.

Files not reviewed (1)
  • src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs: Language not supported

Copilot AI review requested due to automatic review settings June 4, 2026 19:33
@AndriySvyryd
AndriySvyryd requested a review from cincuranet June 4, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs: Language not supported

Copilot AI review requested due to automatic review settings June 9, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 35 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs: Language not supported

Add support for Vector and FullText indexes with properties in complex properties or collections
Add support for keys spanning non-collection complex properties

Fixes #38067
Fixes #17303
@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) June 9, 2026 22:46
@AndriySvyryd
AndriySvyryd merged commit 57cd370 into main Jun 9, 2026
13 checks passed
@AndriySvyryd
AndriySvyryd deleted the Issue38067 branch June 9, 2026 23:07
@github-actions github-actions Bot added the api-review This PR or issue is introducing public API changes that need to be reviewed label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

API review baseline changes for src/EFCore.Cosmos/EFCore.Cosmos.baseline.json

Show diff

The diff below was generated by ApiChief between the base and the PR.

  static class Microsoft.EntityFrameworkCore.CosmosComplexCollectionTypePropertyBuilderExtensions
+ static ComplexCollectionTypePropertyBuilder EnableFullTextSearch(this ComplexCollectionTypePropertyBuilder propertyBuilder, string? language = null,
+     bool enabled = true);
+ static ComplexCollectionTypePropertyBuilder<TProperty> EnableFullTextSearch<TProperty>(this ComplexCollectionTypePropertyBuilder<TProperty> propertyBuilder,
+     string? language = null, bool enabled = true);
+ static ComplexCollectionTypePropertyBuilder IsVectorProperty(this ComplexCollectionTypePropertyBuilder propertyBuilder, DistanceFunction distanceFunction,
+     int dimensions);
+ static ComplexCollectionTypePropertyBuilder<TProperty> IsVectorProperty<TProperty>(this ComplexCollectionTypePropertyBuilder<TProperty> propertyBuilder,
+     DistanceFunction distanceFunction, int dimensions);
  static class Microsoft.EntityFrameworkCore.CosmosEntityTypeBuilderExtensions
+ static bool CanSetAutomaticIndexing(this IConventionEntityTypeBuilder entityTypeBuilder, bool? enabled, bool fromDataAnnotation = false);
+ static bool CanSetAutomaticIndexingExceptions(this IConventionEntityTypeBuilder entityTypeBuilder, IReadOnlyList<string>? exceptions,
+     bool fromDataAnnotation = false);
+ static CosmosAutomaticIndexingBuilder HasAutomaticIndexing(this EntityTypeBuilder entityTypeBuilder, bool enabled = true);
+ static IConventionEntityTypeBuilder? HasAutomaticIndexing(this IConventionEntityTypeBuilder entityTypeBuilder, bool? enabled,
+     bool fromDataAnnotation = false);
+ static CosmosAutomaticIndexingBuilder<TEntity> HasAutomaticIndexing<TEntity>(this EntityTypeBuilder<TEntity> entityTypeBuilder, bool enabled = true);
  static class Microsoft.EntityFrameworkCore.CosmosEntityTypeExtensions
+ static bool? GetAutomaticIndexingEnabled(this IReadOnlyEntityType entityType);
+ static ConfigurationSource? GetAutomaticIndexingEnabledConfigurationSource(this IConventionEntityType entityType);
+ static IReadOnlyList<string>? GetAutomaticIndexingExceptions(this IReadOnlyEntityType entityType);
+ static ConfigurationSource? GetAutomaticIndexingExceptionsConfigurationSource(this IConventionEntityType entityType);
+ static bool? SetAutomaticIndexingEnabled(this IConventionEntityType entityType, bool? enabled, bool fromDataAnnotation = false);
+ static void SetAutomaticIndexingEnabled(this IMutableEntityType entityType, bool? enabled);
+ static IReadOnlyList<string>? SetAutomaticIndexingExceptions(this IConventionEntityType entityType, IReadOnlyList<string>? exceptions,
+     bool fromDataAnnotation = false);
+ static void SetAutomaticIndexingExceptions(this IMutableEntityType entityType, IReadOnlyList<string>? exceptions);
  static class Microsoft.EntityFrameworkCore.CosmosIndexBuilderExtensions
- static IndexBuilder IsVectorIndex(this IndexBuilder indexBuilder, VectorIndexType? indexType, bool vectorIndex = true);
+ static IndexBuilder IsVectorIndex(this IndexBuilder indexBuilder, VectorIndexType? indexType);
- static IndexBuilder<TEntity> IsVectorIndex<TEntity>(this IndexBuilder<TEntity> indexBuilder, VectorIndexType? indexType, bool vectorIndex = true);
+ static IndexBuilder<TEntity> IsVectorIndex<TEntity>(this IndexBuilder<TEntity> indexBuilder, VectorIndexType? indexType);
  static class Microsoft.EntityFrameworkCore.CosmosIndexExtensions
- static string? SetIsFullTextIndex(this IConventionIndex index, bool? fullTextIndex, bool fromDataAnnotation = false);
+ static bool? SetIsFullTextIndex(this IConventionIndex index, bool? fullTextIndex, bool fromDataAnnotation = false);
- static string? SetVectorIndexType(this IConventionIndex index, VectorIndexType? indexType, bool? vectorIndex, bool fromDataAnnotation = false);
- static void SetVectorIndexType(this IMutableIndex index, VectorIndexType? indexType, bool? vectorIndex);
+ static string? SetVectorIndexType(this IConventionIndex index, VectorIndexType? indexType, bool fromDataAnnotation = false);
+ static void SetVectorIndexType(this IMutableIndex index, VectorIndexType? indexType);
+ class Microsoft.EntityFrameworkCore.Metadata.Builders.CosmosAutomaticIndexingBuilder :
+     Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionEntityTypeBuilder>
+ virtual EntityTypeBuilder EntityTypeBuilder { get; }
+ CosmosAutomaticIndexingBuilder(EntityTypeBuilder entityTypeBuilder);
+ virtual CosmosAutomaticIndexingBuilder Except(string path);
+ class Microsoft.EntityFrameworkCore.Metadata.Builders.CosmosAutomaticIndexingBuilder<TEntity> :
+     Microsoft.EntityFrameworkCore.Metadata.Builders.CosmosAutomaticIndexingBuilder where TEntity : class
+ CosmosAutomaticIndexingBuilder(EntityTypeBuilder<TEntity> entityTypeBuilder);
+ virtual CosmosAutomaticIndexingBuilder<TEntity> Except(string path);

@AndriySvyryd AndriySvyryd removed the api-review This PR or issue is introducing public API changes that need to be reviewed label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cosmos: Allow vector and fulltext indexes on complex type scalar properties Cosmos: Support composite, tuple and range indexes

4 participants