Skip to content

Commit

Permalink
Code changes to upgrade direct version to 3.34.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kundadebdatta committed May 15, 2024
1 parent d64b12c commit 7184f14
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 64 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
28 changes: 9 additions & 19 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,30 +138,14 @@ public IndexingPolicy()
/// ]
/// ]]>
/// </example>
[JsonIgnore]
[JsonProperty(PropertyName = "vectorIndexes", NullValueHandling = NullValueHandling.Ignore)]
#if PREVIEW

public
#else
internal
#endif
// Remove this place holder for VectorIndexes once the new Cosmos.Direct version 3.34.2 is released and rename the VectorIndexesInternal to VectorIndexes.
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; }
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 @@ -618,21 +618,25 @@
"Microsoft.Azure.Cosmos.IndexingPolicy;System.Object;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
"System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] get_VectorIndexes()": {
"System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] get_VectorIndexes()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [],
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] get_VectorIndexes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] VectorIndexes[Newtonsoft.Json.JsonIgnoreAttribute()]": {
"System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] VectorIndexes[Newtonsoft.Json.JsonPropertyAttribute(NullValueHandling = 1, PropertyName = \"vectorIndexes\")]": {
"Type": "Property",
"Attributes": [
"JsonIgnoreAttribute"
"JsonPropertyAttribute"
],
"MethodInfo": "System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] VectorIndexes;CanRead:True;CanWrite:True;System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath] get_VectorIndexes();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_VectorIndexes(System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_VectorIndexes(System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath])": {
"Void set_VectorIndexes(System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [],
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_VectorIndexes(System.Collections.ObjectModel.Collection`1[Microsoft.Azure.Cosmos.VectorIndexPath]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,31 @@ public void SettingPKShouldNotResetVersion()
[TestMethod]
public void ValidateVectorEmbeddingsAndIndexes()
{
Embedding embedding1 = new ()
Cosmos.Embedding embedding1 = new ()
{
Path = "/vector1",
DataType = VectorDataType.Int8,
DistanceFunction = DistanceFunction.DotProduct,
DataType = Cosmos.VectorDataType.Int8,
DistanceFunction = Cosmos.DistanceFunction.DotProduct,
Dimensions = 1200,
};

Embedding embedding2 = new ()
Cosmos.Embedding embedding2 = new ()
{
Path = "/vector2",
DataType = VectorDataType.Uint8,
DistanceFunction = DistanceFunction.Cosine,
DataType = Cosmos.VectorDataType.Uint8,
DistanceFunction = Cosmos.DistanceFunction.Cosine,
Dimensions = 3,
};

Embedding embedding3 = new ()
Cosmos.Embedding embedding3 = new ()
{
Path = "/vector3",
DataType = VectorDataType.Float32,
DistanceFunction = DistanceFunction.Euclidean,
DataType = Cosmos.VectorDataType.Float32,
DistanceFunction = Cosmos.DistanceFunction.Euclidean,
Dimensions = 400,
};

Collection<Embedding> embeddings = new Collection<Embedding>()
Collection<Cosmos.Embedding> embeddings = new Collection<Cosmos.Embedding>()
{
embedding1,
embedding2,
Expand All @@ -216,25 +216,25 @@ public void ValidateVectorEmbeddingsAndIndexes()

ContainerProperties containerSettings = new ContainerProperties(id: "TestContainer", partitionKeyPath: "/partitionKey")
{
VectorEmbeddingPolicy = new(embeddings),
VectorEmbeddingPolicy = new (embeddings),
IndexingPolicy = new Cosmos.IndexingPolicy()
{
VectorIndexes = new()
{
new VectorIndexPath()
new Cosmos.VectorIndexPath()
{
Path = "/vector1",
Type = VectorIndexType.Flat,
Type = Cosmos.VectorIndexType.Flat,
},
new VectorIndexPath()
new Cosmos.VectorIndexPath()
{
Path = "/vector2",
Type = VectorIndexType.Flat,
Type = Cosmos.VectorIndexType.Flat,
},
new VectorIndexPath()
new Cosmos.VectorIndexPath()
{
Path = "/vector3",
Type = VectorIndexType.Flat,
Type = Cosmos.VectorIndexType.Flat,
}
},

Expand All @@ -245,18 +245,18 @@ public void ValidateVectorEmbeddingsAndIndexes()
Assert.IsNotNull(containerSettings.VectorEmbeddingPolicy);
Assert.IsNotNull(containerSettings.IndexingPolicy.VectorIndexes);

VectorEmbeddingPolicy embeddingPolicy = containerSettings.VectorEmbeddingPolicy;
Cosmos.VectorEmbeddingPolicy embeddingPolicy = containerSettings.VectorEmbeddingPolicy;
Assert.IsNotNull(embeddingPolicy.Embeddings);
Assert.AreEqual(embeddings.Count, embeddingPolicy.Embeddings.Count());
CollectionAssert.AreEquivalent(embeddings, embeddingPolicy.Embeddings.ToList());

Collection<VectorIndexPath> vectorIndexes = containerSettings.IndexingPolicy.VectorIndexes;
Collection<Cosmos.VectorIndexPath> vectorIndexes = containerSettings.IndexingPolicy.VectorIndexes;
Assert.AreEqual("/vector1", vectorIndexes[0].Path);
Assert.AreEqual(VectorIndexType.Flat, vectorIndexes[0].Type);
Assert.AreEqual(Cosmos.VectorIndexType.Flat, vectorIndexes[0].Type);
Assert.AreEqual("/vector2", vectorIndexes[1].Path);
Assert.AreEqual(VectorIndexType.Flat, vectorIndexes[1].Type);
Assert.AreEqual(Cosmos.VectorIndexType.Flat, vectorIndexes[1].Type);
Assert.AreEqual("/vector3", vectorIndexes[2].Path);
Assert.AreEqual(VectorIndexType.Flat, vectorIndexes[2].Type);
Assert.AreEqual(Cosmos.VectorIndexType.Flat, vectorIndexes[2].Type);
}

private static string SerializeDocumentCollection(DocumentCollection collection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ public void ContainerPropertiesDeserializeWithAdditionalDataTest()
Assert.IsNotNull(containerProperties.VectorEmbeddingPolicy);
Assert.AreEqual(3, containerProperties.VectorEmbeddingPolicy.Embeddings.Count);
Assert.AreEqual("/vector1", containerProperties.VectorEmbeddingPolicy.Embeddings[0].Path);
Assert.AreEqual(VectorDataType.Float32, containerProperties.VectorEmbeddingPolicy.Embeddings[0].DataType);
Assert.AreEqual(Cosmos.VectorDataType.Float32, containerProperties.VectorEmbeddingPolicy.Embeddings[0].DataType);
Assert.AreEqual((ulong)1200, containerProperties.VectorEmbeddingPolicy.Embeddings[0].Dimensions);
Assert.AreEqual(DistanceFunction.Cosine, containerProperties.VectorEmbeddingPolicy.Embeddings[0].DistanceFunction);
Assert.AreEqual(Cosmos.DistanceFunction.Cosine, containerProperties.VectorEmbeddingPolicy.Embeddings[0].DistanceFunction);

Assert.AreEqual(2, containerProperties.ComputedProperties.Count);
Assert.AreEqual("lowerName", containerProperties.ComputedProperties[0].Name);
Expand Down Expand Up @@ -805,11 +805,7 @@ public void ContainerSettingsDefaults()
[TestMethod]
public async Task ContainerSettingsIndexTest()
{
#if PREVIEW
string containerJsonString = "{\"indexingPolicy\":{\"automatic\":true,\"indexingMode\":\"Consistent\",\"includedPaths\":[{\"path\":\"/*\",\"indexes\":[{\"dataType\":\"Number\",\"precision\":-1,\"kind\":\"Range\"},{\"dataType\":\"String\",\"precision\":-1,\"kind\":\"Range\"}]}],\"excludedPaths\":[{\"path\":\"/\\\"_etag\\\"/?\"}],\"compositeIndexes\":[],\"spatialIndexes\":[],\"vectorIndexes\":[]},\"id\":\"MigrationTest\",\"partitionKey\":{\"paths\":[\"/id\"],\"kind\":\"Hash\"}}";
#else
string containerJsonString = "{\"indexingPolicy\":{\"automatic\":true,\"indexingMode\":\"Consistent\",\"includedPaths\":[{\"path\":\"/*\",\"indexes\":[{\"dataType\":\"Number\",\"precision\":-1,\"kind\":\"Range\"},{\"dataType\":\"String\",\"precision\":-1,\"kind\":\"Range\"}]}],\"excludedPaths\":[{\"path\":\"/\\\"_etag\\\"/?\"}],\"compositeIndexes\":[],\"spatialIndexes\":[]},\"id\":\"MigrationTest\",\"partitionKey\":{\"paths\":[\"/id\"],\"kind\":\"Hash\"}}";
#endif

CosmosJsonDotNetSerializer serializerCore = new CosmosJsonDotNetSerializer();
ContainerProperties containerProperties = null;
Expand Down Expand Up @@ -1082,29 +1078,29 @@ public void VectorEmbeddingPolicySerialization()
string serialization = JsonConvert.SerializeObject(containerSettings);
Assert.IsFalse(serialization.Contains("vectorEmbeddingPolicy"), "Vector Embedding Policy should not be included by default");

Embedding embedding1 = new()
Cosmos.Embedding embedding1 = new()
{
Path = "/vector1",
DataType = VectorDataType.Int8,
DistanceFunction = DistanceFunction.DotProduct,
DataType = Cosmos.VectorDataType.Int8,
DistanceFunction = Cosmos.DistanceFunction.DotProduct,
Dimensions = 1200,
};

Embedding embedding2 = new()
Cosmos.Embedding embedding2 = new()
{
Path = "/vector2",
DataType = VectorDataType.Uint8,
DistanceFunction = DistanceFunction.Cosine,
DataType = Cosmos.VectorDataType.Uint8,
DistanceFunction = Cosmos.DistanceFunction.Cosine,
Dimensions = 3,
};

Collection<Embedding> embeddings = new ()
Collection<Cosmos.Embedding> embeddings = new ()
{
embedding1,
embedding2,
};

containerSettings.VectorEmbeddingPolicy = new VectorEmbeddingPolicy(embeddings);
containerSettings.VectorEmbeddingPolicy = new Cosmos.VectorEmbeddingPolicy(embeddings);

string serializationWithValues = JsonConvert.SerializeObject(containerSettings);
Assert.IsTrue(serializationWithValues.Contains("vectorEmbeddingPolicy"), "Vector Embedding Policy should be included.");
Expand All @@ -1113,8 +1109,8 @@ public void VectorEmbeddingPolicySerialization()
JObject parsed = JObject.Parse(serializationWithValues);
JToken vectorEmbeddings = parsed["vectorEmbeddingPolicy"]["vectorEmbeddings"];
Assert.AreEqual(JTokenType.Array, vectorEmbeddings.Type, "Vector Embedding Policy serialized vectorEmbeddings should be an array.");
Assert.IsTrue(embedding1.Equals(vectorEmbeddings.Value<JArray>()[0].ToObject<Embedding>()));
Assert.IsTrue(embedding2.Equals(vectorEmbeddings.Value<JArray>()[1].ToObject<Embedding>()));
Assert.IsTrue(embedding1.Equals(vectorEmbeddings.Value<JArray>()[0].ToObject<Cosmos.Embedding>()));
Assert.IsTrue(embedding2.Equals(vectorEmbeddings.Value<JArray>()[1].ToObject<Cosmos.Embedding>()));
}

private static T CosmosDeserialize<T>(string payload)
Expand Down

0 comments on commit 7184f14

Please sign in to comment.