Skip to content

v6: Refactor REST endpoints and JSON de-/serialization #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 12, 2025
Merged
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
2 changes: 1 addition & 1 deletion src/it/java/io/weaviate/containers/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.testcontainers.containers.Network;
import org.testcontainers.lifecycle.Startable;

import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.api.WeaviateClient;
import lombok.RequiredArgsConstructor;

public class Container {
Expand Down
4 changes: 2 additions & 2 deletions src/it/java/io/weaviate/containers/Weaviate.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import org.testcontainers.weaviate.WeaviateContainer;

import io.weaviate.client6.Config;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.api.Config;
import io.weaviate.client6.v1.api.WeaviateClient;

public class Weaviate extends WeaviateContainer {
private WeaviateClient clientInstance;
Expand Down
10 changes: 5 additions & 5 deletions src/it/java/io/weaviate/integration/AggregationITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
import org.junit.Test;

import io.weaviate.ConcurrentTest;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
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.collections.Property;
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.Vectorizer;
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 +36,7 @@ public static void beforeAll() throws IOException {
.properties(
Property.text("category"),
Property.integer("price"))
.vectors(io.weaviate.client6.v1.collections.Vectors.of(new VectorIndex<>(Vectorizer.none()))));
.vector(Hnsw.of(new NoneVectorizer())));

var things = client.collections.use(COLLECTION);
for (var category : List.of("Shoes", "Hat", "Jacket")) {
Expand Down
26 changes: 12 additions & 14 deletions src/it/java/io/weaviate/integration/CollectionsITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
import org.junit.Test;

import io.weaviate.ConcurrentTest;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.collections.Collection;
import io.weaviate.client6.v1.collections.NoneVectorizer;
import io.weaviate.client6.v1.collections.Property;
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.VectorIndex.IndexType;
import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy;
import io.weaviate.client6.v1.collections.Vectorizer;
import io.weaviate.client6.v1.collections.Vectors;
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.WeaviateCollection;
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 CollectionsITest extends ConcurrentTest {
Expand All @@ -27,18 +24,19 @@ public void testCreateGetDelete() throws IOException {
client.collections.create(collectionName,
col -> col
.properties(Property.text("username"), Property.integer("age"))
.vector(new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none())));
.vector(Hnsw.of(new NoneVectorizer())));

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

Assertions.assertThat(thingsCollection).get()
.hasFieldOrPropertyWithValue("name", collectionName)
.extracting(Collection::vectors).extracting(Vectors::getDefault)
.as("default vector").satisfies(defaultVector -> {
.extracting(WeaviateCollection::vectors, InstanceOfAssertFactories.map(String.class, VectorIndex.class))
.as("default vector").extractingByKey("default")
.satisfies(defaultVector -> {
Assertions.assertThat(defaultVector).extracting(VectorIndex::vectorizer)
.as("has none vectorizer").isInstanceOf(NoneVectorizer.class);
Assertions.assertThat(defaultVector).extracting(VectorIndex::configuration)
.as("has hnsw index").returns(IndexType.HNSW, IndexingStrategy::type);
Assertions.assertThat(defaultVector).extracting(VectorIndex::config)
.isInstanceOf(Hnsw.class);
});

client.collections.delete(collectionName);
Expand Down
29 changes: 14 additions & 15 deletions src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import org.junit.Test;

import io.weaviate.ConcurrentTest;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.Vectors;
import io.weaviate.client6.v1.collections.Property;
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy;
import io.weaviate.client6.v1.collections.Vectorizer;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
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 {

private static WeaviateClient client = Container.WEAVIATE.getClient();
private static final String COLLECTION = unique("Artists");
private static final String VECTOR_INDEX = "bring_your_own";
Expand All @@ -34,9 +33,10 @@ public void testCreateGetDelete() throws IOException {
var id = randomUUID();
Float[] vector = { 1f, 2f, 3f };

artists.data.insert(Map.of("name", "john doe"), metadata -> metadata
.id(id)
.vectors(Vectors.of(VECTOR_INDEX, vector)));
artists.data.insert(Map.of("name", "john doe"),
metadata -> metadata
.uuid(id)
.vectors(Vectors.of(VECTOR_INDEX, vector)));

var object = artists.query.byId(id, query -> query
.returnProperties("name")
Expand All @@ -45,11 +45,10 @@ public void testCreateGetDelete() throws IOException {
Assertions.assertThat(object)
.as("object exists after insert").get()
.satisfies(obj -> {
Assertions.assertThat(obj.metadata().id())
Assertions.assertThat(obj.metadata().uuid())
.as("object id").isEqualTo(id);

Assertions.assertThat(obj.metadata().vectors()).extracting(Vectors::getSingle)
.asInstanceOf(InstanceOfAssertFactories.OPTIONAL).as("has single vector").get()
Assertions.assertThat(obj.metadata().vectors()).extracting(v -> v.getSingle(VECTOR_INDEX))
.asInstanceOf(InstanceOfAssertFactories.array(Float[].class)).containsExactly(vector);

Assertions.assertThat(obj.properties())
Expand Down Expand Up @@ -77,11 +76,11 @@ public void testBlobData() throws IOException {
"breed", "ragdoll",
"img", ragdollPng));

var got = cats.query.byId(ragdoll.metadata().id(),
var got = cats.query.byId(ragdoll.metadata().uuid(),
cat -> cat.returnProperties("img"));

Assertions.assertThat(got).get()
.extracting(io.weaviate.client6.v1.api.collections.WeaviateObject::properties, InstanceOfAssertFactories.MAP)
.extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP)
.extractingByKey("img").isEqualTo(ragdollPng);
}

Expand All @@ -99,6 +98,6 @@ private static void createTestCollections() throws IOException {
Property.integer("age"))
.references(
Property.reference("hasAwards", awardsGrammy, awardsOscar))
.vector(VECTOR_INDEX, new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none())));
.vectors(named -> named.vector(VECTOR_INDEX, Hnsw.of(new NoneVectorizer()))));
}
}
48 changes: 28 additions & 20 deletions src/it/java/io/weaviate/integration/ReferencesITest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.weaviate.integration;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand All @@ -9,15 +10,14 @@
import org.junit.Test;

import io.weaviate.ConcurrentTest;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.api.collections.ObjectReference;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.ObjectMetadata;
import io.weaviate.client6.v1.api.collections.Property;
import io.weaviate.client6.v1.api.collections.ReferenceProperty;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.api.collections.data.Reference;
import io.weaviate.client6.v1.api.collections.query.MetadataField;
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
import io.weaviate.client6.v1.api.collections.query.QueryReference;
import io.weaviate.client6.v1.collections.Property;
import io.weaviate.client6.v1.collections.Reference;
import io.weaviate.client6.v1.collections.ReferenceProperty;
import io.weaviate.containers.Container;

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ public void testReferences() throws IOException {
Map.of("name", "Alex"),
opt -> opt
.reference("hasAwards", Reference.uuids(
grammy_1.metadata().id(), oscar_1.metadata().id()))
grammy_1.metadata().uuid(), oscar_1.metadata().uuid()))
.reference("hasAwards", Reference.objects(grammy_2, oscar_2)));

// Act: add one more reference
Expand All @@ -92,7 +92,7 @@ public void testReferences() throws IOException {
.extracting(ReferenceProperty::dataTypes, InstanceOfAssertFactories.list(String.class))
.containsOnly(nsMovies);

var gotAlex = artists.query.byId(alex.metadata().id(),
var gotAlex = artists.query.byId(alex.metadata().uuid(),
opt -> opt.returnReferences(
QueryReference.multi("hasAwards", nsOscar,
ref -> ref.returnMetadata(MetadataField.ID)),
Expand All @@ -101,18 +101,21 @@ public void testReferences() throws IOException {

Assertions.assertThat(gotAlex).get()
.as("Artists: fetch by id including hasAwards references")
.extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, ObjectReference.class))

// Cast references to Map<String, List<WeaviateObject>>
.extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class))
.as("hasAwards object reference").extractingByKey("hasAwards")
.extracting(ObjectReference::objects, InstanceOfAssertFactories.list(WeaviateObject.class))
.extracting(object -> ((QueryMetadata) object.metadata()).id())
.asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class))

