Skip to content

Commit abfa495

Browse files
committed
feat: add sourceProperties to text-based vectorizers
1 parent 2ed93a8 commit abfa495

3 files changed

Lines changed: 78 additions & 6 deletions

File tree

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.weaviate.client6.v1.api.collections.vectorizers;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.Collections;
6+
import java.util.List;
37
import java.util.function.Function;
48

59
import com.google.gson.annotations.SerializedName;
@@ -11,13 +15,16 @@
1115
public record Text2VecContextionaryVectorizer(
1216
/**
1317
* Weaviate defaults to {@code true} if the value is not provided.
14-
* Because text2vec-contextionary cannot handle understores in collection names,
18+
* Because text2vec-contextionary cannot handle underscores in collection names,
1519
* this quickly becomes inconvenient.
1620
*
1721
* To avoid that we send "vectorizeClassName": false all the time
1822
* and make it impossible to enable this feature, as it is deprecated.
1923
*/
2024
@Deprecated @SerializedName("vectorizeClassName") boolean vectorizeCollectionName,
25+
/** Properties included in the embedding. */
26+
@SerializedName("sourceProperties") List<String> sourceProperties,
27+
/** Vector index configuration. */
2128
VectorIndex vectorIndex) implements Vectorizer {
2229

2330
@Override
@@ -42,20 +49,41 @@ public static Text2VecContextionaryVectorizer of(
4249
/**
4350
* Canonical constructor always sets {@link #vectorizeCollectionName} to false.
4451
*/
45-
public Text2VecContextionaryVectorizer(boolean vectorizeCollectionName, VectorIndex vectorIndex) {
52+
public Text2VecContextionaryVectorizer(boolean vectorizeCollectionName, List<String> sourceProperties,
53+
VectorIndex vectorIndex) {
4654
this.vectorizeCollectionName = false;
4755
this.vectorIndex = vectorIndex;
56+
this.sourceProperties = Collections.emptyList();
4857
}
4958

5059
public Text2VecContextionaryVectorizer(Builder builder) {
51-
this(builder.vectorizeCollectionName, builder.vectorIndex);
60+
this(builder.vectorizeCollectionName, builder.sourceProperties, builder.vectorIndex);
5261
}
5362

5463
public static class Builder implements ObjectBuilder<Text2VecContextionaryVectorizer> {
5564
private final boolean vectorizeCollectionName = false;
5665

66+
private List<String> sourceProperties = new ArrayList<>();
5767
private VectorIndex vectorIndex = VectorIndex.DEFAULT_VECTOR_INDEX;
5868

69+
/** Add properties to include in the embedding. */
70+
public Builder sourceProperties(String... properties) {
71+
return sourceProperties(Arrays.asList(properties));
72+
}
73+
74+
/** Add properties to include in the embedding. */
75+
public Builder sourceProperties(List<String> properties) {
76+
this.sourceProperties.addAll(properties);
77+
return this;
78+
}
79+
80+
/**
81+
* Override default vector index configuration.
82+
*
83+
* <a href=
84+
* "https://docs.weaviate.io/weaviate/config-refs/indexing/vector-index#hnsw-index-parameters">HNSW</a>
85+
* is the default vector index.
86+
*/
5987
public Builder vectorIndex(VectorIndex vectorIndex) {
6088
this.vectorIndex = vectorIndex;
6189
return this;

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.weaviate.client6.v1.api.collections.vectorizers;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
36
import java.util.function.Function;
47

58
import com.google.gson.annotations.SerializedName;
@@ -9,9 +12,15 @@
912
import io.weaviate.client6.v1.internal.ObjectBuilder;
1013

1114
public record Text2VecWeaviateVectorizer(
15+
/** Weaviate Embeddings Service base URL. */
1216
@SerializedName("baseUrl") String inferenceUrl,
17+
/** Dimensionality of the generated vectors. */
1318
@SerializedName("dimensions") Integer dimensions,
19+
/** Embedding model. */
1420
@SerializedName("model") String model,
21+
/** Properties included in the embedding. */
22+
@SerializedName("sourceProperties") List<String> sourceProperties,
23+
/** Vector index configuration. */
1524
VectorIndex vectorIndex) implements Vectorizer {
1625

1726
@Override
@@ -37,33 +46,65 @@ public Text2VecWeaviateVectorizer(Builder builder) {
3746
builder.inferenceUrl,
3847
builder.dimensions,
3948
builder.model,
49+
builder.sourceProperties,
4050
builder.vectorIndex);
4151
}
4252

43-
public static final String SNOWFLAKE_ARCTIC_EMBED_L_20 = "Snowflake/snowflake-arctic-embed-l-v2.0";
4453
public static final String SNOWFLAKE_ARCTIC_EMBED_M_15 = "Snowflake/snowflake-arctic-embed-m-v1.5";
54+
public static final String SNOWFLAKE_ARCTIC_EMBED_L_20 = "Snowflake/snowflake-arctic-embed-l-v2.0";
4555

4656
public static class Builder implements ObjectBuilder<Text2VecWeaviateVectorizer> {
4757
private VectorIndex vectorIndex = VectorIndex.DEFAULT_VECTOR_INDEX;
4858
private String inferenceUrl;
4959
private Integer dimensions;
5060
private String model;
61+
private List<String> sourceProperties = new ArrayList<>();
5162

63+
/**
64+
* Base URL for Weaviate Embeddings Service. This can be omitted when connecting
65+
* to a Weaviate Cloud instance: the client will automatically set the necessary
66+
* headers.
67+
*/
5268
public Builder inferenceUrl(String inferenceUrl) {
5369
this.inferenceUrl = inferenceUrl;
5470
return this;
5571
}
5672

73+
/** Set target dimensionality for generated embeddings. */
5774
public Builder dimensions(int dimensions) {
5875
this.dimensions = dimensions;
5976
return this;
6077
}
6178

79+
/**
80+
* Select the embedding model.
81+
*
82+
* @see {@link Text2VecWeaviateVectorizer#SNOWFLAKE_ARCTIC_EMBED_M_15},
83+
* {@link Text2VecWeaviateVectorizer#SNOWFLAKE_ARCTIC_EMBED_L_20}
84+
*/
6285
public Builder model(String model) {
6386
this.model = model;
6487
return this;
6588
}
6689

90+
/** Add properties to include in the embedding. */
91+
public Builder sourceProperties(String... properties) {
92+
return sourceProperties(Arrays.asList(properties));
93+
}
94+
95+
/** Add properties to include in the embedding. */
96+
public Builder sourceProperties(List<String> properties) {
97+
this.sourceProperties.addAll(properties);
98+
return this;
99+
}
100+
101+
/**
102+
* Override default vector index configuration.
103+
*
104+
* <a href=
105+
* "https://docs.weaviate.io/weaviate/config-refs/indexing/vector-index#hnsw-index-parameters">HNSW</a>
106+
* is the default vector index.
107+
*/
67108
public Builder vectorIndex(VectorIndex vectorIndex) {
68109
this.vectorIndex = vectorIndex;
69110
return this;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public static Object[][] testCases() {
101101
"vectorIndexConfig": {},
102102
"vectorizer": {
103103
"text2vec-contextionary": {
104-
"vectorizeClassName": false
104+
"vectorizeClassName": false,
105+
"sourceProperties": []
105106
}
106107
}
107108
}
@@ -121,7 +122,9 @@ public static Object[][] testCases() {
121122
"text2vec-weaviate": {
122123
"baseUrl": "http://example.com",
123124
"dimensions": 4,
124-
"model": "very-good-model"
125+
"model": "very-good-model",
126+
"sourceProperties": []
127+
125128
}
126129
}
127130
}

0 commit comments

Comments
 (0)