Skip to content

Commit 4b619bc

Browse files
authored
Merge pull request #496 from weaviate/v6-devex-feedback
v6: DevEx feedback
2 parents c1e65f5 + a6ac987 commit 4b619bc

37 files changed

+1388
-175
lines changed

src/it/java/io/weaviate/integration/CollectionsITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void testUpdateCollection() throws IOException {
142142
var things = client.collections.use(nsThings);
143143

144144
// Act
145-
things.config.update(nsThings, collection -> collection
145+
things.config.update(c -> c
146146
.description("Things stored on shelves")
147147
.propertyDescription("width", "not height")
148148
.invertedIndex(idx -> idx.cleanupIntervalSeconds(30))

src/it/java/io/weaviate/integration/DataITest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.weaviate.client6.v1.api.collections.data.DeleteManyResponse;
2626
import io.weaviate.client6.v1.api.collections.data.Reference;
2727
import io.weaviate.client6.v1.api.collections.query.Metadata;
28+
import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField;
2829
import io.weaviate.client6.v1.api.collections.query.QueryMetadata;
2930
import io.weaviate.client6.v1.api.collections.query.QueryReference;
3031
import io.weaviate.client6.v1.api.collections.query.Where;
@@ -54,7 +55,7 @@ public void testCreateGetDelete() throws IOException {
5455
var object = artists.query.byId(id, query -> query
5556
.returnProperties("name")
5657
.returnMetadata(
57-
Metadata.VECTOR,
58+
MetadataField.VECTOR,
5859
Metadata.CREATION_TIME_UNIX, Metadata.LAST_UPDATE_TIME_UNIX));
5960

6061
Assertions.assertThat(artists.data.exists(id))

src/it/java/io/weaviate/integration/SearchITest.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,12 @@ public void testBadRequest_async() throws Throwable {
446446
var nsThings = ns("Things");
447447

448448
try (final var async = client.async()) {
449-
async.collections.create(nsThings,
449+
var things = async.collections.create(nsThings,
450450
collection -> collection
451451
.properties(Property.text("name"))
452452
.vectorConfig(VectorConfig.text2vecModel2Vec()))
453453
.join();
454454

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

458457
try {
@@ -463,17 +462,44 @@ public void testBadRequest_async() throws Throwable {
463462
}
464463
}
465464

465+
@Test
466+
public void test_includeVectors() throws IOException {
467+
// Arrange
468+
var nsThings = ns("Things");
469+
var things = client.collections.create(nsThings,
470+
c -> c.vectorConfig(
471+
VectorConfig.selfProvided("v1"),
472+
VectorConfig.selfProvided("v2"),
473+
VectorConfig.selfProvided("v3")));
474+
475+
var thing_1 = things.data.insert(Map.of(), thing -> thing.vectors(
476+
Vectors.of("v1", new float[] { 1, 2, 3 }),
477+
Vectors.of("v2", new float[] { 4, 5, 6 }),
478+
Vectors.of("v3", new float[] { 7, 8, 9 })));
479+
480+
// Act
481+
var got = things.query.byId(
482+
thing_1.uuid(),
483+
q -> q.includeVector("v1", "v2"));
484+
485+
// Assert
486+
Assertions.assertThat(got).get()
487+
.extracting(WeaviateObject::vectors)
488+
.returns(true, v -> v.contains("v1"))
489+
.returns(true, v -> v.contains("v2"))
490+
.returns(false, v -> v.contains("v3"));
491+
}
492+
466493
@Test
467494
public void testMetadataAll() throws IOException {
468495
// Arrange
469496
var nsThings = ns("Things");
470-
client.collections.create(nsThings,
497+
var things = client.collections.create(nsThings,
471498
c -> c
472499
.properties(Property.text("name"))
473500
.vectorConfig(VectorConfig.text2vecModel2Vec(
474501
t2v -> t2v.sourceProperties("name"))));
475502

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

479505
// Act
@@ -513,16 +539,14 @@ public void testNearVector_targetVectors() throws IOException {
513539
// Arrange
514540
var nsThings = ns("Things");
515541

516-
client.collections.create(nsThings,
542+
var things = client.collections.create(nsThings,
517543
c -> c.vectorConfig(
518544
VectorConfig.selfProvided("v1d"),
519545
VectorConfig.selfProvided("v2d",
520546
none -> none
521547
.vectorIndex(Hnsw.of(
522548
hnsw -> hnsw.multiVector(MultiVector.of()))))));
523549

524-
var things = client.collections.use(nsThings);
525-
526550
var thing123 = things.data.insert(Map.of(), thing -> thing.vectors(
527551
Vectors.of("v1d", new float[] { 1, 2, 3 }),
528552
Vectors.of("v2d", new float[][] { { 1, 2, 3 }, { 1, 2, 3 } })));
@@ -559,15 +583,13 @@ public void testGenerative_bm25() throws IOException {
559583
// Arrange
560584
var nsThings = ns("Things");
561585

562-
client.collections.create(nsThings,
586+
var things = client.collections.create(nsThings,
563587
c -> c
564588
.properties(Property.text("title"))
565589
.generativeModule(new DummyGenerative())
566590
.vectorConfig(VectorConfig.text2vecModel2Vec(
567591
t2v -> t2v.sourceProperties("title"))));
568592

569-
var things = client.collections.use(nsThings);
570-
571593
things.data.insertMany(
572594
Map.of("title", "Salad Fork"),
573595
Map.of("title", "Dessert Fork"));
@@ -600,15 +622,13 @@ public void testGenerative_bm25_groupBy() throws IOException {
600622
// Arrange
601623
var nsThings = ns("Things");
602624

603-
client.collections.create(nsThings,
625+
var things = client.collections.create(nsThings,
604626
c -> c
605627
.properties(Property.text("title"))
606628
.generativeModule(new DummyGenerative())
607629
.vectorConfig(VectorConfig.text2vecModel2Vec(
608630
t2v -> t2v.sourceProperties("title"))));
609631

610-
var things = client.collections.use(nsThings);
611-
612632
things.data.insertMany(
613633
Map.of("title", "Salad Fork"),
614634
Map.of("title", "Dessert Fork"));

src/main/java/io/weaviate/client6/v1/api/Config.java

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.net.ssl.TrustManagerFactory;
99

1010
import io.weaviate.client6.v1.internal.ObjectBuilder;
11+
import io.weaviate.client6.v1.internal.Timeout;
1112
import io.weaviate.client6.v1.internal.TokenProvider;
1213
import io.weaviate.client6.v1.internal.grpc.GrpcChannelOptions;
1314
import io.weaviate.client6.v1.internal.rest.RestTransportOptions;
@@ -20,7 +21,8 @@ public record Config(
2021
int grpcPort,
2122
Map<String, String> headers,
2223
Authentication authentication,
23-
TrustManagerFactory trustManagerFactory) {
24+
TrustManagerFactory trustManagerFactory,
25+
Timeout timeout) {
2426

2527
public static Config of(Function<Custom, ObjectBuilder<Config>> fn) {
2628
return fn.apply(new Custom()).build();
@@ -35,26 +37,27 @@ private Config(Builder<?> builder) {
3537
builder.grpcPort,
3638
builder.headers,
3739
builder.authentication,
38-
builder.trustManagerFactory);
40+
builder.trustManagerFactory,
41+
builder.timeout);
3942
}
4043

4144
RestTransportOptions restTransportOptions() {
4245
return restTransportOptions(null);
4346
}
4447

4548
RestTransportOptions restTransportOptions(TokenProvider tokenProvider) {
46-
return new RestTransportOptions(scheme, httpHost, httpPort, headers, tokenProvider, trustManagerFactory);
49+
return new RestTransportOptions(scheme, httpHost, httpPort, headers, tokenProvider, trustManagerFactory, timeout);
4750
}
4851

4952
GrpcChannelOptions grpcTransportOptions() {
5053
return grpcTransportOptions(null);
5154
}
5255

5356
GrpcChannelOptions grpcTransportOptions(TokenProvider tokenProvider) {
54-
return new GrpcChannelOptions(scheme, grpcHost, grpcPort, headers, tokenProvider, trustManagerFactory);
57+
return new GrpcChannelOptions(scheme, grpcHost, grpcPort, headers, tokenProvider, trustManagerFactory, timeout);
5558
}
5659

57-
private abstract static class Builder<SELF extends Builder<SELF>> implements ObjectBuilder<Config> {
60+
private abstract static class Builder<SelfT extends Builder<SelfT>> implements ObjectBuilder<Config> {
5861
protected String scheme;
5962

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

6872
/**
6973
* Set URL scheme. Subclasses may increase the visibility of this method to
7074
* {@code public} if using a different scheme is allowed.
7175
*/
7276
@SuppressWarnings("unchecked")
73-
protected SELF scheme(String scheme) {
77+
protected SelfT scheme(String scheme) {
7478
this.scheme = scheme;
75-
return (SELF) this;
79+
return (SelfT) this;
7680
}
7781

7882
/**
7983
* Set port for REST requests. Subclasses may increase the visibility of this
8084
* method to {@code public} if using a different port is allowed.
8185
*/
8286
@SuppressWarnings("unchecked")
83-
protected SELF httpHost(String httpHost) {
87+
protected SelfT httpHost(String httpHost) {
8488
this.httpHost = trimScheme(httpHost);
85-
return (SELF) this;
89+
return (SelfT) this;
8690
}
8791

8892
/**
8993
* Set port for gRPC requests. Subclasses may increase the visibility of this
9094
* method to {@code public} if using a different port is allowed.
9195
*/
9296
@SuppressWarnings("unchecked")
93-
protected SELF grpcHost(String grpcHost) {
97+
protected SelfT grpcHost(String grpcHost) {
9498
this.grpcHost = trimScheme(grpcHost);
95-
return (SELF) this;
99+
return (SelfT) this;
96100
}
97101

98102
/** Remove leading http(s):// prefix from a URL, if present. */
@@ -105,19 +109,19 @@ private String trimScheme(String url) {
105109
* secure connection should expose this method.
106110
*/
107111
@SuppressWarnings("unchecked")
108-
protected SELF trustManagerFactory(TrustManagerFactory tmf) {
112+
protected SelfT trustManagerFactory(TrustManagerFactory tmf) {
109113
this.trustManagerFactory = tmf;
110-
return (SELF) this;
114+
return (SelfT) this;
111115
}
112116

113117
/**
114118
* Set authentication method. Setting this to {@code null} or omitting
115119
* will not use any authentication mechanism.
116120
*/
117121
@SuppressWarnings("unchecked")
118-
public SELF authentication(Authentication authz) {
122+
public SelfT authentication(Authentication authz) {
119123
this.authentication = authz;
120-
return (SELF) this;
124+
return (SelfT) this;
121125
}
122126

123127
/**
@@ -126,19 +130,47 @@ public SELF authentication(Authentication authz) {
126130
* This will be applied both to REST and gRPC requests.
127131
*/
128132
@SuppressWarnings("unchecked")
129-
public SELF setHeader(String key, String value) {
133+
public SelfT setHeader(String key, String value) {
130134
this.headers.put(key, value);
131-
return (SELF) this;
135+
return (SelfT) this;
132136
}
133137

134138
/**
135139
* Set multiple request headers.
136140
* This will be applied both to REST and gRPC requests.
137141
*/
138142
@SuppressWarnings("unchecked")
139-
public SELF setHeaders(Map<String, String> headers) {
143+
public SelfT setHeaders(Map<String, String> headers) {
140144
this.headers.putAll(Map.copyOf(headers));
141-
return (SELF) this;
145+
return (SelfT) this;
146+
}
147+
148+
/**
149+
* Set connection, query, and insert timeout to the same value.
150+
*
151+
* @param timeoutSeconds Response timeout in seconds.
152+
*/
153+
@SuppressWarnings("unchecked")
154+
public SelfT timeout(int timeoutSeconds) {
155+
this.timeout = new Timeout(timeoutSeconds);
156+
return (SelfT) this;
157+
}
158+
159+
/**
160+
* Set individual connection, query, and insert timeouts.
161+
*
162+
* <p>
163+
* Because all inserts go over gRPC connection, the REST requests
164+
* will assume {@code querySeconds} timeouts.
165+
*
166+
* @param initSeconds Connection timeout in seconds.
167+
* @param querySeconds Response timeout for query requests.
168+
* @param insertSeconds Response timeout for insert requests.
169+
*/
170+
@SuppressWarnings("unchecked")
171+
public SelfT timeout(int initSeconds, int querySeconds, int insertSeconds) {
172+
this.timeout = new Timeout(initSeconds, querySeconds, insertSeconds);
173+
return (SelfT) this;
142174
}
143175

144176
/**

src/main/java/io/weaviate/client6/v1/api/WeaviateClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.weaviate.client6.v1.api.rbac.roles.WeaviateRolesClient;
1212
import io.weaviate.client6.v1.api.rbac.users.WeaviateUsersClient;
1313
import io.weaviate.client6.v1.internal.ObjectBuilder;
14+
import io.weaviate.client6.v1.internal.Timeout;
1415
import io.weaviate.client6.v1.internal.TokenProvider;
1516
import io.weaviate.client6.v1.internal.grpc.DefaultGrpcTransport;
1617
import io.weaviate.client6.v1.internal.grpc.GrpcChannelOptions;
@@ -83,7 +84,8 @@ public WeaviateClient(Config config) {
8384
// the associated resources in case we have to throw an exception.
8485
// Assign to this.restTransport only once we're in the clear to
8586
// avoid publishing the object before it's fully initialized.
86-
var _restTransport = new DefaultRestTransport(restOpt);
87+
var _restTransport = new DefaultRestTransport(restOpt.withTimeout(
88+
new Timeout(restOpt.timeout().initSeconds())));
8789
boolean isLive = false;
8890
InstanceMetadata meta = null;
8991
try {

src/main/java/io/weaviate/client6/v1/api/WeaviateClientAsync.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.weaviate.client6.v1.api.rbac.roles.WeaviateRolesClientAsync;
1414
import io.weaviate.client6.v1.api.rbac.users.WeaviateUsersClientAsync;
1515
import io.weaviate.client6.v1.internal.ObjectBuilder;
16+
import io.weaviate.client6.v1.internal.Timeout;
1617
import io.weaviate.client6.v1.internal.TokenProvider;
1718
import io.weaviate.client6.v1.internal.grpc.DefaultGrpcTransport;
1819
import io.weaviate.client6.v1.internal.grpc.GrpcChannelOptions;
@@ -86,7 +87,8 @@ public WeaviateClientAsync(Config config) {
8687
// the associated resources in case we have to throw an exception.
8788
// Assign to this.restTransport only once we're in the clear to
8889
// avoid publishing the object before it's fully initialized.
89-
var _restTransport = new DefaultRestTransport(restOpt);
90+
var _restTransport = new DefaultRestTransport(restOpt.withTimeout(
91+
new Timeout(restOpt.timeout().initSeconds())));
9092
boolean isLive = false;
9193
InstanceMetadata meta = null;
9294
try {

src/main/java/io/weaviate/client6/v1/api/collections/Vectors.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ public Vectors(Vectors... vectors) {
8181
this.vectorsMap = namedVectors;
8282
}
8383

84+
/**
85+
* Check if a vector exists in the query result.
86+
*
87+
* @param name Vector name.
88+
*/
89+
public boolean contains(String name) {
90+
return vectorsMap.containsKey(name);
91+
}
92+
8493
/**
8594
* Get 1-dimensional vector by name.
8695
*

0 commit comments

Comments
 (0)