Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/it/java/io/weaviate/integration/AggregationITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void beforeAll() throws IOException {
.properties(
Property.text("category"),
Property.integer("price"))
.vectors(Vectorizers.none()));
.vectors(Vectorizers.selfProvided()));

var things = client.collections.use(COLLECTION);
for (var category : List.of("Shoes", "Hat", "Jacket")) {
Expand Down
6 changes: 3 additions & 3 deletions src/it/java/io/weaviate/integration/CollectionsITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.weaviate.client6.v1.api.collections.config.Shard;
import io.weaviate.client6.v1.api.collections.config.ShardStatus;
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.SelfProvidedVectorizer;
import io.weaviate.containers.Container;

public class CollectionsITest extends ConcurrentTest {
Expand All @@ -30,7 +30,7 @@ public void testCreateGetDelete() throws IOException {
client.collections.create(collectionName,
col -> col
.properties(Property.text("username"), Property.integer("age"))
.vectors(Vectorizers.none()));
.vectors(Vectorizers.selfProvided()));

var thingsCollection = client.collections.getConfig(collectionName);

Expand All @@ -40,7 +40,7 @@ public void testCreateGetDelete() throws IOException {
.as("default vector").extractingByKey("default")
.satisfies(defaultVector -> {
Assertions.assertThat(defaultVector)
.as("has none vectorizer").isInstanceOf(NoneVectorizer.class);
.as("has none vectorizer").isInstanceOf(SelfProvidedVectorizer.class);
Assertions.assertThat(defaultVector).extracting(Vectorizer::vectorIndex)
.isInstanceOf(Hnsw.class);
});
Expand Down
4 changes: 2 additions & 2 deletions src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static void createTestCollections() throws IOException {
Property.integer("age"))
.references(
Property.reference("hasAwards", awardsGrammy, awardsOscar))
.vectors(Vectorizers.none(VECTOR_INDEX)));
.vectors(Vectorizers.selfProvided(VECTOR_INDEX)));
}

@Test
Expand Down Expand Up @@ -233,7 +233,7 @@ public void testUpdate() throws IOException {
collection -> collection
.properties(Property.text("title"), Property.integer("year"))
.references(Property.reference("writtenBy", nsAuthors))
.vectors(Vectorizers.none()));
.vectors(Vectorizers.selfProvided()));

