Skip to content

Commit 64fb14c

Browse files
authored
Merge pull request #353 from weaviate/feat/text2vec-google-location
feat: add optional location to text2vec-google vectorizer
2 parents bde7784 + 460374c commit 64fb14c

4 files changed

Lines changed: 55 additions & 1 deletion

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,43 @@ public void Test_Text2VecDigitalOcean_Omits_Unset_BaseURL()
497497
Assert.DoesNotContain("\"baseURL\"", json);
498498
}
499499

500+
/// <summary>
501+
/// Tests that Text2VecGoogle omits <c>location</c> when unset so the server can apply its
502+
/// default.
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_Text2VecGoogle_Omits_Unset_Location()
511+
{
512+
// Arrange
513+
var vc = Configure.Vector("default", v => v.Text2VecGoogleVertex(projectId: "my-project"));
514+
515+
// Act
516+
var dto = vc.Vectorizer?.ToDto() ?? default;
517+
var json = JsonSerializer.Serialize(
518+
dto,
519+
new JsonSerializerOptions
520+
{
521+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
522+
DefaultIgnoreCondition = System
523+
.Text
524+
.Json
525+
.Serialization
526+
.JsonIgnoreCondition
527+
.WhenWritingNull,
528+
WriteIndented = false,
529+
}
530+
);
531+
532+
// Assert
533+
Assert.Contains("\"text2vec-google\"", json);
534+
Assert.DoesNotContain("\"location\"", json);
535+
}
536+
500537
/// <summary>
501538
/// Tests that Text2VecAWS serializes <c>dimensions</c> as a JSON number (not a string) when it
502539
/// is set via the Bedrock factory.

src/Weaviate.Client/Configure/VectorizerFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ public VectorizerConfig Text2VecOpenAI(
869869
/// <param name="dimensions">The dimensions</param>
870870
/// <param name="taskType">The task type</param>
871871
/// <param name="vectorizeCollectionName">The vectorize collection name</param>
872+
/// <param name="location">The Google Vertex AI region; optional, server-defaulted when null</param>
872873
/// <returns>The vectorizer config</returns>
873874
public VectorizerConfig Text2VecGoogleVertex(
874875
string? apiEndpoint = null,
@@ -877,7 +878,8 @@ public VectorizerConfig Text2VecGoogleVertex(
877878
string? titleProperty = null,
878879
int? dimensions = null,
879880
string? taskType = null,
880-
bool? vectorizeCollectionName = null
881+
bool? vectorizeCollectionName = null,
882+
string? location = null
881883
) =>
882884
new Text2VecGoogle
883885
{
@@ -888,6 +890,7 @@ public VectorizerConfig Text2VecGoogleVertex(
888890
Dimensions = dimensions,
889891
TaskType = taskType,
890892
VectorizeCollectionName = vectorizeCollectionName,
893+
Location = location,
891894
};
892895

893896
/// <summary>
@@ -915,6 +918,9 @@ public VectorizerConfig Text2VecGoogleGemini(
915918
Dimensions = dimensions,
916919
TaskType = taskType,
917920
VectorizeCollectionName = vectorizeCollectionName,
921+
// Location (Vertex AI region) is not applicable to the Gemini
922+
// (generative-language) API; left null so it is omitted on the wire.
923+
Location = null,
918924
};
919925

920926
/// <summary>

src/Weaviate.Client/Models/Vectorizer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,13 @@ internal Text2VecGoogle() { }
12771277
/// </summary>
12781278
public string? TaskType { get; set; } = null;
12791279

1280+
/// <summary>
1281+
/// Gets or sets the Google Vertex AI region.
1282+
/// Optional; when omitted the server applies its default.
1283+
/// Serialized as the lowercase <c>location</c> module-config key.
1284+
/// </summary>
1285+
public string? Location { get; set; } = null;
1286+
12801287
/// <summary>
12811288
/// Gets or sets the value of the vectorize collection name
12821289
/// </summary>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#nullable enable
22
*REMOVED*Weaviate.Client.VectorizerFactory.Text2VecAWSBedrock(string! region, string! model, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
33
*REMOVED*Weaviate.Client.VectorizerFactory.Text2VecAWSSagemaker(string! region, string! endpoint, string? targetModel = null, string? targetVariant = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
4+
*REMOVED*Weaviate.Client.VectorizerFactory.Text2VecGoogleVertex(string? apiEndpoint = null, string? model = null, string? projectId = null, string? titleProperty = null, int? dimensions = null, string? taskType = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
45
Weaviate.Client.Models.Vectorizer.Text2VecAWS.Dimensions.get -> int?
56
Weaviate.Client.Models.Vectorizer.Text2VecAWS.Dimensions.set -> void
7+
Weaviate.Client.Models.Vectorizer.Text2VecGoogle.Location.get -> string?
8+
Weaviate.Client.Models.Vectorizer.Text2VecGoogle.Location.set -> void
69
Weaviate.Client.VectorizerFactory.Text2VecAWSBedrock(string! region, string! model, int? dimensions = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
710
Weaviate.Client.VectorizerFactory.Text2VecAWSSagemaker(string! region, string! endpoint, string? targetModel = null, string? targetVariant = null, int? dimensions = null, bool? vectorizeCollectionName = null) -> Weaviate.Client.Models.VectorizerConfig!
11+
Weaviate.Client.VectorizerFactory.Text2VecGoogleVertex(string? apiEndpoint = null, string? model = null, string? projectId = null, string? titleProperty = null, int? dimensions = null, string? taskType = null, bool? vectorizeCollectionName = null, string? location = null) -> Weaviate.Client.Models.VectorizerConfig!

0 commit comments

Comments
 (0)