Skip to content

Commit

Permalink
ContainerProperties: Refactors Vector Embedding and Indexing Policy I…
Browse files Browse the repository at this point in the history
…nterfaces to Mark Them as Public for Preview (#4486)

* Code changes to mark internal vector interfaces as public.

* Code changes to update the public and preview modifiers.

* Code changes to update preview and ga contracts.

* Code changes to mark the policy definitions as public interface.

* Code changes to update GA contract and use #if all over.

* Code changes to fix some of the broken tests in preview.

* Code changes to update the preview contract too reflect the JSON Ignore.

* Code changes to upgrade direct version to 3.34.2
  • Loading branch information
kundadebdatta authored May 15, 2024
1 parent 3ae56db commit a3c9d77
Show file tree
Hide file tree
Showing 16 changed files with 510 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ClientOfficialVersion>3.39.1</ClientOfficialVersion>
<ClientPreviewVersion>3.40.0</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview.1</ClientPreviewSuffixVersion>
<DirectVersion>3.34.0</DirectVersion>
<DirectVersion>3.34.2</DirectVersion>
<EncryptionOfficialVersion>2.0.4</EncryptionOfficialVersion>
<EncryptionPreviewVersion>2.1.0</EncryptionPreviewVersion>
<EncryptionPreviewSuffixVersion>preview4</EncryptionPreviewSuffixVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public ClientEncryptionPolicyDefinition WithClientEncryptionPolicy(int policyFor
/// </summary>
/// <param name="embeddings">List of vector embeddings to include in the policy definition.</param>
/// <returns>An instance of <see cref="VectorEmbeddingPolicyDefinition"/>.</returns>
internal VectorEmbeddingPolicyDefinition WithVectorEmbeddingPolicy(
#if PREVIEW
public
#else
internal
#endif
VectorEmbeddingPolicyDefinition WithVectorEmbeddingPolicy(
Collection<Embedding> embeddings)
{
return new VectorEmbeddingPolicyDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ public SpatialIndexDefinition<IndexingPolicyDefinition<T>> WithSpatialIndex()
/// Defines a <see cref="VectorIndexPath"/> in the current <see cref="Container"/>'s definition.
/// </summary>
/// <returns>An instance of <see cref="VectorIndexDefinition{T}"/>.</returns>
internal VectorIndexDefinition<IndexingPolicyDefinition<T>> WithVectorIndex()
#if PREVIEW
public
#else
internal
#endif
VectorIndexDefinition<IndexingPolicyDefinition<T>> WithVectorIndex()
{
return new VectorIndexDefinition<IndexingPolicyDefinition<T>>(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ namespace Microsoft.Azure.Cosmos.Fluent
/// <summary>
/// <see cref="VectorEmbeddingPolicy"/> fluent definition.
/// </summary>
internal class VectorEmbeddingPolicyDefinition
#if PREVIEW
public
#else
internal
#endif
class VectorEmbeddingPolicyDefinition
{
private readonly ContainerBuilder parent;
private readonly Action<VectorEmbeddingPolicy> attachCallback;
private readonly Collection<Embedding> vectorEmbeddings;

internal VectorEmbeddingPolicyDefinition(
/// <summary>
/// Initializes a new instance of the <see cref="VectorEmbeddingPolicyDefinition"/> class.
/// </summary>
/// <param name="parent">The original instance of <see cref="ContainerBuilder"/>.</param>
/// <param name="embeddings">List of embeddings to include in the policy definition.</param>
/// <param name="attachCallback">A callback delegate to be used at a later point of time.</param>
public VectorEmbeddingPolicyDefinition(
ContainerBuilder parent,
Collection<Embedding> embeddings,
Action<VectorEmbeddingPolicy> attachCallback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ namespace Microsoft.Azure.Cosmos.Fluent
/// Vector index fluent definition.
/// </summary>
/// <seealso cref="VectorIndexPath"/>
internal class VectorIndexDefinition<T>
#if PREVIEW
public
#else
internal
#endif
class VectorIndexDefinition<T>
{
private readonly VectorIndexPath vectorIndexPath = new VectorIndexPath();
private readonly VectorIndexPath vectorIndexPath = new ();
private readonly T parent;
private readonly Action<VectorIndexPath> attachCallback;

internal VectorIndexDefinition(
/// <summary>
/// Initializes a new instance of the <see cref="VectorIndexDefinition{T}"/> class.
/// </summary>
/// <param name="parent">The original instance of <see cref="ContainerBuilder"/>.</param>
/// <param name="attachCallback">A callback delegate to be used at a later point of time.</param>
public VectorIndexDefinition(
T parent,
Action<VectorIndexPath> attachCallback)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ public IndexingPolicy IndexingPolicy
/// </para>
/// </remarks>
[JsonIgnore]
internal VectorEmbeddingPolicy VectorEmbeddingPolicy
#if PREVIEW
public
#else
internal
#endif
VectorEmbeddingPolicy VectorEmbeddingPolicy
{
get => this.vectorEmbeddingPolicyInternal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ namespace Microsoft.Azure.Cosmos
/// Defines the distance function for a vector index specification in the Azure Cosmos DB service.
/// </summary>
/// <seealso cref="Embedding"/> for usage.
internal enum DistanceFunction
#if PREVIEW
public
#else
internal
#endif
enum DistanceFunction
{
/// <summary>
/// Represents the euclidean distance function.
Expand Down
7 changes: 6 additions & 1 deletion Microsoft.Azure.Cosmos/src/Resource/Settings/Embedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Represents the embedding settings for the vector index.
/// </summary>
internal class Embedding : IEquatable<Embedding>
#if PREVIEW
public
#else
internal
#endif
class Embedding : IEquatable<Embedding>
{
/// <summary>
/// Gets or sets a string containing the path of the vector index.
Expand Down
29 changes: 13 additions & 16 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public IndexingPolicy()
[JsonProperty(PropertyName = Constants.Properties.CompositeIndexes)]
public Collection<Collection<CompositePath>> CompositeIndexes { get; internal set; } = new Collection<Collection<CompositePath>>();

/// <summary>
/// Collection of spatial index definitions to be used
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.SpatialIndexes)]
public Collection<SpatialPath> SpatialIndexes { get; internal set; } = new Collection<SpatialPath>();

/// <summary>
/// Gets the vector indexes for additional indexes
/// </summary>
Expand All @@ -132,23 +138,14 @@ public IndexingPolicy()
/// ]
/// ]]>
/// </example>
internal Collection<VectorIndexPath> VectorIndexes
{
get => this.VectorIndexesInternal ??= new Collection<VectorIndexPath>();
set => this.VectorIndexesInternal = value;
}

/// <summary>
/// Collection of spatial index definitions to be used
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.SpatialIndexes)]
public Collection<SpatialPath> SpatialIndexes { get; internal set; } = new Collection<SpatialPath>();

/// <summary>
/// Gets or Sets an internal placeholder collection to hold the vector indexes.
/// </summary>
[JsonProperty(PropertyName = "vectorIndexes", NullValueHandling = NullValueHandling.Ignore)]
internal Collection<VectorIndexPath> VectorIndexesInternal { get; set; }
#if PREVIEW

public
#else
internal
#endif
Collection<VectorIndexPath> VectorIndexes { get; set; } = new Collection<VectorIndexPath>();

/// <summary>
/// This contains additional values for scenarios where the SDK is not aware of new fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Defines the target data type of a vector index specification in the Azure Cosmos DB service.
/// </summary>
internal enum VectorDataType
#if PREVIEW
public
#else
internal
#endif
enum VectorDataType
{
/// <summary>
/// Represent a float16 data type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ namespace Microsoft.Azure.Cosmos
/// Represents the vector embedding policy configuration for specifying the vector embeddings on documents in the collection in the Azure Cosmos DB service.
/// </summary>
/// <seealso cref="ContainerProperties"/>
internal sealed class VectorEmbeddingPolicy
#if PREVIEW
public
#else
internal
#endif
sealed class VectorEmbeddingPolicy
{
/// <summary>
/// Initializes a new instance of the <see cref="VectorEmbeddingPolicy"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ namespace Microsoft.Azure.Cosmos
/// }
/// ]]>
/// </example>
internal sealed class VectorIndexPath
#if PREVIEW
public
#else
internal
#endif
sealed class VectorIndexPath
{
/// <summary>
/// Gets or sets the full path in a document used for vector indexing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ namespace Microsoft.Azure.Cosmos
/// <summary>
/// Defines the target index type of an vector index path specification in the Azure Cosmos DB service.
/// </summary>
internal enum VectorIndexType
#if PREVIEW
public
#else
internal
#endif
enum VectorIndexType
{
/// <summary>
/// Represents a flat vector index type.
Expand Down
Loading

0 comments on commit a3c9d77

Please sign in to comment.