Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions src/it/java/io/weaviate/integration/AggregationITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import io.weaviate.ConcurrentTest;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.Vectorizer;
import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.api.collections.aggregate.AggregateResponseGroup;
import io.weaviate.client6.v1.api.collections.aggregate.AggregateResponseGrouped;
import io.weaviate.client6.v1.api.collections.aggregate.Aggregation;
import io.weaviate.client6.v1.api.collections.aggregate.GroupBy;
import io.weaviate.client6.v1.api.collections.aggregate.GroupedBy;
import io.weaviate.client6.v1.api.collections.aggregate.IntegerAggregation;
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
import io.weaviate.containers.Container;

public class AggregationITest extends ConcurrentTest {
Expand All @@ -36,7 +35,7 @@ public static void beforeAll() throws IOException {
.properties(
Property.text("category"),
Property.integer("price"))
.vector(Hnsw.of(new NoneVectorizer())));
.vectors(Vectorizer.none()));

var things = client.collections.use(COLLECTION);
for (var category : List.of("Shoes", "Hat", "Jacket")) {
Expand Down
3 changes: 2 additions & 1 deletion src/it/java/io/weaviate/integration/CollectionsITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.VectorIndex;
import io.weaviate.client6.v1.api.collections.Vectorizer;
import io.weaviate.client6.v1.api.collections.WeaviateCollection;
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
Expand All @@ -24,7 +25,7 @@ public void testCreateGetDelete() throws IOException {
client.collections.create(collectionName,
col -> col
.properties(Property.text("username"), Property.integer("age"))
.vector(Hnsw.of(new NoneVectorizer())));
.vectors(Vectorizer.none()));

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

Expand Down
5 changes: 2 additions & 3 deletions src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import io.weaviate.ConcurrentTest;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.Vectorizer;
import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.query.Metadata;
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
import io.weaviate.containers.Container;

public class DataITest extends ConcurrentTest {
Expand Down Expand Up @@ -99,6 +98,6 @@ private static void createTestCollections() throws IOException {
Property.integer("age"))
.references(
Property.reference("hasAwards", awardsGrammy, awardsOscar))
.vectors(named -> named.vector(VECTOR_INDEX, Hnsw.of(new NoneVectorizer()))));
.vectors(Vectorizer.none(VECTOR_INDEX)));
}
}
20 changes: 8 additions & 12 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.weaviate.ConcurrentTest;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.Vectorizer;
import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.data.Reference;
Expand All @@ -25,10 +26,6 @@
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup;
import io.weaviate.client6.v1.api.collections.query.Where;
import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw;
import io.weaviate.client6.v1.api.collections.vectorizers.Img2VecNeuralVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Text2VecContextionaryVectorizer;
import io.weaviate.containers.Container;
import io.weaviate.containers.Container.ContainerGroup;
import io.weaviate.containers.Contextionary;
Expand Down Expand Up @@ -131,7 +128,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"))
.vector(VECTOR_INDEX, Hnsw.of(new NoneVectorizer())));
.vectors(Vectorizer.none(VECTOR_INDEX)));
}

@Test
Expand All @@ -140,7 +137,7 @@ public void testNearText() throws IOException {
client.collections.create(nsSongs,
col -> col
.properties(Property.text("title"))
.vector(Hnsw.of(Text2VecContextionaryVectorizer.of())));
.vectors(Vectorizer.text2VecContextionary()));

var songs = client.collections.use(nsSongs);
var submarine = songs.data.insert(Map.of("title", "Yellow Submarine"));
Expand All @@ -162,13 +159,13 @@ public void testNearText() throws IOException {

@Test
public void testNearText_groupBy() throws IOException {
var vectorIndex = Hnsw.of(Text2VecContextionaryVectorizer.of());
var vectorIndex = Vectorizer.text2VecContextionary();

var nsArtists = ns("Artists");
client.collections.create(nsArtists,
col -> col
.properties(Property.text("name"))
.vector(vectorIndex));
.vectors(vectorIndex));

var artists = client.collections.use(nsArtists);
var beatles = artists.data.insert(Map.of("name", "Beatles"));
Expand All @@ -179,7 +176,7 @@ public void testNearText_groupBy() throws IOException {
col -> col
.properties(Property.text("title"))
.references(Property.reference("performedBy", nsArtists))
.vector(vectorIndex));
.vectors(vectorIndex));

var songs = client.collections.use(nsSongs);
songs.data.insert(Map.of("title", "Yellow Submarine"),
Expand All @@ -206,9 +203,8 @@ public void testNearImage() throws IOException {
.properties(
Property.text("breed"),
Property.blob("img"))
.vector(Hnsw.of(
Img2VecNeuralVectorizer.of(
i2v -> i2v.imageFields("img")))));
.vectors(Vectorizer.img2vecNeural(
i2v -> i2v.imageFields("img"))));