.extracting(object -> ((ObjectMetadata) object.metadata()).uuid())
.containsOnly(
// INVESTIGATE: When references to 2+ collections are requested,
// seems to Weaviate only return references to the first one in the list.
// In this case we request { "hasAwards": Oscars } and { "hasAwards": Grammys }
// so the latter will not be in the response.
//
// grammy_1.metadata().id(), grammy_2.metadata().id(),
oscar_1.metadata().id(), oscar_2.metadata().id());
oscar_1.metadata().uuid(), oscar_2.metadata().uuid());
}

@Test
Expand Down Expand Up @@ -155,7 +158,7 @@ public void testNestedReferences() throws IOException {
.reference("hasAwards", Reference.objects(grammy_1)));

// Assert: fetch nested references
var gotAlex = artists.query.byId(alex.metadata().id(),
var gotAlex = artists.query.byId(alex.metadata().uuid(),
opt -> opt.returnReferences(
QueryReference.single("hasAwards",
ref -> ref
Expand All @@ -167,15 +170,20 @@ public void testNestedReferences() throws IOException {

Assertions.assertThat(gotAlex).get()
.as("Artists: fetch by id including nested references")
.extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, ObjectReference.class))

// Cast references to Map<String, List<WeaviateObject>>
.extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class))
.as("hasAwards object reference").extractingByKey("hasAwards")
.extracting(ObjectReference::objects, InstanceOfAssertFactories.list(WeaviateObject.class))
.asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class))

