Skip to content

Commit afff617

Browse files
committed
feat: add .includeVector() shortcut like the other clients have
1 parent 162f860 commit afff617

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ public void testUpdate() throws IOException {
257257
var updIvanhoe = books.query.byId(
258258
ivanhoe.metadata().uuid(),
259259
query -> query
260-
.returnMetadata(Metadata.VECTOR)
261-
.returnReferences(
262-
QueryReference.single("writtenBy")));
260+
.includeVector()
261+
.returnReferences(QueryReference.single("writtenBy")));
263262

264263
Assertions.assertThat(updIvanhoe).get()
265264
.satisfies(book -> {

src/main/java/io/weaviate/client6/v1/api/collections/query/BaseQueryOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public final SELF returnMetadata(List<Metadata> metadata) {
117117
return (SELF) this;
118118
}
119119

120+
public final SELF includeVector() {
121+
return returnMetadata(Metadata.VECTOR);
122+
}
123+
120124
final BaseQueryOptions baseOptions() {
121125
return _build();
122126
}

src/main/java/io/weaviate/client6/v1/api/collections/query/ById.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public final Builder returnMetadata(List<Metadata> metadata) {
7575
return this;
7676
}
7777

78+
public final Builder includeVector() {
79+
return returnMetadata(Metadata.VECTOR);
80+
}
81+
7882
@Override
7983
public ById build() {
8084
return new ById(this);

src/main/java/io/weaviate/client6/v1/api/collections/query/QueryReference.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5+
import java.util.HashSet;
56
import java.util.List;
7+
import java.util.Set;
68
import java.util.function.Function;
79

810
import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField;
@@ -12,7 +14,6 @@
1214
public record QueryReference(
1315
String property,
1416
String collection,
15-
boolean includeVector,
1617
List<String> includeVectors,
1718
List<String> returnProperties,
1819
List<QueryReference> returnReferences,
@@ -22,11 +23,10 @@ public QueryReference(Builder options) {
2223
this(
2324
options.property,
2425
options.collection,
25-
options.includeVector,
26-
options.includeVectors,
27-
options.returnProperties,
26+
new ArrayList<>(options.includeVectors),
27+
new ArrayList<>(options.returnProperties),
2828
options.returnReferences,
29-
options.returnMetadata);
29+
new ArrayList<>(options.returnMetadata));
3030
}
3131

3232
public static QueryReference single(String property) {
@@ -51,25 +51,19 @@ public static class Builder implements ObjectBuilder<QueryReference> {
5151
private final String property;
5252
private final String collection;
5353

54-
private boolean includeVector;
55-
private List<String> includeVectors = new ArrayList<>();
56-
private List<String> returnProperties = new ArrayList<>();
54+
private Set<String> includeVectors = new HashSet<>();
55+
private Set<String> returnProperties = new HashSet<>();
5756
private List<QueryReference> returnReferences = new ArrayList<>();
58-
private List<Metadata> returnMetadata = new ArrayList<>();
57+
private Set<Metadata> returnMetadata = new HashSet<>();
5958

6059
public Builder(String collection, String property) {
6160
this.property = property;
6261
this.collection = collection;
6362
returnMetadata(MetadataField.UUID);
6463
}
6564

66-
public final Builder includeVector() {
67-
this.includeVector = true;
68-
return this;
69-
}
70-
7165
public final Builder includeVectors(String... vectors) {
72-
this.includeVectors = Arrays.asList(vectors);
66+
this.includeVectors.addAll(Arrays.asList(vectors));
7367
return this;
7468
}
7569

@@ -100,6 +94,10 @@ public final Builder returnMetadata(List<Metadata> metadata) {
10094
return this;
10195
}
10296

97+
public final Builder includeVector() {
98+
return returnMetadata(Metadata.VECTOR);
99+
}
100+
103101
@Override
104102
public QueryReference build() {
105103
return new QueryReference(this);
@@ -115,6 +113,7 @@ public void appendTo(WeaviateProtoSearchGet.RefPropertiesRequest.Builder referen
115113
if (!returnMetadata.isEmpty()) {
116114
var metadata = WeaviateProtoSearchGet.MetadataRequest.newBuilder();
117115
returnMetadata.forEach(m -> m.appendTo(metadata));
116+
metadata.addAllVectors(includeVectors);
118117
references.setMetadata(metadata);
119118
}
120119

0 commit comments

Comments
 (0)