Skip to content
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/integration/CollectionsITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void testUpdateCollection() throws IOException {
var things = client.collections.use(nsThings);

// Act
things.config.update(nsThings, collection -> collection
things.config.update(c -> c
.description("Things stored on shelves")
.propertyDescription("width", "not height")
.invertedIndex(idx -> idx.cleanupIntervalSeconds(30))
Expand Down
3 changes: 2 additions & 1 deletion src/it/java/io/weaviate/integration/DataITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.weaviate.client6.v1.api.collections.data.DeleteManyResponse;
import io.weaviate.client6.v1.api.collections.data.Reference;
import io.weaviate.client6.v1.api.collections.query.Metadata;
import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField;
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
import io.weaviate.client6.v1.api.collections.query.QueryReference;
import io.weaviate.client6.v1.api.collections.query.Where;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void testCreateGetDelete() throws IOException {
var object = artists.query.byId(id, query -> query
.returnProperties("name")
.returnMetadata(
Metadata.VECTOR,
MetadataField.VECTOR,
Metadata.CREATION_TIME_UNIX, Metadata.LAST_UPDATE_TIME_UNIX));

Assertions.assertThat(artists.data.exists(id))
Expand Down
46 changes: 33 additions & 13 deletions src/it/java/io/weaviate/integration/SearchITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,12 @@ public void testBadRequest_async() throws Throwable {
var nsThings = ns("Things");

try (final var async = client.async()) {
async.collections.create(nsThings,
var things = async.collections.create(nsThings,
collection -> collection
.properties(Property.text("name"))
.vectorConfig(VectorConfig.text2vecContextionary()))
.join();

var things = async.collections.use(nsThings);
var balloon = things.data.insert(Map.of("name", "balloon")).join();

try {
Expand All @@ -463,17 +462,44 @@ public void testBadRequest_async() throws Throwable {
}
}

@Test
public void test_includeVectors() throws IOException {
// Arrange
var nsThings = ns("Things");
var things = client.collections.create(nsThings,
c -> c.vectorConfig(
VectorConfig.selfProvided("v1"),
VectorConfig.selfProvided("v2"),
VectorConfig.selfProvided("v3")));

var thing_1 = things.data.insert(Map.of(), thing -> thing.vectors(
Vectors.of("v1", new float[] { 1, 2, 3 }),
Vectors.of("v2", new float[] { 4, 5, 6 }),
Vectors.of("v3", new float[] { 7, 8, 9 })));

// Act
var got = things.query.byId(
thing_1.uuid(),
q -> q.includeVector("v1", "v2"));

// Assert
Assertions.assertThat(got).get()
.extracting(WeaviateObject::vectors)
.returns(true, v -> v.contains("v1"))
.returns(true, v -> v.contains("v2"))
.returns(false, v -> v.contains("v3"));
}

@Test
public void testMetadataAll() throws IOException {
// Arrange
var nsThings = ns("Things");
client.collections.create(nsThings,
var things = client.collections.create(nsThings,
c -> c
.properties(Property.text("name"))
.vectorConfig(VectorConfig.text2vecContextionary(
t2v -> t2v.sourceProperties("name"))));

var things = client.collections.use(nsThings);
var frisbee = things.data.insert(Map.of("name", "orange disc"));

// Act
Expand Down Expand Up @@ -513,16 +539,14 @@ public void testNearVector_targetVectors() throws IOException {
// Arrange
var nsThings = ns("Things");

client.collections.create(nsThings,
var 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 } })));
Expand Down Expand Up @@ -559,15 +583,13 @@ public void testGenerative_bm25() throws IOException {
// Arrange
var nsThings = ns("Things");

client.collections.create(nsThings,
var things = client.collections.create(nsThings,
c -> c
.properties(Property.text("title"))
.generativeModule(new DummyGenerative())
.vectorConfig(VectorConfig.text2vecContextionary(
t2v -> t2v.sourceProperties("title"))));

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

things.data.insertMany(
Map.of("title", "Salad Fork"),
Map.of("title", "Dessert Fork"));
Expand Down Expand Up @@ -600,15 +622,13 @@ public void testGenerative_bm25_groupBy() throws IOException {
// Arrange
var nsThings = ns("Things");

client.collections.create(nsThings,
var things = client.collections.create(nsThings,
c -> c
.properties(Property.text("title"))
.generativeModule(new DummyGenerative())
.vectorConfig(VectorConfig.text2vecContextionary(
t2v -> t2v.sourceProperties("title"))));

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

things.data.insertMany(
Map.of("title", "Salad Fork"),
Map.of("title", "Dessert Fork"));
Expand Down
70 changes: 51 additions & 19 deletions src/main/java/io/weaviate/client6/v1/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.net.ssl.TrustManagerFactory;

import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.Timeout;
import io.weaviate.client6.v1.internal.TokenProvider;
import io.weaviate.client6.v1.internal.grpc.GrpcChannelOptions;
import io.weaviate.client6.v1.internal.rest.RestTransportOptions;
Expand All @@ -20,7 +21,8 @@ public record Config(
int grpcPort,
Map<String, String> headers,
Authentication authentication,
TrustManagerFactory trustManagerFactory) {
TrustManagerFactory trustManagerFactory,
Timeout timeout) {

public static Config of(Function<Custom, ObjectBuilder<Config>> fn) {
return fn.apply(new Custom()).build();
Expand All @@ -35,26 +37,27 @@ private Config(Builder<?> builder) {
builder.grpcPort,
builder.headers,
builder.authentication,
builder.trustManagerFactory);
builder.trustManagerFactory,
builder.timeout);
}

RestTransportOptions restTransportOptions() {
return restTransportOptions(null);
}

RestTransportOptions restTransportOptions(TokenProvider tokenProvider) {
return new RestTransportOptions(scheme, httpHost, httpPort, headers, tokenProvider, trustManagerFactory);
return new RestTransportOptions(scheme, httpHost, httpPort, headers, tokenProvider, trustManagerFactory, timeout);
}

GrpcChannelOptions grpcTransportOptions() {
return grpcTransportOptions(null);
}

GrpcChannelOptions grpcTransportOptions(TokenProvider tokenProvider) {
return new GrpcChannelOptions(scheme, grpcHost, grpcPort, headers, tokenProvider, trustManagerFactory);
return new GrpcChannelOptions(scheme, grpcHost, grpcPort, headers, tokenProvider, trustManagerFactory, timeout);
}

private abstract static class Builder<SELF extends Builder<SELF>> implements ObjectBuilder<Config> {
private abstract static class Builder<SelfT extends Builder<SelfT>> implements ObjectBuilder<Config> {
protected String scheme;

protected String httpHost;
Expand All @@ -63,36 +66,37 @@ private abstract static class Builder<SELF extends Builder<SELF>> implements Obj
protected int grpcPort;
protected Authentication authentication;
protected TrustManagerFactory trustManagerFactory;
protected Timeout timeout = new Timeout();
protected Map<String, String> headers = new HashMap<>();

/**
* Set URL scheme. Subclasses may increase the visibility of this method to
* {@code public} if using a different scheme is allowed.
*/
@SuppressWarnings("unchecked")
protected SELF scheme(String scheme) {
protected SelfT scheme(String scheme) {
this.scheme = scheme;
return (SELF) this;
return (SelfT) this;
}

/**
* Set port for REST requests. Subclasses may increase the visibility of this
* method to {@code public} if using a different port is allowed.
*/
@SuppressWarnings("unchecked")
protected SELF httpHost(String httpHost) {
protected SelfT httpHost(String httpHost) {
this.httpHost = trimScheme(httpHost);
return (SELF) this;
return (SelfT) this;
}

/**
* Set port for gRPC requests. Subclasses may increase the visibility of this
* method to {@code public} if using a different port is allowed.
*/
@SuppressWarnings("unchecked")
protected SELF grpcHost(String grpcHost) {
protected SelfT grpcHost(String grpcHost) {
this.grpcHost = trimScheme(grpcHost);
return (SELF) this;
return (SelfT) this;
}

/** Remove leading http(s):// prefix from a URL, if present. */
Expand All @@ -105,19 +109,19 @@ private String trimScheme(String url) {
* secure connection should expose this method.
*/
@SuppressWarnings("unchecked")
protected SELF trustManagerFactory(TrustManagerFactory tmf) {
protected SelfT trustManagerFactory(TrustManagerFactory tmf) {
this.trustManagerFactory = tmf;
return (SELF) this;
return (SelfT) this;
}

/**
* Set authentication method. Setting this to {@code null} or omitting
* will not use any authentication mechanism.
*/
@SuppressWarnings("unchecked")
public SELF authentication(Authentication authz) {
public SelfT authentication(Authentication authz) {
this.authentication = authz;
return (SELF) this;
return (SelfT) this;
}

/**
Expand All @@ -126,19 +130,47 @@ public SELF authentication(Authentication authz) {
* This will be applied both to REST and gRPC requests.
*/
@SuppressWarnings("unchecked")
public SELF setHeader(String key, String value) {
public SelfT setHeader(String key, String value) {
this.headers.put(key, value);
return (SELF) this;
return (SelfT) this;
}

/**
* Set multiple request headers.
* This will be applied both to REST and gRPC requests.
*/
@SuppressWarnings("unchecked")
public SELF setHeaders(Map<String, String> headers) {
public SelfT setHeaders(Map<String, String> headers) {
this.headers.putAll(Map.copyOf(headers));
return (SELF) this;
return (SelfT) this;
}

/**
* Set connection, query, and insert timeout to the same value.
*
* @param timeoutSeconds Response timeout in seconds.
*/
@SuppressWarnings("unchecked")
public SelfT timeout(int timeoutSeconds) {
this.timeout = new Timeout(timeoutSeconds);
return (SelfT) this;
}

/**
* Set individual connection, query, and insert timeouts.
*
* <p>
* Because all inserts go over gRPC connection, the REST requests
* will assume {@code querySeconds} timeouts.
*
* @param initSeconds Connection timeout in seconds.
* @param querySeconds Response timeout for query requests.
* @param insertSeconds Response timeout for insert requests.
*/
@SuppressWarnings("unchecked")
public SelfT timeout(int initSeconds, int querySeconds, int insertSeconds) {
this.timeout = new Timeout(initSeconds, querySeconds, insertSeconds);
return (SelfT) this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/weaviate/client6/v1/api/WeaviateClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.weaviate.client6.v1.api.rbac.roles.WeaviateRolesClient;
import io.weaviate.client6.v1.api.rbac.users.WeaviateUsersClient;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.Timeout;
import io.weaviate.client6.v1.internal.TokenProvider;
import io.weaviate.client6.v1.internal.grpc.DefaultGrpcTransport;
import io.weaviate.client6.v1.internal.grpc.GrpcChannelOptions;
Expand Down Expand Up @@ -83,7 +84,8 @@ public WeaviateClient(Config config) {
// the associated resources in case we have to throw an exception.
// Assign to this.restTransport only once we're in the clear to
// avoid publishing the object before it's fully initialized.
var _restTransport = new DefaultRestTransport(restOpt);
var _restTransport = new DefaultRestTransport(restOpt.withTimeout(
new Timeout(restOpt.timeout().initSeconds())));
boolean isLive = false;
InstanceMetadata meta = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.weaviate.client6.v1.api.rbac.roles.WeaviateRolesClientAsync;
import io.weaviate.client6.v1.api.rbac.users.WeaviateUsersClientAsync;
import io.weaviate.client6.v1.internal.ObjectBuilder;
import io.weaviate.client6.v1.internal.Timeout;
import io.weaviate.client6.v1.internal.TokenProvider;
import io.weaviate.client6.v1.internal.grpc.DefaultGrpcTransport;
import io.weaviate.client6.v1.internal.grpc.GrpcChannelOptions;
Expand Down Expand Up @@ -86,7 +87,8 @@ public WeaviateClientAsync(Config config) {
// the associated resources in case we have to throw an exception.
// Assign to this.restTransport only once we're in the clear to
// avoid publishing the object before it's fully initialized.
var _restTransport = new DefaultRestTransport(restOpt);
var _restTransport = new DefaultRestTransport(restOpt.withTimeout(
new Timeout(restOpt.timeout().initSeconds())));
boolean isLive = false;
InstanceMetadata meta = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public Vectors(Vectors... vectors) {
this.vectorsMap = namedVectors;
}

/**
* Check if a vector exists in the query result.
*
* @param name Vector name.
*/
public boolean contains(String name) {
return vectorsMap.containsKey(name);
}

/**
* Get 1-dimensional vector by name.
*
Expand Down
Loading