Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.56.0</ClientOfficialVersion>
<ClientPreviewVersion>3.57.0</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview.0</ClientPreviewSuffixVersion>
<DirectVersion>3.41.2</DirectVersion>
<DirectVersion>3.41.3</DirectVersion>
Comment thread
aavasthy marked this conversation as resolved.
<FaultInjectionVersion>1.0.0</FaultInjectionVersion>
<FaultInjectionSuffixVersion>beta.0</FaultInjectionSuffixVersion>
<EncryptionOfficialVersion>2.0.5</EncryptionOfficialVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ public VectorIndexDefinition<T> Path(
return this;
}

/// <summary>
/// Configures the quantizer type for the current <see cref="VectorIndexPath"/> definition.
/// </summary>
/// <param name="quantizerType">
/// The quantizer type to be used for vector quantization. This is an optional parameter and applies to index
/// types DiskANN and quantizedFlat. Allowed values are Product and Spherical.
/// </param>
/// <returns>An instance of the current <see cref="VectorIndexDefinition{T}"/>.</returns>
#if PREVIEW
public
#else
internal
#endif
VectorIndexDefinition<T> WithQuantizerType(
QuantizerType quantizerType)
{
this.vectorIndexPath.QuantizerType = quantizerType;
return this;
}

/// <summary>
/// Configures the quantization byte size for the current <see cref="VectorIndexPath"/> definition.
/// </summary>
Expand Down
108 changes: 108 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,114 @@ public int GetHashCode(IndexingPolicy indexingPolicy)
return hashCode;
}
}

internal sealed class VectorIndexPathEqualityComparer : IEqualityComparer<VectorIndexPath>
{
public static readonly VectorIndexPathEqualityComparer Singleton = new VectorIndexPathEqualityComparer();

public bool Equals(VectorIndexPath vectorIndexPath1, VectorIndexPath vectorIndexPath2)
{
if (Object.ReferenceEquals(vectorIndexPath1, vectorIndexPath2))
{
return true;
}

if (vectorIndexPath1 == null || vectorIndexPath2 == null)
{
return false;
}

if (vectorIndexPath1.Path != vectorIndexPath2.Path ||
vectorIndexPath1.Type != vectorIndexPath2.Type ||
vectorIndexPath1.QuantizerType != vectorIndexPath2.QuantizerType ||
vectorIndexPath1.QuantizationByteSize != vectorIndexPath2.QuantizationByteSize ||
vectorIndexPath1.IndexingSearchListSize != vectorIndexPath2.IndexingSearchListSize ||
!vectorIndexPath1.AdditionalProperties.EqualsTo(vectorIndexPath2.AdditionalProperties))
{
return false;
}

// Compare VectorIndexShardKey arrays
if (vectorIndexPath1.VectorIndexShardKey == null && vectorIndexPath2.VectorIndexShardKey == null)
{
return true;
}

if (vectorIndexPath1.VectorIndexShardKey == null || vectorIndexPath2.VectorIndexShardKey == null)
{
return false;
}

if (vectorIndexPath1.VectorIndexShardKey.Length != vectorIndexPath2.VectorIndexShardKey.Length)
{
return false;
}

HashSet<string> shardKeys1 = new HashSet<string>(vectorIndexPath1.VectorIndexShardKey);
HashSet<string> shardKeys2 = new HashSet<string>(vectorIndexPath2.VectorIndexShardKey);

return shardKeys1.SetEquals(shardKeys2);
}

public int GetHashCode(VectorIndexPath vectorIndexPath)
{
if (vectorIndexPath == null)
{
return 0;
}

int hashCode = 0;
hashCode ^= vectorIndexPath.Path?.GetHashCode() ?? 0;
hashCode ^= vectorIndexPath.Type.GetHashCode();
hashCode ^= vectorIndexPath.QuantizerType?.GetHashCode() ?? 0;
hashCode ^= vectorIndexPath.QuantizationByteSize.GetHashCode();
hashCode ^= vectorIndexPath.IndexingSearchListSize.GetHashCode();

if (vectorIndexPath.VectorIndexShardKey != null)
{
foreach (string shardKey in vectorIndexPath.VectorIndexShardKey)
{
hashCode ^= shardKey?.GetHashCode() ?? 0;
}
}

return hashCode;
}
}

internal sealed class VectorIndexesEqualityComparer : IEqualityComparer<Collection<VectorIndexPath>>
{
private static readonly VectorIndexPathEqualityComparer vectorIndexPathEqualityComparer = new VectorIndexPathEqualityComparer();

public bool Equals(Collection<VectorIndexPath> vectorIndexes1, Collection<VectorIndexPath> vectorIndexes2)
{
if (Object.ReferenceEquals(vectorIndexes1, vectorIndexes2))
{
return true;
}

if (vectorIndexes1 == null || vectorIndexes2 == null)
{
return false;
}

HashSet<VectorIndexPath> hashedVectorIndexes1 = new HashSet<VectorIndexPath>(vectorIndexes1, vectorIndexPathEqualityComparer);
HashSet<VectorIndexPath> hashedVectorIndexes2 = new HashSet<VectorIndexPath>(vectorIndexes2, vectorIndexPathEqualityComparer);

return hashedVectorIndexes1.SetEquals(hashedVectorIndexes2);
}

public int GetHashCode(Collection<VectorIndexPath> vectorIndexes)
{
int hashCode = 0;
foreach (VectorIndexPath vectorIndexPath in vectorIndexes)
{
hashCode ^= vectorIndexPathEqualityComparer.GetHashCode(vectorIndexPath);
}

return hashCode;
}
}
#endregion
}
}
33 changes: 33 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/QuantizerType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

