Skip to content

Commit 3adda03

Browse files
authored
Merge pull request #548 from weaviate/feat/multi2vec-google-audio
Add audio modality to multi2vec-google vectorizers
2 parents 391b875 + d6f8755 commit 3adda03

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/vectorizers/Multi2VecGoogleVectorizer.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public record Multi2VecGoogleVectorizer(
2323
@SerializedName("imageFields") List<String> imageFields,
2424
/** BLOB video properties included in the embedding. */
2525
@SerializedName("videoFields") List<String> videoFields,
26+
/** BLOB audio properties included in the embedding. */
27+
@SerializedName("audioFields") List<String> audioFields,
2628
/** TEXT properties included in the embedding. */
2729
@SerializedName("textFields") List<String> textFields,
2830
/** Weights of the included properties. */
@@ -43,6 +45,11 @@ private static record Weights(
4345
* corresponding property names in {@code videoFields}.
4446
*/
4547
@SerializedName("videoWeights") List<Float> videoWeights,
48+
/**
49+
* Weights of the BLOB audio properties. Values appear in the same order as the
50+
* corresponding property names in {@code audioFields}.
51+
*/
52+
@SerializedName("audioWeights") List<Float> audioWeights,
4653
/**
4754
* Weights of the TEXT properties. Values appear in the same order as the
4855
* corresponding property names in {@code textFields}.
@@ -101,6 +108,7 @@ public Multi2VecGoogleVectorizer(
101108
Integer videoIntervalSeconds,
102109
List<String> imageFields,
103110
List<String> videoFields,
111+
List<String> audioFields,
104112
List<String> textFields,
105113
Weights weights,
106114
VectorIndex vectorIndex,
@@ -114,6 +122,7 @@ public Multi2VecGoogleVectorizer(
114122
this.videoIntervalSeconds = videoIntervalSeconds;
115123
this.imageFields = imageFields;
116124
this.videoFields = videoFields;
125+
this.audioFields = audioFields;
117126
this.textFields = textFields;
118127
this.weights = weights;
119128
this.vectorIndex = vectorIndex;
@@ -130,6 +139,7 @@ public Multi2VecGoogleVectorizer(Builder builder) {
130139
builder.videoIntervalSeconds,
131140
builder.imageFields,
132141
builder.videoFields,
142+
builder.audioFields,
133143
builder.textFields,
134144
builder.getWeights(),
135145
builder.vectorIndex,
@@ -143,7 +153,9 @@ public static class Builder implements ObjectBuilder<Multi2VecGoogleVectorizer>
143153
private List<String> imageFields;
144154
private List<Float> imageWeights;
145155
private List<String> videoFields;
156+
private List<String> audioFields;
146157
private List<Float> videoWeights;
158+
private List<Float> audioWeights;
147159
private List<String> textFields;
148160
private List<Float> textWeights;
149161

@@ -242,6 +254,35 @@ public Builder videoField(String field, float weight) {
242254
return this;
243255
}
244256

257+
/** Add BLOB audio properties to include in the embedding. */
258+
public Builder audioFields(List<String> fields) {
259+
this.audioFields = fields;
260+
return this;
261+
}
262+
263+
/** Add BLOB audio properties to include in the embedding. */
264+
public Builder audioFields(String... fields) {
265+
return audioFields(Arrays.asList(fields));
266+
}
267+
268+
/**
269+
* Add BLOB audio property to include in the embedding.
270+
*
271+
* @param field Property name.
272+
* @param weight Custom weight between 0.0 and 1.0.
273+
*/
274+
public Builder audioField(String field, float weight) {
275+
if (this.audioFields == null) {
276+
this.audioFields = new ArrayList<>();
277+
}
278+
if (this.audioWeights == null) {
279+
this.audioWeights = new ArrayList<>();
280+
}
281+
this.audioFields.add(field);
282+
this.audioWeights.add(weight);
283+
return this;
284+
}
285+
245286
/** Add TEXT properties to include in the embedding. */
246287
public Builder textFields(List<String> fields) {
247288
this.textFields = fields;
@@ -272,8 +313,9 @@ public Builder textField(String field, float weight) {
272313
}
273314

274315
protected Weights getWeights() {
275-
if (this.textWeights != null || this.imageWeights != null || this.videoWeights != null) {
276-
return new Weights(this.imageWeights, this.videoWeights, this.textWeights);
316+
if (this.textWeights != null || this.imageWeights != null || this.videoWeights != null
317+
|| this.audioWeights != null) {
318+
return new Weights(this.imageWeights, this.videoWeights, this.audioWeights, this.textWeights);
277319
}
278320
return null;
279321
}

src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ public static Object[][] testCases() {
792792
.apiEndpoint("example.com")
793793
.imageFields("a", "b")
794794
.textFields("c")
795-
.videoFields("d")),
795+
.videoFields("d")
796+
.audioFields("f")),
796797
"""
797798
{
798799
"vectorIndexType": "hnsw",
@@ -804,7 +805,8 @@ public static Object[][] testCases() {
804805
"location": "location",
805806
"imageFields": ["a", "b"],
806807
"textFields": ["c"],
807-
"videoFields": ["d"]
808+
"videoFields": ["d"],
809+
"audioFields": ["f"]
808810
}
809811
}
810812
}

0 commit comments

Comments
 (0)