var authors = client.collections.use(nsAuthors);
var walter = authors.data.insert(Map.of("name", "walter scott"));
Expand Down
2 changes: 1 addition & 1 deletion src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static Map<String, float[]> populateTest(int n) throws IOException {
private static void createTestCollection() throws IOException {
client.collections.create(COLLECTION, cfg -> cfg
.properties(Property.text("category"))
.vectors(Vectorizers.none(VECTOR_INDEX)));
.vectors(Vectorizers.selfProvided(VECTOR_INDEX)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import io.weaviate.client6.v1.api.collections.vectorizers.Img2VecNeuralVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Multi2VecClipVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.SelfProvidedVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Text2VecContextionaryVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Text2VecWeaviateVectorizer;
import io.weaviate.client6.v1.internal.json.JsonEnum;
Expand Down Expand Up @@ -63,7 +63,7 @@ private final void addAdapter(Gson gson, Vectorizer.Kind kind, Class<? extends V
}

private final void init(Gson gson) {
addAdapter(gson, Vectorizer.Kind.NONE, NoneVectorizer.class);
addAdapter(gson, Vectorizer.Kind.NONE, SelfProvidedVectorizer.class);
addAdapter(gson, Vectorizer.Kind.IMG2VEC_NEURAL, Img2VecNeuralVectorizer.class);
addAdapter(gson, Vectorizer.Kind.MULTI2VEC_CLIP, Multi2VecClipVectorizer.class);
addAdapter(gson, Vectorizer.Kind.TEXT2VEC_WEAVIATE, Text2VecWeaviateVectorizer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,172 @@

import io.weaviate.client6.v1.api.collections.vectorizers.Img2VecNeuralVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Multi2VecClipVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.SelfProvidedVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Text2VecContextionaryVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Text2VecWeaviateVectorizer;
import io.weaviate.client6.v1.internal.ObjectBuilder;

/** Static methods for creating instances of {@link Vectorizer}. */
/** Static factories for creating instances of {@link Vectorizer}. */
public final class Vectorizers {
/** Prevent public initialization. */
private Vectorizers() {
}

public static Map.Entry<String, Vectorizer> none() {
return none(VectorIndex.DEFAULT_VECTOR_NAME);
public static Map.Entry<String, Vectorizer> selfProvided() {
return selfProvided(VectorIndex.DEFAULT_VECTOR_NAME);
}

public static Map.Entry<String, Vectorizer> none(
Function<NoneVectorizer.Builder, ObjectBuilder<NoneVectorizer>> fn) {
return none(VectorIndex.DEFAULT_VECTOR_NAME, fn);
public static Map.Entry<String, Vectorizer> selfProvided(
Function<SelfProvidedVectorizer.Builder, ObjectBuilder<SelfProvidedVectorizer>> fn) {
return selfProvided(VectorIndex.DEFAULT_VECTOR_NAME, fn);
}

public static Map.Entry<String, Vectorizer> none(String vectorName) {
return Map.entry(vectorName, NoneVectorizer.of());
public static Map.Entry<String, Vectorizer> selfProvided(String vectorName) {
return Map.entry(vectorName, SelfProvidedVectorizer.of());
}

public static Map.Entry<String, Vectorizer> none(String vectorName,
Function<NoneVectorizer.Builder, ObjectBuilder<NoneVectorizer>> fn) {
return Map.entry(vectorName, NoneVectorizer.of(fn));
public static Map.Entry<String, Vectorizer> selfProvided(String vectorName,
Function<SelfProvidedVectorizer.Builder, ObjectBuilder<SelfProvidedVectorizer>> fn) {
return Map.entry(vectorName, SelfProvidedVectorizer.of(fn));
}

/** Create a vector index with an {@code img2vec-neural} vectorizer. */
public static Map.Entry<String, Vectorizer> img2vecNeural() {
return img2vecNeural(VectorIndex.DEFAULT_VECTOR_NAME);
}

/**
* Create a vector index with an {@code img2vec-neural} vectorizer.
*
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> img2vecNeural(
Function<Img2VecNeuralVectorizer.Builder, ObjectBuilder<Img2VecNeuralVectorizer>> fn) {
return img2vecNeural(VectorIndex.DEFAULT_VECTOR_NAME, fn);
}

/**
* Create a named vector index with an {@code img2vec-neural} vectorizer.
*
* @param vectorName Vector name.
*/
public static Map.Entry<String, Vectorizer> img2vecNeural(String vectorName) {
return Map.entry(vectorName, Img2VecNeuralVectorizer.of());
}

/**
* Create a vector index with an {@code img2vec-neural} vectorizer.
*
* @param vectorName Vector name.
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> img2vecNeural(String vectorName,
Function<Img2VecNeuralVectorizer.Builder, ObjectBuilder<Img2VecNeuralVectorizer>> fn) {
return Map.entry(vectorName, Img2VecNeuralVectorizer.of(fn));
}

/** Create a vector index with an {@code multi2vec-clip} vectorizer. */
public static Map.Entry<String, Vectorizer> multi2vecClip() {
return multi2vecClip(VectorIndex.DEFAULT_VECTOR_NAME);
}

/**
* Create a vector index with an {@code multi2vec-clip} vectorizer.
*
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> multi2vecClip(
Function<Multi2VecClipVectorizer.Builder, ObjectBuilder<Multi2VecClipVectorizer>> fn) {
return multi2vecClip(VectorIndex.DEFAULT_VECTOR_NAME, fn);
}

/**
* Create a named vector index with an {@code multi2vec-clip} vectorizer.
*
* @param vectorName Vector name.
*/
public static Map.Entry<String, Vectorizer> multi2vecClip(String vectorName) {
return Map.entry(vectorName, Multi2VecClipVectorizer.of());
}

/**
* Create a named vector index with an {@code multi2vec-clip} vectorizer.
*
* @param vectorName Vector name.
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> multi2vecClip(String vectorName,
Function<Multi2VecClipVectorizer.Builder, ObjectBuilder<Multi2VecClipVectorizer>> fn) {
return Map.entry(vectorName, Multi2VecClipVectorizer.of(fn));
}

/** Create a vector index with an {@code text2vec-contextionary} vectorizer. */
public static Map.Entry<String, Vectorizer> text2vecContextionary() {
return text2vecContextionary(VectorIndex.DEFAULT_VECTOR_NAME);
}

/**
* Create a vector index with an {@code text2vec-contextionary} vectorizer.
*
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> text2vecContextionary(
Function<Text2VecContextionaryVectorizer.Builder, ObjectBuilder<Text2VecContextionaryVectorizer>> fn) {
return text2vecContextionary(VectorIndex.DEFAULT_VECTOR_NAME, fn);
}

/**
* Create a named vector index with an {@code text2vec-contextionary}
* vectorizer.
*
* @param vectorName Vector name.
*/
public static Map.Entry<String, Vectorizer> text2vecContextionary(String vectorName) {
return Map.entry(vectorName, Text2VecContextionaryVectorizer.of());
}

/**
* Create a named vector index with an {@code text2vec-contextionary}
* vectorizer.
*
* @param vectorName Vector name.
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> text2vecContextionary(String vectorName,
Function<Text2VecContextionaryVectorizer.Builder, ObjectBuilder<Text2VecContextionaryVectorizer>> fn) {
return Map.entry(vectorName, Text2VecContextionaryVectorizer.of(fn));
}

/** Create a vector index with an {@code text2vec-weaviate} vectorizer. */
public static Map.Entry<String, Vectorizer> text2VecWeaviate() {
return text2VecWeaviate(VectorIndex.DEFAULT_VECTOR_NAME);
}

/**
* Create a vector index with an {@code text2vec-weaviate} vectorizer.
*
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> text2VecWeaviate(
Function<Text2VecWeaviateVectorizer.Builder, ObjectBuilder<Text2VecWeaviateVectorizer>> fn) {
return text2VecWeaviate(VectorIndex.DEFAULT_VECTOR_NAME, fn);
}

/**
* Create a named vector index with an {@code text2vec-weaviate} vectorizer.
*
* @param vectorName Vector name.
*/
public static Map.Entry<String, Vectorizer> text2VecWeaviate(String vectorName) {
return Map.entry(vectorName, Text2VecWeaviateVectorizer.of());
}

/**
* Create a named vector index with an {@code text2vec-weaviate} vectorizer.
*
* @param vectorName Vector name.
* @param fn Lambda expression for optional parameters.
*/
public static Map.Entry<String, Vectorizer> text2VecWeaviate(String vectorName,
Function<Text2VecWeaviateVectorizer.Builder, ObjectBuilder<Text2VecWeaviateVectorizer>> fn) {
return Map.entry(vectorName, Text2VecWeaviateVectorizer.of(fn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import io.weaviate.client6.v1.internal.ObjectBuilder;

public record Img2VecNeuralVectorizer(
/** BLOB properties included in the embedding. */
@SerializedName("imageFields") List<String> imageFields,
/** Vector index configuration. */
VectorIndex vectorIndex) implements Vectorizer {

@Override
Expand Down Expand Up @@ -41,15 +43,24 @@ public static class Builder implements ObjectBuilder<Img2VecNeuralVectorizer> {
private VectorIndex vectorIndex = VectorIndex.DEFAULT_VECTOR_INDEX;
private List<String> imageFields = new ArrayList<>();

/** Add BLOB properties to include in the embedding. */
public Builder imageFields(List<String> fields) {
this.imageFields = fields;
return this;
}

/** Add BLOB properties to include in the embedding. */
public Builder imageFields(String... fields) {
return imageFields(Arrays.asList(fields));
}

/**
* Override default vector index configuration.
*
* <a href=
* "https://docs.weaviate.io/weaviate/config-refs/indexing/vector-index#hnsw-index-parameters">HNSW</a>
* is the default vector index.
*/
public Builder vectorIndex(VectorIndex vectorIndex) {
this.vectorIndex = vectorIndex;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@
import io.weaviate.client6.v1.internal.ObjectBuilder;

public record Multi2VecClipVectorizer(
/** Base URL of the embedding service. */
@SerializedName("inferenceUrl") String inferenceUrl,
/** BLOB properties included in the embedding. */
@SerializedName("imageFields") List<String> imageFields,
/** TEXT properties included in the embedding. */
@SerializedName("textFields") List<String> textFields,
/** Weights of the included properties. */
@SerializedName("weights") Weights weights,
/** Vector index configuration. */
VectorIndex vectorIndex) implements Vectorizer {

private static record Weights(
/**
* Weights of the BLOB properties. Values appear in the same order as the
* corresponding property names in {@code imageFields}.
*/
@SerializedName("imageWeights") List<Float> imageWeights,
/**
* Weights of the TEXT properties. Values appear in the same order as the
* corresponding property names in {@code textFields}.
*/
@SerializedName("textWeights") List<Float> textWeights) {
}

Expand Down Expand Up @@ -59,39 +72,63 @@ public static class Builder implements ObjectBuilder<Multi2VecClipVectorizer> {
private Map<String, Float> imageFields = new HashMap<>();
private Map<String, Float> textFields = new HashMap<>();

/** Set base URL of the embedding service. */
public Builder inferenceUrl(String inferenceUrl) {
this.inferenceUrl = inferenceUrl;
return this;
}

/** Add BLOB properties to include in the embedding. */
public Builder imageFields(List<String> fields) {
fields.forEach(field -> imageFields.put(field, null));
return this;
}

/** Add BLOB properties to include in the embedding. */
public Builder imageFields(String... fields) {
return imageFields(Arrays.asList(fields));
}

/**
* Add BLOB property to include in the embedding.
*
* @param field Property name.
* @param weight Custom weight between 0.0 and 1.0.
*/
public Builder imageField(String field, float weight) {
imageFields.put(field, weight);
return this;
}

/** Add TEXT properties to include in the embedding. */
public Builder textFields(List<String> fields) {
fields.forEach(field -> textFields.put(field, null));
return this;
}

/** Add TEXT properties to include in the embedding. */
public Builder textFields(String... fields) {
return textFields(Arrays.asList(fields));
}

/**
* Add TEXT property to include in the embedding.
*
* @param field Property name.
* @param weight Custom weight between 0.0 and 1.0.
*/
public Builder textField(String field, float weight) {
textFields.put(field, weight);
return this;
}

/**
* Override default vector index configuration.
*
* <a href=
* "https://docs.weaviate.io/weaviate/config-refs/indexing/vector-index#hnsw-index-parameters">HNSW</a>
* is the default vector index.
*/
public Builder vectorIndex(VectorIndex vectorIndex) {
this.vectorIndex = vectorIndex;
return this;
Expand Down
Loading