Skip to content
6 changes: 3 additions & 3 deletions src/it/java/io/weaviate/integration/OIDCSupportITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class OIDCSupportITest extends ConcurrentTest {
*/
@Test
public void test_bearerToken() throws Exception {
Assume.assumeTrue("WCS_DUMMY_CI_PW is not set", WCS_DUMMY_CI_PW != null);
Assume.assumeTrue("WCS_DUMMY_CI_PW is not set", WCS_DUMMY_CI_PW != null && !WCS_DUMMY_CI_PW.isBlank());
Assume.assumeTrue("no internet connection", hasInternetConnection());

var passwordAuth = Authentication.resourceOwnerPassword(WCS_DUMMY_CI_USERNAME, WCS_DUMMY_CI_PW, List.of());
Expand All @@ -78,7 +78,7 @@ public void test_bearerToken() throws Exception {

@Test
public void test_resourceOwnerPassword() throws Exception {
Assume.assumeTrue("WCS_DUMMY_CI_PW is not set", WCS_DUMMY_CI_PW != null);
Assume.assumeTrue("WCS_DUMMY_CI_PW is not set", WCS_DUMMY_CI_PW != null && !WCS_DUMMY_CI_PW.isBlank());
Assume.assumeTrue("no internet connection", hasInternetConnection());

// Check norwal resource owner password flow works.
Expand All @@ -103,7 +103,7 @@ public void test_resourceOwnerPassword() throws Exception {

@Test
public void test_clientCredentials() throws Exception {
Assume.assumeTrue("OKTA_CLIENT_SECRET is not set", OKTA_CLIENT_SECRET != null);
Assume.assumeTrue("OKTA_CLIENT_SECRET is not set", OKTA_CLIENT_SECRET != null && !OKTA_CLIENT_SECRET.isBlank());
Assume.assumeTrue("no internet connection", hasInternetConnection());

// Check norwal client credentials flow works.
Expand Down
50 changes: 50 additions & 0 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.weaviate.ConcurrentTest;
import io.weaviate.client6.v1.api.WeaviateApiException;
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.VectorConfig;
Expand All @@ -31,7 +32,10 @@
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.SortBy;
import io.weaviate.client6.v1.api.collections.query.Target;
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.vectorindex.MultiVector;
import io.weaviate.containers.Container;
import io.weaviate.containers.Container.ContainerGroup;
import io.weaviate.containers.Contextionary;
Expand Down Expand Up @@ -499,4 +503,50 @@ public void testMetadataAll() throws IOException {
Assertions.assertThat(metadataNearText.distance()).as("distance").isNotNull();
Assertions.assertThat(metadataNearText.certainty()).as("certainty").isNotNull();
}

@Test
public void testNearVector_targetVectors() throws IOException {
// Arrange
var nsThings = ns("Things");

client.collections.create(nsThings,
c -> c.vectorConfig(
VectorConfig.selfProvided("v1d"),
VectorConfig.selfProvided("v2d",
none -> none
.vectorIndex(Hnsw.of(
hnsw -> hnsw.multiVector(MultiVector.of()))))));

var things = client.collections.use(nsThings);

var thing123 = things.data.insert(Map.of(), thing -> thing.vectors(
Vectors.of("v1d", new float[] { 1, 2, 3 }),
Vectors.of("v2d", new float[][] { { 1, 2, 3 }, { 1, 2, 3 } })));

var thing456 = things.data.insertMany(List.of(
WeaviateObject.of(thing -> thing
.metadata(ObjectMetadata.of(
meta -> meta
.vectors(
Vectors.of("v1d", new float[] { 4, 5, 6 }),
Vectors.of("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } })))))));
Assertions.assertThat(thing456.errors()).as("insert many").isEmpty();

// Act
var got123 = things.query.nearVector(
Target.vector("v1d", new float[] { 1, 2, 3 }),
q -> q.limit(1));
Assertions.assertThat(got123.objects())
.as("search v1d")
.hasSize(1).extracting(WeaviateObject::uuid)
.containsExactly(thing123.uuid());

var got456 = things.query.nearVector(
Target.vector("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } }),
q -> q.limit(1));
Assertions.assertThat(got456.objects())
.as("search v2d")
.hasSize(1).extracting(WeaviateObject::uuid)
.containsExactly(thing456.uuids().get(0));
}
}
108 changes: 108 additions & 0 deletions src/main/java/io/weaviate/client6/v1/api/collections/Encoding.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.weaviate.client6.v1.api.collections;

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;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import io.weaviate.client6.v1.api.collections.encoding.MuveraEncoding;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.json.JsonEnum;

public interface Encoding {

enum Kind implements JsonEnum<Kind> {
MUVERA("muvera");

private static final Map<String, Kind> jsonValueMap = JsonEnum.collectNames(Kind.values());
private final String jsonValue;

private Kind(String jsonValue) {
this.jsonValue = jsonValue;
}

@Override
public String jsonValue() {
return this.jsonValue;
}

public static Kind valueOfJson(String jsonValue) {
return JsonEnum.valueOfJson(jsonValue, jsonValueMap, Kind.class);
}
}

Kind _kind();

Object _self();

public static Encoding muvera() {
return MuveraEncoding.of();
}

public static Encoding muvera(Function<MuveraEncoding.Builder, ObjectBuilder<MuveraEncoding>> fn) {
return MuveraEncoding.of(fn);
}

public enum CustomTypeAdapterFactory implements TypeAdapterFactory {
INSTANCE;

private static final EnumMap<Encoding.Kind, TypeAdapter<? extends Encoding>> delegateAdapters = new EnumMap<>(
Encoding.Kind.class);

private final void addAdapter(Gson gson, Encoding.Kind kind, Class<? extends Encoding> cls) {
delegateAdapters.put(kind,
(TypeAdapter<? extends Encoding>) gson.getDelegateAdapter(this, TypeToken.get(cls)));
}

private final void init(Gson gson) {
addAdapter(gson, Encoding.Kind.MUVERA, MuveraEncoding.class);
}

@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
final var rawType = type.getRawType();
if (!Encoding.class.isAssignableFrom(rawType)) {
return null;
}

if (delegateAdapters.isEmpty()) {
init(gson);
}

return (TypeAdapter<T>) new TypeAdapter<Encoding>() {

@Override
public void write(JsonWriter out, Encoding value) throws IOException {
TypeAdapter<T> adapter = (TypeAdapter<T>) delegateAdapters.get(value._kind());
adapter.write(out, (T) value._self());
}

@Override
public Encoding read(JsonReader in) throws IOException {
var encodingObject = JsonParser.parseReader(in).getAsJsonObject();
var encodingName = encodingObject.keySet().iterator().next();

Encoding.Kind kind;
try {
kind = Encoding.Kind.valueOfJson(encodingName);
} catch (IllegalArgumentException e) {
return null;
}

var adapter = delegateAdapters.get(kind);
var concreteEncoding = encodingObject.get(encodingName).getAsJsonObject();
return adapter.fromJsonTree(concreteEncoding);
}
}.nullSafe();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ public ObjectMetadata(Builder builder) {
this(builder.uuid, builder.vectors, null, null);
}

public static ObjectMetadata of() {
return of(ObjectBuilder.identity());
}

public static ObjectMetadata of(Function<Builder, ObjectBuilder<ObjectMetadata>> fn) {
return fn.apply(new Builder()).build();
}

public static class Builder implements ObjectBuilder<ObjectMetadata> {
private String uuid;
private String uuid = UUID.randomUUID().toString();
private Vectors vectors;

/** Assign a custom UUID for the object. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
@Override
public void write(JsonWriter out, Quantization value) throws IOException {
if (value._kind() == Quantization.Kind.UNCOMPRESSED) {
// out.name(value._kind().jsonValue());
out.value(true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.weaviate.client6.v1.api.collections.query.NearThermal;
import io.weaviate.client6.v1.api.collections.query.NearVector;
import io.weaviate.client6.v1.api.collections.query.NearVideo;
import io.weaviate.client6.v1.api.collections.query.Target;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.grpc.GrpcTransport;
import io.weaviate.client6.v1.internal.orm.CollectionDescriptor;
Expand Down Expand Up @@ -197,7 +198,7 @@ public GroupedResponseT hybrid(Hybrid filter, Function<Aggregation.Builder, Obje
* @see AggregateResponse
*/
public ResponseT nearVector(float[] vector, Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn) {
return nearVector(NearVector.of(vector), fn);
return nearVector(NearVector.of(Target.vector(vector)), fn);
}

/**
Expand All @@ -214,7 +215,7 @@ public ResponseT nearVector(float[] vector, Function<Aggregation.Builder, Object
*/
public ResponseT nearVector(float[] vector, Function<NearVector.Builder, ObjectBuilder<NearVector>> nv,
Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn) {
return nearVector(NearVector.of(vector, nv), fn);
return nearVector(NearVector.of(Target.vector(vector), nv), fn);
}

/**
Expand Down Expand Up @@ -248,7 +249,7 @@ public ResponseT nearVector(NearVector filter, Function<Aggregation.Builder, Obj
*/
public GroupedResponseT nearVector(float[] vector, Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn,
GroupBy groupBy) {
return nearVector(NearVector.of(vector), fn, groupBy);
return nearVector(NearVector.of(Target.vector(vector)), fn, groupBy);
}

/**
Expand All @@ -268,7 +269,7 @@ public GroupedResponseT nearVector(float[] vector, Function<Aggregation.Builder,
*/
public GroupedResponseT nearVector(float[] vector, Function<NearVector.Builder, ObjectBuilder<NearVector>> nv,
Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn, GroupBy groupBy) {
return nearVector(NearVector.of(vector, nv), fn, groupBy);
return nearVector(NearVector.of(Target.vector(vector), nv), fn, groupBy);
}

/**
Expand Down Expand Up @@ -426,7 +427,7 @@ public ResponseT nearText(String text, Function<Aggregation.Builder, ObjectBuild
* @see AggregateResponse
*/
public ResponseT nearText(List<String> concepts, Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn) {
return nearText(NearText.of(concepts), fn);
return nearText(NearText.of(Target.text(concepts)), fn);
}

/**
Expand All @@ -443,7 +444,7 @@ public ResponseT nearText(List<String> concepts, Function<Aggregation.Builder, O
*/
public ResponseT nearText(String text, Function<NearText.Builder, ObjectBuilder<NearText>> nt,
Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn) {
return nearText(NearText.of(text, nt), fn);
return nearText(NearText.of(Target.text(List.of(text)), nt), fn);
}

/**
Expand All @@ -460,7 +461,7 @@ public ResponseT nearText(String text, Function<NearText.Builder, ObjectBuilder<
*/
public ResponseT nearText(List<String> concepts, Function<NearText.Builder, ObjectBuilder<NearText>> nt,
Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn) {
return nearText(NearText.of(concepts, nt), fn);
return nearText(NearText.of(Target.text(concepts), nt), fn);
}

/**
Expand Down Expand Up @@ -512,7 +513,7 @@ public GroupedResponseT nearText(String text, Function<Aggregation.Builder, Obje
*/
public GroupedResponseT nearText(List<String> concepts, Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn,
GroupBy groupBy) {
return nearText(NearText.of(concepts), fn, groupBy);
return nearText(NearText.of(Target.text(concepts)), fn, groupBy);
}

/**
Expand Down Expand Up @@ -552,7 +553,7 @@ public GroupedResponseT nearText(String text, Function<NearText.Builder, ObjectB
*/
public GroupedResponseT nearText(List<String> concepts, Function<NearText.Builder, ObjectBuilder<NearText>> nt,
Function<Aggregation.Builder, ObjectBuilder<Aggregation>> fn, GroupBy groupBy) {
return nearText(NearText.of(concepts, nt), fn, groupBy);
return nearText(NearText.of(Target.text(concepts), nt), fn, groupBy);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults;
import io.weaviate.client6.v1.api.collections.ObjectMetadata;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import io.weaviate.client6.v1.internal.Debug;
import io.weaviate.client6.v1.internal.MapUtil;
import io.weaviate.client6.v1.internal.grpc.ByteStringUtil;
import io.weaviate.client6.v1.internal.grpc.Rpc;
Expand All @@ -32,9 +31,7 @@ public InsertManyRequest(WeaviateObject<T, Reference, ObjectMetadata>... objects
public static final <T> InsertManyRequest<T> of(T... properties) {
var objects = Arrays.stream(properties)
.map(p -> WeaviateObject.<T, Reference, ObjectMetadata>of(
obj -> obj
.properties(p)
.metadata(ObjectMetadata.of(m -> m.uuid(UUID.randomUUID())))))
obj -> obj.properties(p).metadata(ObjectMetadata.of())))
.toList();
return new InsertManyRequest<T>(objects);
}
Expand Down Expand Up @@ -102,9 +99,7 @@ public static <T> void buildObject(WeaviateProtoBatch.BatchObject.Builder object

var metadata = insert.metadata();
if (metadata != null) {
if (metadata.uuid() != null) {
object.setUuid(metadata.uuid());
}
object.setUuid(metadata.uuid());

if (metadata.vectors() != null) {
var vectors = metadata.vectors().asMap()
Expand Down Expand Up @@ -157,13 +152,15 @@ public static <T> void buildObject(WeaviateProtoBatch.BatchObject.Builder object
}
});

var nonRef = marshalStruct(collection.propertiesReader(insert.properties()).readProperties());
object.setProperties(WeaviateProtoBatch.BatchObject.Properties.newBuilder()
.setNonRefProperties(nonRef)
var properties = WeaviateProtoBatch.BatchObject.Properties.newBuilder()
.addAllSingleTargetRefProps(singleRef)
.addAllMultiTargetRefProps(multiRef));
.addAllMultiTargetRefProps(multiRef);

Debug.printProto(object);
if (insert.properties() != null) {
var nonRef = marshalStruct(collection.propertiesReader(insert.properties()).readProperties());
properties.setNonRefProperties(nonRef);
}
object.setProperties(properties);
}

@SuppressWarnings("unchecked")
Expand Down
Loading