/// <summary>
/// Defines the quantizer type of a vector index path specification in the Azure Cosmos DB service.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
#if PREVIEW
public
#else
internal
#endif
enum QuantizerType
{
/// <summary>
/// Represents a product quantizer type.
/// </summary>
[EnumMember(Value = "product")]
Comment thread
aavasthy marked this conversation as resolved.
Product,

/// <summary>
/// Represents a spherical quantizer type.
/// </summary>
[EnumMember(Value = "spherical")]
Spherical
}
}
15 changes: 15 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/VectorIndexPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Microsoft.Azure.Cosmos
/// {
/// "path": "/embeddings/vector",
/// "type": "DiskANN",
/// "quantizerType": "product", // or "spherical"
/// "quantizationByteSize": 2,
/// "indexingSearchListSize": 100,
/// "vectorIndexShardKey": ["/Country"]
Expand Down Expand Up @@ -68,6 +69,20 @@ public sealed class VectorIndexPath
[JsonConverter(typeof(StringEnumConverter))]
public VectorIndexType Type { get; set; }

/// <summary>
/// Gets or sets the quantizer type for the vector index path. This is only applicable for the quantizedFlat and diskann vector index types.
/// Allowed values are "product" and "spherical".
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.QuantizerType, NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(StringEnumConverter))]
#if PREVIEW
public
#else
internal
#endif
QuantizerType? QuantizerType
{ get; set; }

/// <summary>
/// Gets or sets the quantization byte size for the vector index path. This is only applicable for the quantizedFlat and diskann vector index types.
/// The allowed range for this parameter is between 1 and min(dimensions, 512).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,11 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Fluent.VectorIndexDefinition`1[T] WithQuantizationByteSize(Int32);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.Fluent.VectorIndexDefinition`1[T] WithQuantizerType(Microsoft.Azure.Cosmos.QuantizerType)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Fluent.VectorIndexDefinition`1[T] WithQuantizerType(Microsoft.Azure.Cosmos.QuantizerType);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.Fluent.VectorIndexDefinition`1[T] WithVectorIndexShardKey(System.String[])": {
"Type": "Method",
"Attributes": [],
Expand Down Expand Up @@ -1332,6 +1337,31 @@
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.QuantizerType;System.Enum;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:True;IsClass:False;IsValueType:True;IsNested:False;IsGenericType:False;IsSerializable:True": {
"Subclasses": {},
"Members": {
"Int32 value__": {
"Type": "Field",
"Attributes": [],
"MethodInfo": "Int32 value__;IsInitOnly:False;IsStatic:False;"
},
"Microsoft.Azure.Cosmos.QuantizerType Product[System.Runtime.Serialization.EnumMemberAttribute(Value = \"product\")]": {
"Type": "Field",
"Attributes": [
"EnumMemberAttribute"
],
"MethodInfo": "Microsoft.Azure.Cosmos.QuantizerType Product;IsInitOnly:False;IsStatic:True;"
},
"Microsoft.Azure.Cosmos.QuantizerType Spherical[System.Runtime.Serialization.EnumMemberAttribute(Value = \"spherical\")]": {
"Type": "Field",
"Attributes": [
"EnumMemberAttribute"
],
"MethodInfo": "Microsoft.Azure.Cosmos.QuantizerType Spherical;IsInitOnly:False;IsStatic:True;"
}
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.RequestOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
Expand Down Expand Up @@ -1511,10 +1541,32 @@
],
"MethodInfo": "Int32 QuantizationByteSize;CanRead:True;CanWrite:True;Int32 get_QuantizationByteSize();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_QuantizationByteSize(Int32);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType] get_QuantizerType()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType] get_QuantizerType();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType] QuantizerType[Newtonsoft.Json.JsonPropertyAttribute(NullValueHandling = NullValueHandling.Ignore = 1, PropertyName = \"quantizerType\")]-[Newtonsoft.Json.JsonConverterAttribute(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]": {
"Type": "Property",
"Attributes": [
"JsonConverterAttribute",
"JsonPropertyAttribute"
],
"MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType] QuantizerType;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType] get_QuantizerType();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_QuantizerType(System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_QuantizationByteSize(Int32)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Void set_QuantizationByteSize(Int32);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_QuantizerType(System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_QuantizerType(System.Nullable`1[Microsoft.Azure.Cosmos.QuantizerType]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
}
},
"NestedTypes": {}
Expand Down
Loading