From 2ce9bfc5fb0d997dc8872eee6b1e171d6d8e491b Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Mon, 17 Mar 2025 09:42:27 +0100 Subject: [PATCH] Regenerate client using the latest specification --- .../_Generated/Types/Enums/Enums.Mapping.g.cs | 292 ++++++++++++++++++ .../Mapping/DenseVectorIndexOptions.g.cs | 89 +++++- .../Types/Mapping/DenseVectorProperty.g.cs | 175 +++++++++-- 3 files changed, 534 insertions(+), 22 deletions(-) diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Enums/Enums.Mapping.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Enums/Enums.Mapping.g.cs index 3cde2b5248d..97f25205c22 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Enums/Enums.Mapping.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Enums/Enums.Mapping.g.cs @@ -28,6 +28,298 @@ namespace Elastic.Clients.Elasticsearch.Mapping; +[JsonConverter(typeof(DenseVectorElementTypeConverter))] +public enum DenseVectorElementType +{ + /// + /// + /// Indexes a 4-byte floating-point value per dimension. + /// + /// + [EnumMember(Value = "float")] + Float, + /// + /// + /// Indexes a 1-byte integer value per dimension. + /// + /// + [EnumMember(Value = "byte")] + Byte, + /// + /// + /// Indexes a single bit per dimension. Useful for very high-dimensional vectors or models that specifically support + /// bit vectors. + /// + /// + /// NOTE: when using bit, the number of dimensions must be a multiple of 8 and must represent the number of bits. + /// + /// + [EnumMember(Value = "bit")] + Bit +} + +internal sealed class DenseVectorElementTypeConverter : JsonConverter +{ + public override DenseVectorElementType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var enumString = reader.GetString(); + switch (enumString) + { + case "float": + return DenseVectorElementType.Float; + case "byte": + return DenseVectorElementType.Byte; + case "bit": + return DenseVectorElementType.Bit; + } + + ThrowHelper.ThrowJsonException(); + return default; + } + + public override void Write(Utf8JsonWriter writer, DenseVectorElementType value, JsonSerializerOptions options) + { + switch (value) + { + case DenseVectorElementType.Float: + writer.WriteStringValue("float"); + return; + case DenseVectorElementType.Byte: + writer.WriteStringValue("byte"); + return; + case DenseVectorElementType.Bit: + writer.WriteStringValue("bit"); + return; + } + + writer.WriteNullValue(); + } +} + +[JsonConverter(typeof(DenseVectorIndexOptionsTypeConverter))] +public enum DenseVectorIndexOptionsType +{ + /// + /// + /// The default index type for float vectors. This utilizes the HNSW algorithm in addition to automatically scalar + /// quantization for scalable approximate kNN search with element_type of float. + /// + /// + /// This can reduce the memory footprint by 4x at the cost of some accuracy. + /// + /// + [EnumMember(Value = "int8_hnsw")] + Int8Hnsw, + /// + /// + /// This utilizes a brute-force search algorithm in addition to automatically scalar quantization. Only supports + /// element_type of float. + /// + /// + [EnumMember(Value = "int8_flat")] + Int8Flat, + /// + /// + /// This utilizes the HNSW algorithm in addition to automatically scalar quantization for scalable approximate kNN + /// search with element_type of float. + /// + /// + /// This can reduce the memory footprint by 8x at the cost of some accuracy. + /// + /// + [EnumMember(Value = "int4_hnsw")] + Int4Hnsw, + /// + /// + /// This utilizes a brute-force search algorithm in addition to automatically half-byte scalar quantization. + /// Only supports element_type of float. + /// + /// + [EnumMember(Value = "int4_flat")] + Int4Flat, + /// + /// + /// This utilizes the HNSW algorithm for scalable approximate kNN search. This supports all element_type values. + /// + /// + [EnumMember(Value = "hnsw")] + Hnsw, + /// + /// + /// This utilizes a brute-force search algorithm for exact kNN search. This supports all element_type values. + /// + /// + [EnumMember(Value = "flat")] + Flat +} + +internal sealed class DenseVectorIndexOptionsTypeConverter : JsonConverter +{ + public override DenseVectorIndexOptionsType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var enumString = reader.GetString(); + switch (enumString) + { + case "int8_hnsw": + return DenseVectorIndexOptionsType.Int8Hnsw; + case "int8_flat": + return DenseVectorIndexOptionsType.Int8Flat; + case "int4_hnsw": + return DenseVectorIndexOptionsType.Int4Hnsw; + case "int4_flat": + return DenseVectorIndexOptionsType.Int4Flat; + case "hnsw": + return DenseVectorIndexOptionsType.Hnsw; + case "flat": + return DenseVectorIndexOptionsType.Flat; + } + + ThrowHelper.ThrowJsonException(); + return default; + } + + public override void Write(Utf8JsonWriter writer, DenseVectorIndexOptionsType value, JsonSerializerOptions options) + { + switch (value) + { + case DenseVectorIndexOptionsType.Int8Hnsw: + writer.WriteStringValue("int8_hnsw"); + return; + case DenseVectorIndexOptionsType.Int8Flat: + writer.WriteStringValue("int8_flat"); + return; + case DenseVectorIndexOptionsType.Int4Hnsw: + writer.WriteStringValue("int4_hnsw"); + return; + case DenseVectorIndexOptionsType.Int4Flat: + writer.WriteStringValue("int4_flat"); + return; + case DenseVectorIndexOptionsType.Hnsw: + writer.WriteStringValue("hnsw"); + return; + case DenseVectorIndexOptionsType.Flat: + writer.WriteStringValue("flat"); + return; + } + + writer.WriteNullValue(); + } +} + +[JsonConverter(typeof(DenseVectorSimilarityConverter))] +public enum DenseVectorSimilarity +{ + /// + /// + /// Computes the maximum inner product of two vectors. This is similar to dot_product, but doesn't require vectors + /// to be normalized. This means that each vector’s magnitude can significantly effect the score. + /// + /// + /// The document _score is adjusted to prevent negative values. For max_inner_product values < 0, the _score + /// is 1 / (1 + -1 * max_inner_product(query, vector)). For non-negative max_inner_product results the _score + /// is calculated max_inner_product(query, vector) + 1. + /// + /// + [EnumMember(Value = "max_inner_product")] + MaxInnerProduct, + /// + /// + /// Computes similarity based on the L2 distance (also known as Euclidean distance) between the vectors. + /// + /// + /// The document _score is computed as 1 / (1 + l2_norm(query, vector)^2). + /// + /// + /// For bit vectors, instead of using l2_norm, the hamming distance between the vectors is used. + /// + /// + /// The _score transformation is (numBits - hamming(a, b)) / numBits. + /// + /// + [EnumMember(Value = "l2_norm")] + L2Norm, + /// + /// + /// Computes the dot product of two unit vectors. This option provides an optimized way to perform cosine similarity. + /// The constraints and computed score are defined by element_type. + /// + /// + /// When element_type is float, all vectors must be unit length, including both document and query vectors. + /// + /// + /// The document _score is computed as (1 + dot_product(query, vector)) / 2. + /// + /// + /// When element_type is byte, all vectors must have the same length including both document and query vectors or + /// results will be inaccurate. + /// + /// + /// The document _score is computed as 0.5 + (dot_product(query, vector) / (32768 * dims)) where dims is the + /// number of dimensions per vector. + /// + /// + [EnumMember(Value = "dot_product")] + DotProduct, + /// + /// + /// Computes the cosine similarity. During indexing Elasticsearch automatically normalizes vectors with cosine + /// similarity to unit length. This allows to internally use dot_product for computing similarity, which is more + /// efficient. Original un-normalized vectors can be still accessed through scripts. + /// + /// + /// The document _score is computed as (1 + cosine(query, vector)) / 2. + /// + /// + /// The cosine similarity does not allow vectors with zero magnitude, since cosine is not defined in this case. + /// + /// + [EnumMember(Value = "cosine")] + Cosine +} + +internal sealed class DenseVectorSimilarityConverter : JsonConverter +{ + public override DenseVectorSimilarity Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var enumString = reader.GetString(); + switch (enumString) + { + case "max_inner_product": + return DenseVectorSimilarity.MaxInnerProduct; + case "l2_norm": + return DenseVectorSimilarity.L2Norm; + case "dot_product": + return DenseVectorSimilarity.DotProduct; + case "cosine": + return DenseVectorSimilarity.Cosine; + } + + ThrowHelper.ThrowJsonException(); + return default; + } + + public override void Write(Utf8JsonWriter writer, DenseVectorSimilarity value, JsonSerializerOptions options) + { + switch (value) + { + case DenseVectorSimilarity.MaxInnerProduct: + writer.WriteStringValue("max_inner_product"); + return; + case DenseVectorSimilarity.L2Norm: + writer.WriteStringValue("l2_norm"); + return; + case DenseVectorSimilarity.DotProduct: + writer.WriteStringValue("dot_product"); + return; + case DenseVectorSimilarity.Cosine: + writer.WriteStringValue("cosine"); + return; + } + + writer.WriteNullValue(); + } +} + [JsonConverter(typeof(DynamicMappingConverter))] public enum DynamicMapping { diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorIndexOptions.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorIndexOptions.g.cs index 72b319a4a6e..b511d9b0955 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorIndexOptions.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorIndexOptions.g.cs @@ -29,14 +29,56 @@ namespace Elastic.Clients.Elasticsearch.Mapping; public sealed partial class DenseVectorIndexOptions { + /// + /// + /// The confidence interval to use when quantizing the vectors. Can be any value between and including 0.90 and + /// 1.0 or exactly 0. When the value is 0, this indicates that dynamic quantiles should be calculated for + /// optimized quantization. When between 0.90 and 1.0, this value restricts the values used when calculating + /// the quantization thresholds. + /// + /// + /// For example, a value of 0.95 will only use the middle 95% of the values when calculating the quantization + /// thresholds (e.g. the highest and lowest 2.5% of values will be ignored). + /// + /// + /// Defaults to 1/(dims + 1) for int8 quantized vectors and 0 for int4 for dynamic quantile calculation. + /// + /// + /// Only applicable to int8_hnsw, int4_hnsw, int8_flat, and int4_flat index types. + /// + /// [JsonInclude, JsonPropertyName("confidence_interval")] public float? ConfidenceInterval { get; set; } + + /// + /// + /// The number of candidates to track while assembling the list of nearest neighbors for each new node. + /// + /// + /// Only applicable to hnsw, int8_hnsw, and int4_hnsw index types. + /// + /// [JsonInclude, JsonPropertyName("ef_construction")] public int? EfConstruction { get; set; } + + /// + /// + /// The number of neighbors each node will be connected to in the HNSW graph. + /// + /// + /// Only applicable to hnsw, int8_hnsw, and int4_hnsw index types. + /// + /// [JsonInclude, JsonPropertyName("m")] public int? m { get; set; } + + /// + /// + /// The type of kNN algorithm to use. + /// + /// [JsonInclude, JsonPropertyName("type")] - public string Type { get; set; } + public Elastic.Clients.Elasticsearch.Mapping.DenseVectorIndexOptionsType Type { get; set; } } public sealed partial class DenseVectorIndexOptionsDescriptor : SerializableDescriptor @@ -50,27 +92,66 @@ public DenseVectorIndexOptionsDescriptor() : base() private float? ConfidenceIntervalValue { get; set; } private int? EfConstructionValue { get; set; } private int? mValue { get; set; } - private string TypeValue { get; set; } + private Elastic.Clients.Elasticsearch.Mapping.DenseVectorIndexOptionsType TypeValue { get; set; } + /// + /// + /// The confidence interval to use when quantizing the vectors. Can be any value between and including 0.90 and + /// 1.0 or exactly 0. When the value is 0, this indicates that dynamic quantiles should be calculated for + /// optimized quantization. When between 0.90 and 1.0, this value restricts the values used when calculating + /// the quantization thresholds. + /// + /// + /// For example, a value of 0.95 will only use the middle 95% of the values when calculating the quantization + /// thresholds (e.g. the highest and lowest 2.5% of values will be ignored). + /// + /// + /// Defaults to 1/(dims + 1) for int8 quantized vectors and 0 for int4 for dynamic quantile calculation. + /// + /// + /// Only applicable to int8_hnsw, int4_hnsw, int8_flat, and int4_flat index types. + /// + /// public DenseVectorIndexOptionsDescriptor ConfidenceInterval(float? confidenceInterval) { ConfidenceIntervalValue = confidenceInterval; return Self; } + /// + /// + /// The number of candidates to track while assembling the list of nearest neighbors for each new node. + /// + /// + /// Only applicable to hnsw, int8_hnsw, and int4_hnsw index types. + /// + /// public DenseVectorIndexOptionsDescriptor EfConstruction(int? efConstruction) { EfConstructionValue = efConstruction; return Self; } + /// + /// + /// The number of neighbors each node will be connected to in the HNSW graph. + /// + /// + /// Only applicable to hnsw, int8_hnsw, and int4_hnsw index types. + /// + /// public DenseVectorIndexOptionsDescriptor m(int? m) { mValue = m; return Self; } - public DenseVectorIndexOptionsDescriptor Type(string type) + /// + /// + /// The type of kNN algorithm to use. + /// + /// + public DenseVectorIndexOptionsDescriptor Type(Elastic.Clients.Elasticsearch.Mapping.DenseVectorIndexOptionsType type) { TypeValue = type; return Self; @@ -98,7 +179,7 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o } writer.WritePropertyName("type"); - writer.WriteStringValue(TypeValue); + JsonSerializer.Serialize(writer, TypeValue, options); writer.WriteEndObject(); } } \ No newline at end of file diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorProperty.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorProperty.g.cs index 63eecc6fa75..b05fbb4e3a3 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorProperty.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Mapping/DenseVectorProperty.g.cs @@ -29,18 +29,47 @@ namespace Elastic.Clients.Elasticsearch.Mapping; public sealed partial class DenseVectorProperty : IProperty { + /// + /// + /// Number of vector dimensions. Can't exceed 4096. If dims is not specified, it will be set to the length of + /// the first vector added to the field. + /// + /// [JsonInclude, JsonPropertyName("dims")] public int? Dims { get; set; } [JsonInclude, JsonPropertyName("dynamic")] public Elastic.Clients.Elasticsearch.Mapping.DynamicMapping? Dynamic { get; set; } + + /// + /// + /// The data type used to encode vectors. The supported data types are float (default), byte, and bit. + /// + /// [JsonInclude, JsonPropertyName("element_type")] - public string? ElementType { get; set; } + public Elastic.Clients.Elasticsearch.Mapping.DenseVectorElementType? ElementType { get; set; } [JsonInclude, JsonPropertyName("fields")] public Elastic.Clients.Elasticsearch.Mapping.Properties? Fields { get; set; } [JsonInclude, JsonPropertyName("ignore_above")] public int? IgnoreAbove { get; set; } + + /// + /// + /// If true, you can search this field using the kNN search API. + /// + /// [JsonInclude, JsonPropertyName("index")] public bool? Index { get; set; } + + /// + /// + /// An optional section that configures the kNN indexing algorithm. The HNSW algorithm has two internal parameters + /// that influence how the data structure is built. These can be adjusted to improve the accuracy of results, at the + /// expense of slower indexing speed. + /// + /// + /// This parameter can only be specified when index is true. + /// + /// [JsonInclude, JsonPropertyName("index_options")] public Elastic.Clients.Elasticsearch.Mapping.DenseVectorIndexOptions? IndexOptions { get; set; } @@ -53,8 +82,28 @@ public sealed partial class DenseVectorProperty : IProperty public IDictionary? Meta { get; set; } [JsonInclude, JsonPropertyName("properties")] public Elastic.Clients.Elasticsearch.Mapping.Properties? Properties { get; set; } + + /// + /// + /// The vector similarity metric to use in kNN search. + /// + /// + /// Documents are ranked by their vector field's similarity to the query vector. The _score of each document will + /// be derived from the similarity, in a way that ensures scores are positive and that a larger score corresponds + /// to a higher ranking. + /// + /// + /// Defaults to l2_norm when element_type is bit otherwise defaults to cosine. + /// + /// + /// bit vectors only support l2_norm as their similarity metric. + /// + /// + /// This parameter can only be specified when index is true. + /// + /// [JsonInclude, JsonPropertyName("similarity")] - public string? Similarity { get; set; } + public Elastic.Clients.Elasticsearch.Mapping.DenseVectorSimilarity? Similarity { get; set; } [JsonInclude, JsonPropertyName("synthetic_source_keep")] public Elastic.Clients.Elasticsearch.Mapping.SyntheticSourceKeepEnum? SyntheticSourceKeep { get; set; } @@ -72,7 +121,7 @@ public DenseVectorPropertyDescriptor() : base() private int? DimsValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.DynamicMapping? DynamicValue { get; set; } - private string? ElementTypeValue { get; set; } + private Elastic.Clients.Elasticsearch.Mapping.DenseVectorElementType? ElementTypeValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.Properties? FieldsValue { get; set; } private int? IgnoreAboveValue { get; set; } private bool? IndexValue { get; set; } @@ -81,9 +130,15 @@ public DenseVectorPropertyDescriptor() : base() private Action IndexOptionsDescriptorAction { get; set; } private IDictionary? MetaValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.Properties? PropertiesValue { get; set; } - private string? SimilarityValue { get; set; } + private Elastic.Clients.Elasticsearch.Mapping.DenseVectorSimilarity? SimilarityValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.SyntheticSourceKeepEnum? SyntheticSourceKeepValue { get; set; } + /// + /// + /// Number of vector dimensions. Can't exceed 4096. If dims is not specified, it will be set to the length of + /// the first vector added to the field. + /// + /// public DenseVectorPropertyDescriptor Dims(int? dims) { DimsValue = dims; @@ -96,7 +151,12 @@ public DenseVectorPropertyDescriptor Dynamic(Elastic.Clients.Elastics return Self; } - public DenseVectorPropertyDescriptor ElementType(string? elementType) + /// + /// + /// The data type used to encode vectors. The supported data types are float (default), byte, and bit. + /// + /// + public DenseVectorPropertyDescriptor ElementType(Elastic.Clients.Elasticsearch.Mapping.DenseVectorElementType? elementType) { ElementTypeValue = elementType; return Self; @@ -128,12 +188,27 @@ public DenseVectorPropertyDescriptor IgnoreAbove(int? ignoreAbove) return Self; } + /// + /// + /// If true, you can search this field using the kNN search API. + /// + /// public DenseVectorPropertyDescriptor Index(bool? index = true) { IndexValue = index; return Self; } + /// + /// + /// An optional section that configures the kNN indexing algorithm. The HNSW algorithm has two internal parameters + /// that influence how the data structure is built. These can be adjusted to improve the accuracy of results, at the + /// expense of slower indexing speed. + /// + /// + /// This parameter can only be specified when index is true. + /// + /// public DenseVectorPropertyDescriptor IndexOptions(Elastic.Clients.Elasticsearch.Mapping.DenseVectorIndexOptions? indexOptions) { IndexOptionsDescriptor = null; @@ -189,7 +264,26 @@ public DenseVectorPropertyDescriptor Properties(Action Similarity(string? similarity) + /// + /// + /// The vector similarity metric to use in kNN search. + /// + /// + /// Documents are ranked by their vector field's similarity to the query vector. The _score of each document will + /// be derived from the similarity, in a way that ensures scores are positive and that a larger score corresponds + /// to a higher ranking. + /// + /// + /// Defaults to l2_norm when element_type is bit otherwise defaults to cosine. + /// + /// + /// bit vectors only support l2_norm as their similarity metric. + /// + /// + /// This parameter can only be specified when index is true. + /// + /// + public DenseVectorPropertyDescriptor Similarity(Elastic.Clients.Elasticsearch.Mapping.DenseVectorSimilarity? similarity) { SimilarityValue = similarity; return Self; @@ -216,10 +310,10 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o JsonSerializer.Serialize(writer, DynamicValue, options); } - if (!string.IsNullOrEmpty(ElementTypeValue)) + if (ElementTypeValue is not null) { writer.WritePropertyName("element_type"); - writer.WriteStringValue(ElementTypeValue); + JsonSerializer.Serialize(writer, ElementTypeValue, options); } if (FieldsValue is not null) @@ -268,10 +362,10 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o JsonSerializer.Serialize(writer, PropertiesValue, options); } - if (!string.IsNullOrEmpty(SimilarityValue)) + if (SimilarityValue is not null) { writer.WritePropertyName("similarity"); - writer.WriteStringValue(SimilarityValue); + JsonSerializer.Serialize(writer, SimilarityValue, options); } if (SyntheticSourceKeepValue is not null) @@ -335,7 +429,7 @@ public DenseVectorPropertyDescriptor() : base() private int? DimsValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.DynamicMapping? DynamicValue { get; set; } - private string? ElementTypeValue { get; set; } + private Elastic.Clients.Elasticsearch.Mapping.DenseVectorElementType? ElementTypeValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.Properties? FieldsValue { get; set; } private int? IgnoreAboveValue { get; set; } private bool? IndexValue { get; set; } @@ -344,9 +438,15 @@ public DenseVectorPropertyDescriptor() : base() private Action IndexOptionsDescriptorAction { get; set; } private IDictionary? MetaValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.Properties? PropertiesValue { get; set; } - private string? SimilarityValue { get; set; } + private Elastic.Clients.Elasticsearch.Mapping.DenseVectorSimilarity? SimilarityValue { get; set; } private Elastic.Clients.Elasticsearch.Mapping.SyntheticSourceKeepEnum? SyntheticSourceKeepValue { get; set; } + /// + /// + /// Number of vector dimensions. Can't exceed 4096. If dims is not specified, it will be set to the length of + /// the first vector added to the field. + /// + /// public DenseVectorPropertyDescriptor Dims(int? dims) { DimsValue = dims; @@ -359,7 +459,12 @@ public DenseVectorPropertyDescriptor Dynamic(Elastic.Clients.Elasticsearch.Mappi return Self; } - public DenseVectorPropertyDescriptor ElementType(string? elementType) + /// + /// + /// The data type used to encode vectors. The supported data types are float (default), byte, and bit. + /// + /// + public DenseVectorPropertyDescriptor ElementType(Elastic.Clients.Elasticsearch.Mapping.DenseVectorElementType? elementType) { ElementTypeValue = elementType; return Self; @@ -391,12 +496,27 @@ public DenseVectorPropertyDescriptor IgnoreAbove(int? ignoreAbove) return Self; } + /// + /// + /// If true, you can search this field using the kNN search API. + /// + /// public DenseVectorPropertyDescriptor Index(bool? index = true) { IndexValue = index; return Self; } + /// + /// + /// An optional section that configures the kNN indexing algorithm. The HNSW algorithm has two internal parameters + /// that influence how the data structure is built. These can be adjusted to improve the accuracy of results, at the + /// expense of slower indexing speed. + /// + /// + /// This parameter can only be specified when index is true. + /// + /// public DenseVectorPropertyDescriptor IndexOptions(Elastic.Clients.Elasticsearch.Mapping.DenseVectorIndexOptions? indexOptions) { IndexOptionsDescriptor = null; @@ -452,7 +572,26 @@ public DenseVectorPropertyDescriptor Properties(Action + /// + /// The vector similarity metric to use in kNN search. + /// + /// + /// Documents are ranked by their vector field's similarity to the query vector. The _score of each document will + /// be derived from the similarity, in a way that ensures scores are positive and that a larger score corresponds + /// to a higher ranking. + /// + /// + /// Defaults to l2_norm when element_type is bit otherwise defaults to cosine. + /// + /// + /// bit vectors only support l2_norm as their similarity metric. + /// + /// + /// This parameter can only be specified when index is true. + /// + /// + public DenseVectorPropertyDescriptor Similarity(Elastic.Clients.Elasticsearch.Mapping.DenseVectorSimilarity? similarity) { SimilarityValue = similarity; return Self; @@ -479,10 +618,10 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o JsonSerializer.Serialize(writer, DynamicValue, options); } - if (!string.IsNullOrEmpty(ElementTypeValue)) + if (ElementTypeValue is not null) { writer.WritePropertyName("element_type"); - writer.WriteStringValue(ElementTypeValue); + JsonSerializer.Serialize(writer, ElementTypeValue, options); } if (FieldsValue is not null) @@ -531,10 +670,10 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o JsonSerializer.Serialize(writer, PropertiesValue, options); } - if (!string.IsNullOrEmpty(SimilarityValue)) + if (SimilarityValue is not null) { writer.WritePropertyName("similarity"); - writer.WriteStringValue(SimilarityValue); + JsonSerializer.Serialize(writer, SimilarityValue, options); } if (SyntheticSourceKeepValue is not null)