|
| 1 | +package io.weaviate.client6.v1.api.collections.vectorizers; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Arrays; |
| 5 | +import java.util.List; |
| 6 | +import java.util.function.Function; |
| 7 | + |
| 8 | +import com.google.gson.annotations.SerializedName; |
| 9 | + |
| 10 | +import io.weaviate.client6.v1.api.collections.Quantization; |
| 11 | +import io.weaviate.client6.v1.api.collections.VectorConfig; |
| 12 | +import io.weaviate.client6.v1.api.collections.VectorIndex; |
| 13 | +import io.weaviate.client6.v1.internal.ObjectBuilder; |
| 14 | + |
| 15 | +public record Multi2VecTwelveLabsVectorizer( |
| 16 | + /** Base URL of the embedding service. */ |
| 17 | + @SerializedName("baseURL") String baseUrl, |
| 18 | + /** Inference model to use. */ |
| 19 | + @SerializedName("model") String model, |
| 20 | + /** BLOB properties included in the embedding. */ |
| 21 | + @SerializedName("imageFields") List<String> imageFields, |
| 22 | + /** TEXT properties included in the embedding. */ |
| 23 | + @SerializedName("textFields") List<String> textFields, |
| 24 | + /** Weights of the included properties. */ |
| 25 | + @SerializedName("weights") Weights weights, |
| 26 | + /** Vector index configuration. */ |
| 27 | + VectorIndex vectorIndex, |
| 28 | + /** Vector quantization method. */ |
| 29 | + Quantization quantization) implements VectorConfig { |
| 30 | + |
| 31 | + private static record Weights( |
| 32 | + /** |
| 33 | + * Weights of the BLOB properties. Values appear in the same order as the |
| 34 | + * corresponding property names in {@code imageFields}. |
| 35 | + */ |
| 36 | + @SerializedName("imageWeights") List<Float> imageWeights, |
| 37 | + /** |
| 38 | + * Weights of the TEXT properties. Values appear in the same order as the |
| 39 | + * corresponding property names in {@code textFields}. |
| 40 | + */ |
| 41 | + @SerializedName("textWeights") List<Float> textWeights) { |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public VectorConfig.Kind _kind() { |
| 46 | + return VectorConfig.Kind.MULTI2VEC_JINAAI; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public Object _self() { |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | + public static final String MARENGO30 = "marengo3.0"; |
| 55 | + |
| 56 | + public static Multi2VecTwelveLabsVectorizer of() { |
| 57 | + return of(ObjectBuilder.identity()); |
| 58 | + } |
| 59 | + |
| 60 | + public static Multi2VecTwelveLabsVectorizer of(Function<Builder, ObjectBuilder<Multi2VecTwelveLabsVectorizer>> fn) { |
| 61 | + return fn.apply(new Builder()).build(); |
| 62 | + } |
| 63 | + |
| 64 | + public Multi2VecTwelveLabsVectorizer( |
| 65 | + String baseUrl, |
| 66 | + String model, |
| 67 | + List<String> imageFields, |
| 68 | + List<String> textFields, |
| 69 | + Weights weights, |
| 70 | + VectorIndex vectorIndex, |
| 71 | + Quantization quantization) { |
| 72 | + this.baseUrl = baseUrl; |
| 73 | + this.model = model; |
| 74 | + this.imageFields = imageFields; |
| 75 | + this.textFields = textFields; |
| 76 | + this.weights = weights; |
| 77 | + this.vectorIndex = vectorIndex; |
| 78 | + this.quantization = quantization; |
| 79 | + } |
| 80 | + |
| 81 | + public Multi2VecTwelveLabsVectorizer(Builder builder) { |
| 82 | + this( |
| 83 | + builder.baseUrl, |
| 84 | + builder.model, |
| 85 | + builder.imageFields, |
| 86 | + builder.textFields, |
| 87 | + builder.getWeights(), |
| 88 | + builder.vectorIndex, |
| 89 | + builder.quantization); |
| 90 | + } |
| 91 | + |
| 92 | + public static class Builder implements ObjectBuilder<Multi2VecTwelveLabsVectorizer> { |
| 93 | + private VectorIndex vectorIndex = VectorIndex.DEFAULT_VECTOR_INDEX; |
| 94 | + private Quantization quantization; |
| 95 | + |
| 96 | + private List<String> imageFields; |
| 97 | + private List<Float> imageWeights; |
| 98 | + private List<String> textFields; |
| 99 | + private List<Float> textWeights; |
| 100 | + |
| 101 | + private String baseUrl; |
| 102 | + private String model; |
| 103 | + |
| 104 | + /** Set base URL of the embedding service. */ |
| 105 | + public Builder baseUrl(String baseUrl) { |
| 106 | + this.baseUrl = baseUrl; |
| 107 | + return this; |
| 108 | + } |
| 109 | + |
| 110 | + public Builder model(String model) { |
| 111 | + this.model = model; |
| 112 | + return this; |
| 113 | + } |
| 114 | + |
| 115 | + /** Add BLOB properties to include in the embedding. */ |
| 116 | + public Builder imageFields(List<String> fields) { |
| 117 | + this.imageFields = fields; |
| 118 | + return this; |
| 119 | + } |
| 120 | + |
| 121 | + /** Add BLOB properties to include in the embedding. */ |
| 122 | + public Builder imageFields(String... fields) { |
| 123 | + return imageFields(Arrays.asList(fields)); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Add BLOB property to include in the embedding. |
| 128 | + * |
| 129 | + * @param field Property name. |
| 130 | + * @param weight Custom weight between 0.0 and 1.0. |
| 131 | + */ |
| 132 | + public Builder imageField(String field, float weight) { |
| 133 | + if (this.imageFields == null) { |
| 134 | + this.imageFields = new ArrayList<>(); |
| 135 | + } |
| 136 | + if (this.imageWeights == null) { |
| 137 | + this.imageWeights = new ArrayList<>(); |
| 138 | + } |
| 139 | + this.imageFields.add(field); |
| 140 | + this.imageWeights.add(weight); |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + /** Add TEXT properties to include in the embedding. */ |
| 145 | + public Builder textFields(List<String> fields) { |
| 146 | + this.textFields = fields; |
| 147 | + return this; |
| 148 | + } |
| 149 | + |
| 150 | + /** Add TEXT properties to include in the embedding. */ |
| 151 | + public Builder textFields(String... fields) { |
| 152 | + return textFields(Arrays.asList(fields)); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Add TEXT property to include in the embedding. |
| 157 | + * |
| 158 | + * @param field Property name. |
| 159 | + * @param weight Custom weight between 0.0 and 1.0. |
| 160 | + */ |
| 161 | + public Builder textField(String field, float weight) { |
| 162 | + if (this.textFields == null) { |
| 163 | + this.textFields = new ArrayList<>(); |
| 164 | + } |
| 165 | + if (this.textWeights == null) { |
| 166 | + this.textWeights = new ArrayList<>(); |
| 167 | + } |
| 168 | + this.textFields.add(field); |
| 169 | + this.textWeights.add(weight); |
| 170 | + return this; |
| 171 | + } |
| 172 | + |
| 173 | + protected Weights getWeights() { |
| 174 | + if (this.textWeights != null || this.imageWeights != null) { |
| 175 | + return new Weights(this.imageWeights, this.textWeights); |
| 176 | + } |
| 177 | + return null; |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Override default vector index configuration. |
| 182 | + * |
| 183 | + * <a href= |
| 184 | + * "https://docs.weaviate.io/weaviate/config-refs/indexing/vector-index#hnsw-index-parameters">HNSW</a> |
| 185 | + * is the default vector index. |
| 186 | + */ |
| 187 | + public Builder vectorIndex(VectorIndex vectorIndex) { |
| 188 | + this.vectorIndex = vectorIndex; |
| 189 | + return this; |
| 190 | + } |
| 191 | + |
| 192 | + public Builder quantization(Quantization quantization) { |
| 193 | + this.quantization = quantization; |
| 194 | + return this; |
| 195 | + } |
| 196 | + |
| 197 | + @Override |
| 198 | + public Multi2VecTwelveLabsVectorizer build() { |
| 199 | + return new Multi2VecTwelveLabsVectorizer(this); |
| 200 | + } |
| 201 | + } |
| 202 | +} |
0 commit comments