Skip to content

Commit 39772a5

Browse files
committed
Refactor Vertex AI embedding/Gemini options builder methods
- Deprecate the builder methods with the prefix `with` - Update references and docs
1 parent d77c950 commit 39772a5

File tree

27 files changed

+592
-107
lines changed

27 files changed

+592
-107
lines changed

models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/VertexAiEmbeddingConnectionDetails.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
* @author Christian Tzolov
3232
* @author Mark Pollack
33+
* @author Ilayaperumal Gopinathan
3334
* @since 1.0.0
3435
*/
3536
public class VertexAiEmbeddingConnectionDetails {
@@ -125,26 +126,72 @@ public static class Builder {
125126
*/
126127
private PredictionServiceSettings predictionServiceSettings;
127128

129+
public Builder apiEndpoint(String endpoint) {
130+
this.endpoint = endpoint;
131+
return this;
132+
}
133+
134+
public Builder projectId(String projectId) {
135+
this.projectId = projectId;
136+
return this;
137+
}
138+
139+
public Builder location(String location) {
140+
this.location = location;
141+
return this;
142+
}
143+
144+
public Builder publisher(String publisher) {
145+
this.publisher = publisher;
146+
return this;
147+
}
148+
149+
public Builder predictionServiceSettings(PredictionServiceSettings predictionServiceSettings) {
150+
this.predictionServiceSettings = predictionServiceSettings;
151+
return this;
152+
}
153+
154+
/**
155+
* @deprecated use {@link #apiEndpoint(String)} instead.
156+
*/
157+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
128158
public Builder withApiEndpoint(String endpoint) {
129159
this.endpoint = endpoint;
130160
return this;
131161
}
132162

163+
/**
164+
* @deprecated use {@link #projectId(String)} instead.
165+
*/
166+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
133167
public Builder withProjectId(String projectId) {
134168
this.projectId = projectId;
135169
return this;
136170
}
137171

172+
/**
173+
* @deprecated use {@link #location(String)} instead.
174+
*/
175+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
138176
public Builder withLocation(String location) {
139177
this.location = location;
140178
return this;
141179
}
142180

181+
/**
182+
* @deprecated use {@link #publisher(String)} instead.
183+
*/
184+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
143185
public Builder withPublisher(String publisher) {
144186
this.publisher = publisher;
145187
return this;
146188
}
147189

190+
/**
191+
* @deprecated use {@link #predictionServiceSettings(PredictionServiceSettings)}
192+
* instead.
193+
*/
194+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
148195
public Builder withPredictionServiceSettings(PredictionServiceSettings predictionServiceSettings) {
149196
this.predictionServiceSettings = predictionServiceSettings;
150197
return this;

models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/VertexAiEmbeddingUtils.java

Lines changed: 192 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Utility class for constructing parameter objects for Vertex AI embedding requests.
3333
*
3434
* @author Christian Tzolov
35+
* @author Ilayaperumal Gopinathan
3536
* @since 1.0.0
3637
*/
3738
public abstract class VertexAiEmbeddingUtils {
@@ -82,12 +83,32 @@ public static TextParametersBuilder of() {
8283
return new TextParametersBuilder();
8384
}
8485

86+
public TextParametersBuilder outputDimensionality(Integer outputDimensionality) {
87+
Assert.notNull(outputDimensionality, "Output dimensionality must not be null");
88+
this.outputDimensionality = outputDimensionality;
89+
return this;
90+
}
91+
92+
public TextParametersBuilder autoTruncate(Boolean autoTruncate) {
93+
Assert.notNull(autoTruncate, "Auto truncate must not be null");
94+
this.autoTruncate = autoTruncate;
95+
return this;
96+
}
97+
98+
/**
99+
* @deprecated use {@link #outputDimensionality(Integer)} instead.
100+
*/
101+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
85102
public TextParametersBuilder withOutputDimensionality(Integer outputDimensionality) {
86103
Assert.notNull(outputDimensionality, "Output dimensionality must not be null");
87104
this.outputDimensionality = outputDimensionality;
88105
return this;
89106
}
90107

108+
/**
109+
* @deprecated use {@link #autoTruncate(Boolean)} instead.
110+
*/
111+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
91112
public TextParametersBuilder withAutoTruncate(Boolean autoTruncate) {
92113
Assert.notNull(autoTruncate, "Auto truncate must not be null");
93114
this.autoTruncate = autoTruncate;
@@ -123,12 +144,32 @@ public static TextInstanceBuilder of(String content) {
123144
return builder;
124145
}
125146

147+
public TextInstanceBuilder taskType(String taskType) {
148+
Assert.hasText(taskType, "Task type must not be empty");
149+
this.taskType = taskType;
150+
return this;
151+
}
152+
153+
public TextInstanceBuilder title(String title) {
154+
Assert.hasText(title, "Title must not be empty");
155+
this.title = title;
156+
return this;
157+
}
158+
159+
/**
160+
* @deprecated use {@link #taskType(String)} instead.
161+
*/
162+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
126163
public TextInstanceBuilder withTaskType(String taskType) {
127164
Assert.hasText(taskType, "Task type must not be empty");
128165
this.taskType = taskType;
129166
return this;
130167
}
131168

169+
/**
170+
* @deprecated use {@link #title(String)} instead.
171+
*/
172+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
132173
public TextInstanceBuilder withTitle(String title) {
133174
Assert.hasText(title, "Title must not be empty");
134175
this.title = title;
@@ -179,25 +220,66 @@ public static MultimodalInstanceBuilder of() {
179220
return new MultimodalInstanceBuilder();
180221
}
181222

223+
public MultimodalInstanceBuilder text(String text) {
224+
Assert.hasText(text, "Text must not be empty");
225+
this.text = text;
226+
return this;
227+
}
228+
229+
public MultimodalInstanceBuilder dimension(Integer dimension) {
230+
Assert.isTrue(dimension == 128 || dimension == 256 || dimension == 512 || dimension == 1408,
231+
"Invalid dimension value: " + dimension + ". Accepted values: 128, 256, 512, or 1408.");
232+
this.dimension = dimension;
233+
return this;
234+
}
235+
236+
public MultimodalInstanceBuilder image(Struct image) {
237+
Assert.notNull(image, "Image must not be null");
238+
this.image = image;
239+
return this;
240+
}
241+
242+
public MultimodalInstanceBuilder video(Struct video) {
243+
Assert.notNull(video, "Video must not be null");
244+
this.video = video;
245+
return this;
246+
}
247+
248+
/**
249+
* @deprecated use {@link #text(String)} instead.
250+
*/
251+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
182252
public MultimodalInstanceBuilder withText(String text) {
183253
Assert.hasText(text, "Text must not be empty");
184254
this.text = text;
185255
return this;
186256
}
187257

258+
/**
259+
* @deprecated use {@link #dimension(Integer)} instead.
260+
*/
261+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
188262
public MultimodalInstanceBuilder withDimension(Integer dimension) {
189263
Assert.isTrue(dimension == 128 || dimension == 256 || dimension == 512 || dimension == 1408,
190264
"Invalid dimension value: " + dimension + ". Accepted values: 128, 256, 512, or 1408.");
191265
this.dimension = dimension;
192266
return this;
193267
}
194268

269+
/**
270+
* @deprecated use {@link #image(Struct)} instead.
271+
*/
272+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
195273
public MultimodalInstanceBuilder withImage(Struct image) {
196274
Assert.notNull(image, "Image must not be null");
197275
this.image = image;
198276
return this;
199277
}
200278

279+
/**
280+
* @deprecated use {@link #video(Struct)} instead.
281+
*/
282+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
201283
public MultimodalInstanceBuilder withVideo(Struct video) {
202284
Assert.notNull(video, "Video must not be null");
203285
this.video = video;
@@ -255,6 +337,35 @@ public static ImageBuilder of(MimeType mimeType) {
255337
return builder;
256338
}
257339

340+
public ImageBuilder imageData(Object imageData) {
341+
Assert.notNull(imageData, "Image data must not be null");
342+
if (imageData instanceof byte[] bytes) {
343+
return imageBytes(bytes);
344+
}
345+
else if (imageData instanceof String uri) {
346+
return gcsUri(uri);
347+
}
348+
else {
349+
throw new IllegalArgumentException("Unsupported image data type: " + imageData.getClass());
350+
}
351+
}
352+
353+
public ImageBuilder imageBytes(byte[] imageBytes) {
354+
Assert.notNull(imageBytes, "Image bytes must not be null");
355+
this.imageBytes = imageBytes;
356+
return this;
357+
}
358+
359+
public ImageBuilder gcsUri(String gcsUri) {
360+
Assert.hasText(gcsUri, "GCS URI must not be empty");
361+
this.gcsUri = gcsUri;
362+
return this;
363+
}
364+
365+
/**
366+
* @deprecated use {@link #imageData(Object)} instead.
367+
*/
368+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
258369
public ImageBuilder withImageData(Object imageData) {
259370
Assert.notNull(imageData, "Image data must not be null");
260371
if (imageData instanceof byte[] bytes) {
@@ -268,12 +379,20 @@ else if (imageData instanceof String uri) {
268379
}
269380
}
270381

382+
/**
383+
* @deprecated use {@link #imageBytes(byte[])} instead.
384+
*/
385+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
271386
public ImageBuilder withImageBytes(byte[] imageBytes) {
272387
Assert.notNull(imageBytes, "Image bytes must not be null");
273388
this.imageBytes = imageBytes;
274389
return this;
275390
}
276391

392+
/**
393+
* @deprecated use {@link #gcsUri(String)} instead.
394+
*/
395+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
277396
public ImageBuilder withGcsUri(String gcsUri) {
278397
Assert.hasText(gcsUri, "GCS URI must not be empty");
279398
this.gcsUri = gcsUri;
@@ -351,38 +470,105 @@ public static VideoBuilder of(MimeType mimeType) {
351470
return builder;
352471
}
353472

473+
public VideoBuilder videoData(Object imageData) {
474+
Assert.notNull(imageData, "Video data must not be null");
475+
if (imageData instanceof byte[] imageBytes) {
476+
return videoBytes(imageBytes);
477+
}
478+
else if (imageData instanceof String uri) {
479+
return gcsUri(uri);
480+
}
481+
else {
482+
throw new IllegalArgumentException("Unsupported image data type: " + imageData.getClass());
483+
}
484+
}
485+
486+
public VideoBuilder videoBytes(byte[] imageBytes) {
487+
Assert.notNull(imageBytes, "Video bytes must not be null");
488+
this.videoBytes = imageBytes;
489+
return this;
490+
}
491+
492+
public VideoBuilder gcsUri(String gcsUri) {
493+
Assert.hasText(gcsUri, "GCS URI must not be empty");
494+
this.gcsUri = gcsUri;
495+
return this;
496+
}
497+
498+
public VideoBuilder startOffsetSec(Integer startOffsetSec) {
499+
if (startOffsetSec != null) {
500+
this.startOffsetSec = startOffsetSec;
501+
}
502+
return this;
503+
}
504+
505+
public VideoBuilder endOffsetSec(Integer endOffsetSec) {
506+
if (endOffsetSec != null) {
507+
this.endOffsetSec = endOffsetSec;
508+
}
509+
return this;
510+
511+
}
512+
513+
public VideoBuilder intervalSec(Integer intervalSec) {
514+
if (intervalSec != null) {
515+
this.intervalSec = intervalSec;
516+
}
517+
return this;
518+
}
519+
520+
/**
521+
* @deprecated use {@link #videoData(Object)} instead.
522+
*/
523+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
354524
public VideoBuilder withVideoData(Object imageData) {
355525
Assert.notNull(imageData, "Video data must not be null");
356526
if (imageData instanceof byte[] imageBytes) {
357-
return withVideoBytes(imageBytes);
527+
return videoBytes(imageBytes);
358528
}
359529
else if (imageData instanceof String uri) {
360-
return withGcsUri(uri);
530+
return gcsUri(uri);
361531
}
362532
else {
363533
throw new IllegalArgumentException("Unsupported image data type: " + imageData.getClass());
364534
}
365535
}
366536

537+
/**
538+
* @deprecated use {@link #videoBytes(byte[])} instead.
539+
*/
540+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
367541
public VideoBuilder withVideoBytes(byte[] imageBytes) {
368542
Assert.notNull(imageBytes, "Video bytes must not be null");
369543
this.videoBytes = imageBytes;
370544
return this;
371545
}
372546

547+
/**
548+
* @deprecated use {@link #gcsUri(String)} instead.
549+
*/
550+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
373551
public VideoBuilder withGcsUri(String gcsUri) {
374552
Assert.hasText(gcsUri, "GCS URI must not be empty");
375553
this.gcsUri = gcsUri;
376554
return this;
377555
}
378556

557+
/**
558+
* @deprecated use {@link #startOffsetSec(Integer)} instead.
559+
*/
560+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
379561
public VideoBuilder withStartOffsetSec(Integer startOffsetSec) {
380562
if (startOffsetSec != null) {
381563
this.startOffsetSec = startOffsetSec;
382564
}
383565
return this;
384566
}
385567

568+
/**
569+
* @deprecated use {@link #endOffsetSec(Integer)} instead.
570+
*/
571+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
386572
public VideoBuilder withEndOffsetSec(Integer endOffsetSec) {
387573
if (endOffsetSec != null) {
388574
this.endOffsetSec = endOffsetSec;
@@ -391,6 +577,10 @@ public VideoBuilder withEndOffsetSec(Integer endOffsetSec) {
391577

392578
}
393579

580+
/**
581+
* @deprecated use {@link #intervalSec(Integer)} instead.
582+
*/
583+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
394584
public VideoBuilder withIntervalSec(Integer intervalSec) {
395585
if (intervalSec != null) {
396586
this.intervalSec = intervalSec;

0 commit comments

Comments
 (0)