var cats = client.collections.use(nsCats);
cats.data.insert(Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.Function;

import com.google.gson.Gson;
import com.google.gson.JsonParser;
Expand All @@ -18,6 +19,7 @@
import io.weaviate.client6.v1.internal.json.JsonEnum;

public interface VectorIndex {
static final Function<Vectorizer, VectorIndex> DEFAULT_VECTOR_INDEX = Hnsw::of;
static final String DEFAULT_VECTOR_NAME = "default";

public enum Kind implements JsonEnum<Kind> {
Expand Down Expand Up @@ -80,7 +82,8 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
}

final var vectorizerAdapter = gson.getDelegateAdapter(this, TypeToken.get(Vectorizer.class));
final var writeAdapter = gson.getDelegateAdapter(this, TypeToken.get(rawType));
// final var writeAdapter = gson.getDelegateAdapter(this,
// TypeToken.get(rawType));
return (TypeAdapter<T>) new TypeAdapter<VectorIndex>() {

@Override
Expand All @@ -89,10 +92,13 @@ public void write(JsonWriter out, VectorIndex value) throws IOException {
out.name("vectorIndexType");
out.value(value._kind().jsonValue());

var config = writeAdapter.toJsonTree((T) value.config());
config.getAsJsonObject().remove("vectorizer");
out.name("vectorIndexConfig");
Streams.write(config, out);
var adapter = (TypeAdapter<T>) readAdapters.get(value._kind());
if (adapter != null) {
var config = adapter.toJsonTree((T) value.config());
config.getAsJsonObject().remove("vectorizer");
out.name("vectorIndexConfig");
Streams.write(config, out);
}

out.name("vectorizer");
vectorizerAdapter.write(out, value.vectorizer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
Expand All @@ -12,11 +14,13 @@
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import io.weaviate.client6.v1.api.collections.vectorindex.WrappedVectorIndex;
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.Text2VecContextionaryVectorizer;
import io.weaviate.client6.v1.api.collections.vectorizers.Text2VecWeaviateVectorizer;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.json.JsonEnum;

public interface Vectorizer {
Expand Down Expand Up @@ -48,6 +52,99 @@ public static Kind valueOfJson(String jsonValue) {

Object _self();

public static Map.Entry<String, VectorIndex> none() {
return buildVectorIndex(VectorIndex.DEFAULT_VECTOR_NAME, new NoneVectorizer.Builder(), ObjectBuilder.identity());
}

public static Map.Entry<String, VectorIndex> none(
Function<NoneVectorizer.Builder, ObjectBuilder<NoneVectorizer>> fn) {
return buildVectorIndex(VectorIndex.DEFAULT_VECTOR_NAME, new NoneVectorizer.Builder(), ObjectBuilder.identity());
}

public static Map.Entry<String, VectorIndex> none(String vectorName,
Function<NoneVectorizer.Builder, ObjectBuilder<NoneVectorizer>> fn) {
return buildVectorIndex(vectorName, new NoneVectorizer.Builder(), ObjectBuilder.identity());
}

public static Map.Entry<String, VectorIndex> text2vecWeaviate() {
return Map.entry(VectorIndex.DEFAULT_VECTOR_NAME,
VectorIndex.DEFAULT_VECTOR_INDEX.apply(Text2VecWeaviateVectorizer.of()));
}

public static Map.Entry<String, VectorIndex> text2vecWeaviate(
Function<Text2VecWeaviateVectorizer.Builder, ObjectBuilder<Text2VecWeaviateVectorizer>> fn) {
return Map.entry(VectorIndex.DEFAULT_VECTOR_NAME,
VectorIndex.DEFAULT_VECTOR_INDEX.apply(Text2VecWeaviateVectorizer.of(fn)));
}

public static Map.Entry<String, VectorIndex> text2vecWeaviate(String vectorName,
Function<Text2VecWeaviateVectorizer.Builder, ObjectBuilder<Text2VecWeaviateVectorizer>> fn) {
return Map.entry(vectorName,
VectorIndex.DEFAULT_VECTOR_INDEX.apply(Text2VecWeaviateVectorizer.of(fn)));
}

public static Map.Entry<String, VectorIndex> text2VecContextionary() {
return Map.entry(VectorIndex.DEFAULT_VECTOR_NAME,
VectorIndex.DEFAULT_VECTOR_INDEX.apply(Text2VecContextionaryVectorizer.of()));
}

public static Map.Entry<String, VectorIndex> text2VecContextionary(
Function<Text2VecContextionaryVectorizer.Builder, ObjectBuilder<Text2VecContextionaryVectorizer>> fn) {
return Map.entry(VectorIndex.DEFAULT_VECTOR_NAME,
VectorIndex.DEFAULT_VECTOR_INDEX.apply(Text2VecContextionaryVectorizer.of(fn)));
}

public static Map.Entry<String, VectorIndex> text2VecContextionary(String vectorName,
Function<Text2VecContextionaryVectorizer.Builder, ObjectBuilder<Text2VecContextionaryVectorizer>> fn) {
return Map.entry(vectorName,
VectorIndex.DEFAULT_VECTOR_INDEX.apply(Text2VecContextionaryVectorizer.of(fn)));
}

public static <B, I extends VectorIndex> Map.Entry<String, VectorIndex> text2VecContextionary(
BiFunction<Vectorizer, Function<B, ObjectBuilder<I>>, VectorIndex> ctor,
Function<Text2VecContextionaryVectorizer.Builder, ObjectBuilder<Text2VecContextionaryVectorizer>> fnVectorizer,
Function<B, ObjectBuilder<I>> fnIndex) {
return Map.entry("default", ctor.apply(null, null));
}

public static Map.Entry<String, VectorIndex> multi2vecClip() {
return buildVectorIndex(VectorIndex.DEFAULT_VECTOR_NAME, new Multi2VecClipVectorizer.Builder(),
ObjectBuilder.identity());
}

public static Map.Entry<String, VectorIndex> multi2vecClip(
Function<Multi2VecClipVectorizer.Builder, ObjectBuilder<Multi2VecClipVectorizer>> fn) {
return buildVectorIndex(VectorIndex.DEFAULT_VECTOR_NAME, new Multi2VecClipVectorizer.Builder(), fn);
}

public static Map.Entry<String, VectorIndex> multi2vecClip(String vectorName,
Function<Multi2VecClipVectorizer.Builder, ObjectBuilder<Multi2VecClipVectorizer>> fn) {
return buildVectorIndex(vectorName, new Multi2VecClipVectorizer.Builder(), fn);
}

public static Map.Entry<String, VectorIndex> img2vecNeural() {
return buildVectorIndex(VectorIndex.DEFAULT_VECTOR_NAME, new Img2VecNeuralVectorizer.Builder(),
ObjectBuilder.identity());
}

public static Map.Entry<String, VectorIndex> img2vecNeural(
Function<Img2VecNeuralVectorizer.Builder, ObjectBuilder<Img2VecNeuralVectorizer>> fn) {
return buildVectorIndex(VectorIndex.DEFAULT_VECTOR_NAME, new Img2VecNeuralVectorizer.Builder(), fn);
}

public static Map.Entry<String, VectorIndex> img2vecNeural(String vectorName,
Function<Img2VecNeuralVectorizer.Builder, ObjectBuilder<Img2VecNeuralVectorizer>> fn) {
return buildVectorIndex(vectorName, new Img2VecNeuralVectorizer.Builder(), fn);
}

private static <B extends WrappedVectorIndex.Builder<B, V>, V extends Vectorizer> Map.Entry<String, VectorIndex> buildVectorIndex(
String key,
B builder, Function<B, ObjectBuilder<V>> fn) {
@SuppressWarnings("unchecked")
B b = (B) fn.apply(builder);
return Map.entry(key, b.buildVectorIndex());
}

public static enum CustomTypeAdapterFactory implements TypeAdapterFactory {
INSTANCE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,29 @@ public Builder references(List<ReferenceProperty> references) {
return this;
}

public Builder vector(VectorIndex vector) {
this.vectors.put(VectorIndex.DEFAULT_VECTOR_NAME, vector);
return this;
}

public Builder vector(String name, VectorIndex vector) {
this.vectors.put(name, vector);
@SafeVarargs
public final Builder vectors(Map.Entry<String, VectorIndex>... vectors) {
for (final var vector : vectors) {
this.vectors.put(vector.getKey(), vector.getValue());
}
return this;
}

public Builder vectors(Function<VectorsBuilder, ObjectBuilder<Map<String, VectorIndex>>> fn) {
this.vectors = fn.apply(new VectorsBuilder()).build();
return this;
}
// public Builder vector(VectorIndex vector) {
// this.vectors.put(VectorIndex.DEFAULT_VECTOR_NAME, vector);
// return this;
// }
//
// public Builder vector(String name, VectorIndex vector) {
// this.vectors.put(name, vector);
// return this;
// }
//
// public Builder vectors(Function<VectorsBuilder, ObjectBuilder<Map<String,
// VectorIndex>>> fn) {
// this.vectors = fn.apply(new VectorsBuilder()).build();
// return this;
// }

public static class VectorsBuilder implements ObjectBuilder<Map<String, VectorIndex>> {
private Map<String, VectorIndex> vectors = new HashMap<>();
Expand Down
Loading
Loading