Skip to content

Commit aa333c1

Browse files
committed
feat: add optional dimensions to text2vec-aws vectorizer
1 parent e774135 commit aa333c1

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

src/Weaviate.Client.Tests/Unit/TestVectorizers.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,90 @@ public void Test_Text2VecDigitalOcean_Omits_Unset_BaseURL()
496496
Assert.Contains("\"model\":\"qwen3-embedding-0.6b\"", json);
497497
Assert.DoesNotContain("\"baseURL\"", json);
498498
}
499+
500+
/// <summary>
501+
/// Tests that Text2VecAWS serializes <c>dimensions</c> as a JSON number (not a string) when it
502+
/// is set via the Bedrock factory.
503+
/// </summary>
504+
[Fact]
505+
[System.Diagnostics.CodeAnalysis.SuppressMessage(
506+
"Performance",
507+
"CA1869:Cache and reuse 'JsonSerializerOptions' instances",
508+
Justification = "<Pending>"
509+
)]
510+
public void Test_Text2VecAWS_Serializes_Dimensions_When_Set()
511+
{
512+
// Arrange
513+
var vc = Configure.Vector(
514+
"default",
515+
v =>
516+
v.Text2VecAWSBedrock(
517+
region: "us-east-1",
518+
model: "amazon.titan-embed-text-v2:0",
519+
dimensions: 1024
520+
)
521+
);
522+
523+
// Act
524+
var dto = vc.Vectorizer?.ToDto() ?? default;
525+
var json = JsonSerializer.Serialize(
526+
dto,
527+
new JsonSerializerOptions
528+
{
529+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
530+
DefaultIgnoreCondition = System
531+
.Text
532+
.Json
533+
.Serialization
534+
.JsonIgnoreCondition
535+
.WhenWritingNull,
536+
WriteIndented = false,
537+
}
538+
);
539+
540+
// Assert
541+
Assert.Contains("\"text2vec-aws\"", json);
542+
Assert.Contains("\"dimensions\":1024", json);
543+
Assert.DoesNotContain("\"dimensions\":\"1024\"", json);
544+
}
545+
546+
/// <summary>
547+
/// Tests that Text2VecAWS omits <c>dimensions</c> when it is unset so the server can apply its
548+
/// default.
549+
/// </summary>
550+
[Fact]
551+
[System.Diagnostics.CodeAnalysis.SuppressMessage(
552+
"Performance",
553+
"CA1869:Cache and reuse 'JsonSerializerOptions' instances",
554+
Justification = "<Pending>"
555+
)]
556+
public void Test_Text2VecAWS_Omits_Unset_Dimensions()
557+
{
558+
// Arrange
559+
var vc = Configure.Vector(
560+
"default",
561+
v => v.Text2VecAWSSagemaker(region: "us-east-1", endpoint: "my-endpoint")
562+
);
563+
564+
// Act
565+
var dto = vc.Vectorizer?.ToDto() ?? default;
566+
var json = JsonSerializer.Serialize(
567+
dto,
568+
new JsonSerializerOptions
569+
{
570+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
571+
DefaultIgnoreCondition = System
572+
.Text
573+
.Json
574+
.Serialization
575+
.JsonIgnoreCondition
576+
.WhenWritingNull,
577+
WriteIndented = false,
578+
}
579+
);
580+
581+
// Assert
582+
Assert.Contains("\"text2vec-aws\"", json);
583+
Assert.DoesNotContain("\"dimensions\"", json);
584+
}
499585
}

src/Weaviate.Client/Configure/VectorizerFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,13 @@ public VectorizerConfig Ref2VecCentroid(string[] referenceProperties, string met
536536
/// </summary>
537537
/// <param name="region">The region</param>
538538
/// <param name="model">The model</param>
539+
/// <param name="dimensions">Number of vector dimensions.</param>
539540
/// <param name="vectorizeCollectionName">The vectorize collection name</param>
540541
/// <returns>The vectorizer config</returns>
541542
public VectorizerConfig Text2VecAWSBedrock(
542543
string region,
543544
string model,
545+
int? dimensions = null,
544546
bool? vectorizeCollectionName = null
545547
) =>
546548
new Text2VecAWS
@@ -551,6 +553,7 @@ public VectorizerConfig Text2VecAWSBedrock(
551553
Model = model,
552554
TargetModel = null,
553555
TargetVariant = null,
556+
Dimensions = dimensions,
554557
VectorizeCollectionName = vectorizeCollectionName,
555558
};
556559

@@ -561,13 +564,15 @@ public VectorizerConfig Text2VecAWSBedrock(
561564
/// <param name="endpoint">The endpoint</param>
562565
/// <param name="targetModel">The target model</param>
563566
/// <param name="targetVariant">The target variant</param>
567+
/// <param name="dimensions">Number of vector dimensions.</param>
564568
/// <param name="vectorizeCollectionName">The vectorize collection name</param>
565569
/// <returns>The vectorizer config</returns>
566570
public VectorizerConfig Text2VecAWSSagemaker(
567571
string region,
568572
string endpoint,
569573
string? targetModel = null,
570574
string? targetVariant = null,
575+
int? dimensions = null,
571576
bool? vectorizeCollectionName = null
572577
) =>
573578
new Text2VecAWS
@@ -578,6 +583,7 @@ public VectorizerConfig Text2VecAWSSagemaker(
578583
Model = null,
579584
TargetModel = targetModel,
580585
TargetVariant = targetVariant,
586+
Dimensions = dimensions,
581587
VectorizeCollectionName = vectorizeCollectionName,
582588
};
583589

src/Weaviate.Client/Models/Vectorizer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ internal Text2VecAWS() { }
717717
/// </summary>
718718
public string? TargetVariant { get; set; } = null;
719719

720+
/// <summary>
721+
/// Gets or sets the value of the dimensions
722+
/// </summary>
723+
public int? Dimensions { get; set; } = null;
724+
720725
/// <summary>
721726
/// Gets or sets the value of the vectorize collection name
722727
/// </summary>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
#nullable enable
2+
*REMOVED*Weaviate.Client.VectorizerFactory.Text2VecAWSBedrock(string! region, string! model, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
3+
*REMOVED*Weaviate.Client.VectorizerFactory.Text2VecAWSSagemaker(string! region, string! endpoint, string? targetModel = null, string? targetVariant = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
4+
Weaviate.Client.Models.Vectorizer.Text2VecAWS.Dimensions.get -> int?
5+
Weaviate.Client.Models.Vectorizer.Text2VecAWS.Dimensions.set -> void
6+
Weaviate.Client.VectorizerFactory.Text2VecAWSBedrock(string! region, string! model, int? dimensions = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
7+
Weaviate.Client.VectorizerFactory.Text2VecAWSSagemaker(string! region, string! endpoint, string? targetModel = null, string? targetVariant = null, int? dimensions = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!

0 commit comments

Comments
 (0)