.hasSize(1).allSatisfy(award -> Assertions.assertThat(award)
.returns(grammy_1.metadata().id(), grammy -> ((QueryMetadata) grammy.metadata()).id())
.extracting(WeaviateObject::references,
InstanceOfAssertFactories.map(String.class, ObjectReference.class))
.extractingByKey("presentedBy")
.extracting(ObjectReference::objects, InstanceOfAssertFactories.list(WeaviateObject.class))
.returns(grammy_1.metadata().uuid(), grammy -> ((ObjectMetadata) grammy.metadata()).uuid())

// Cast references to Map<String, List<WeaviateObject>>
.extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class))
.as("presentedBy object reference").extractingByKey("presentedBy")
.asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class))

.hasSize(1).extracting(WeaviateObject::properties)
.allSatisfy(properties -> Assertions.assertThat(properties)
.asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class))
Expand Down
34 changes: 17 additions & 17 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
import org.junit.rules.TestRule;

import io.weaviate.ConcurrentTest;
import io.weaviate.client6.WeaviateClient;
import io.weaviate.client6.v1.api.WeaviateClient;
import io.weaviate.client6.v1.api.collections.Property;
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;
import io.weaviate.client6.v1.api.collections.query.GroupBy;
import io.weaviate.client6.v1.api.collections.query.MetadataField;
import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup;
import io.weaviate.client6.v1.collections.Property;
import io.weaviate.client6.v1.collections.Reference;
import io.weaviate.client6.v1.collections.VectorIndex;
import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy;
import io.weaviate.client6.v1.collections.Vectorizer;
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 @@ -111,10 +112,10 @@ private static Map<String, Float[]> populateTest(int n) throws IOException {
var object = things.data.insert(
Map.of("category", CATEGORIES.get(i % CATEGORIES.size())),
metadata -> metadata
.id(randomUUID())
.uuid(randomUUID())
.vectors(Vectors.of(VECTOR_INDEX, vector)));

created.put(object.metadata().id(), vector);
created.put(object.metadata().uuid(), vector);
}

return created;
Expand All @@ -128,7 +129,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, new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none())));
.vector(VECTOR_INDEX, Hnsw.of(new NoneVectorizer())));
}

@Test
Expand All @@ -137,7 +138,7 @@ public void testNearText() throws IOException {
client.collections.create(nsSongs,
col -> col
.properties(Property.text("title"))
.vector(new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.text2vecContextionary())));
.vector(Hnsw.of(Text2VecContextionaryVectorizer.of())));

var songs = client.collections.use(nsSongs);
var submarine = songs.data.insert(Map.of("title", "Yellow Submarine"));
Expand All @@ -148,7 +149,7 @@ public void testNearText() throws IOException {
opt -> opt
.distance(0.5f)
.moveTo(.98f, to -> to.concepts("tropical"))
.moveAway(.4f, away -> away.uuids(submarine.metadata().id()))
.moveAway(.4f, away -> away.uuids(submarine.metadata().uuid()))
.returnProperties("title"));

Assertions.assertThat(result.objects()).hasSize(2)
Expand All @@ -159,7 +160,7 @@ public void testNearText() throws IOException {

@Test
public void testNearText_groupBy() throws IOException {
var vectorIndex = new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.text2vecContextionary());
var vectorIndex = Hnsw.of(Text2VecContextionaryVectorizer.of());

var nsArtists = ns("Artists");
client.collections.create(nsArtists,
Expand Down Expand Up @@ -190,8 +191,8 @@ public void testNearText_groupBy() throws IOException {

Assertions.assertThat(result.groups()).hasSize(2)
.containsOnlyKeys(
"weaviate://localhost/%s/%s".formatted(nsArtists, beatles.metadata().id()),
"weaviate://localhost/%s/%s".formatted(nsArtists, ccr.metadata().id()));
"weaviate://localhost/%s/%s".formatted(nsArtists, beatles.metadata().uuid()),
"weaviate://localhost/%s/%s".formatted(nsArtists, ccr.metadata().uuid()));
}

@Test
Expand All @@ -203,9 +204,8 @@ public void testNearImage() throws IOException {
.properties(
Property.text("breed"),
Property.blob("img"))
.vector(new VectorIndex<>(
IndexingStrategy.hnsw(),
Vectorizer.img2VecNeuralVectorizer(
.vector(Hnsw.of(
Img2VecNeuralVectorizer.of(
i2v -> i2v.imageFields("img")))));

var cats = client.collections.use(nsCats);
Expand Down
Loading