Skip to content

Commit 0131d53

Browse files
authored
Merge pull request #468 from weaviate/v6-write-the-docs
v6: Update README.md and write Javadoc
2 parents 725ef52 + bb09b02 commit 0131d53

41 files changed

Lines changed: 2927 additions & 98 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 644 additions & 1 deletion
Large diffs are not rendered by default.

assets/duke-client6.png

238 KB
Loading

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,37 @@ private WeaviateApiException(String method, String endpoint, int statusCode, Str
4343
this.grpcStatusCode = null;
4444
}
4545

46+
/** Get raw error message. */
47+
public String getError() {
48+
return errorMessage;
49+
}
50+
51+
/** Check if the exception originates from the gRPC transport. */
4652
public boolean isGPRC() {
4753
return source == Source.GRPC;
4854
}
4955

56+
/** Get the gRPC status code. */
5057
public String grpcStatusCode() {
58+
if (!isGPRC()) {
59+
return null;
60+
}
5161
return grpcStatusCode.toString();
5262
}
5363

64+
/** Check if the exception originates from the HTTP transport. */
5465
public boolean isHTTP() {
5566
return source == Source.HTTP;
5667
}
5768

69+
/** Get the endpoint that the failed request was sent to. */
5870
public String endpoint() {
5971
return endpoint;
6072
}
6173

74+
/** Get the HTTP status code. */
6275
public Integer httpStatusCode() {
6376
return httpStatusCode;
6477
}
6578

66-
public String getError() {
67-
return errorMessage;
68-
}
6979
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,27 @@
2323
import io.weaviate.client6.v1.internal.ObjectBuilder;
2424

2525
public record CollectionConfig(
26+
/** Collection name. */
2627
@SerializedName("class") String collectionName,
28+
/** Collection description. */
2729
@SerializedName("description") String description,
30+
/** Collection properties. */
2831
@SerializedName("properties") List<Property> properties,
32+
/** Cross-reference properties. */
2933
List<ReferenceProperty> references,
34+
/** Vector indexes configured for this collection. */
3035
@SerializedName("vectorConfig") Map<String, VectorConfig> vectors,
36+
/** Multi-tenantcy options. */
3137
@SerializedName("multiTenancyConfig") MultiTenancy multiTenancy,
38+
/** Sharding configuration. */
3239
@SerializedName("shardingConfig") Sharding sharding,
40+
/** Replication configuration. */
3341
@SerializedName("replicationConfig") Replication replication,
42+
/** Inverted index configuration. */
3443
@SerializedName("invertedIndexConfig") InvertedIndex invertedIndex,
44+
/** Reranker modules. */
3545
List<Reranker> rerankerModules,
46+
/** Generative modules. */
3647
Generative generativeModule) {
3748

3849
public static CollectionConfig of(String collectionName) {
@@ -100,15 +111,26 @@ public Builder(String collectionName) {
100111
this.collectionName = collectionName;
101112
}
102113

114+
/** Add collection description. */
103115
public Builder description(String description) {
104116
this.description = description;
105117
return this;
106118
}
107119

120+
/**
121+
* Add collection properties.
122+
*
123+
* @see Property
124+
*/
108125
public Builder properties(Property... properties) {
109126
return properties(Arrays.asList(properties));
110127
}
111128

129+
/**
130+
* Add collection properties.
131+
*
132+
* @see Property
133+
*/
112134
public Builder properties(List<Property> properties) {
113135
properties.forEach(property -> this.properties.put(property.propertyName(), property));
114136
return this;
@@ -118,10 +140,20 @@ private List<Property> propertyList() {
118140
return this.properties.values().stream().toList();
119141
}
120142

143+
/**
144+
* Add cross-reference properties.
145+
*
146+
* @see ReferenceProperty#to
147+
*/
121148
public Builder references(ReferenceProperty... references) {
122149
return references(Arrays.asList(references));
123150
}
124151

152+
/**
153+
* Add cross-reference properties.
154+
*
155+
* @see ReferenceProperty#to
156+
*/
125157
public Builder references(List<ReferenceProperty> references) {
126158
references.forEach(reference -> this.references.put(reference.propertyName(), reference));
127159
return this;
@@ -131,66 +163,83 @@ private List<ReferenceProperty> referenceList() {
131163
return this.references.values().stream().toList();
132164
}
133165

166+
/** Add vector index configurations. */
134167
public final Builder vectorConfig(Map<String, VectorConfig> vectors) {
135168
this.vectors.putAll(vectors);
136169
return this;
137170
}
138171

172+
/**
173+
* Add vector index configurations.
174+
*
175+
* @see VectorConfig
176+
*/
139177
@SafeVarargs
140178
public final Builder vectorConfig(Map.Entry<String, VectorConfig>... vectors) {
141179
this.vectors.putAll(Map.ofEntries(vectors));
142180
return this;
143181
}
144182

183+
/** Configure collection's sharding. */
145184
public Builder sharding(Sharding sharding) {
146185
this.sharding = sharding;
147186
return this;
148187
}
149188

189+
/** Configure collection's sharding. */
150190
public Builder sharding(Function<Sharding.Builder, ObjectBuilder<Sharding>> fn) {
151191
this.sharding = Sharding.of(fn);
152192
return this;
153193
}
154194

195+
/** Configure multi-tenancy. */
155196
public Builder multiTenancy(MultiTenancy multiTenancy) {
156197
this.multiTenancy = multiTenancy;
157198
return this;
158199
}
159200

201+
/** Configure multi-tenancy. */
160202
public Builder multiTenancy(Function<MultiTenancy.Builder, ObjectBuilder<MultiTenancy>> fn) {
161203
this.multiTenancy = MultiTenancy.of(fn);
162204
return this;
163205
}
164206

207+
/** Configure replication. */
165208
public Builder replication(Replication replication) {
166209
this.replication = replication;
167210
return this;
168211
}
169212

213+
/** Configure replication. */
170214
public Builder replication(Function<Replication.Builder, ObjectBuilder<Replication>> fn) {
171215
this.replication = Replication.of(fn);
172216
return this;
173217
}
174218

219+
/** Change inverted index configurations. */
175220
public Builder invertedIndex(InvertedIndex invertedIndex) {
176221
this.invertedIndex = invertedIndex;
177222
return this;
178223
}
179224

225+
/** Change inverted index configurations. */
180226
public Builder invertedIndex(Function<InvertedIndex.Builder, ObjectBuilder<InvertedIndex>> fn) {
181227
this.invertedIndex = InvertedIndex.of(fn);
182228
return this;
183229
}
184230

231+
/** Add reranker modules. */
185232
public Builder rerankerModules(Reranker... rerankerModules) {
186233
return rerankerModules(Arrays.asList(rerankerModules));
187234
}
188235

236+
/** Add reranker modules. */
189237
public Builder rerankerModules(List<Reranker> rerankerModules) {
190238
this.rerankerModules.addAll(rerankerModules);
191239
return this;
192240
}
193241

242+
/** Add a generative module. */
194243
public Builder generativeModule(Generative generativeModule) {
195244
this.generativeModule = generativeModule;
196245
return this;

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,39 @@ private CollectionHandle(CollectionHandle<PropertiesT> c, CollectionHandleDefaul
4949
this.tenants = c.tenants;
5050
}
5151

52+
/**
53+
* Create a Paginator over the objects in this collection.
54+
*
55+
* <p>
56+
* Usage:
57+
*
58+
* <pre>
59+
* {@code
60+
* var things = client.collections.use("Things");
61+
*
62+
* // In a for-loop:
63+
* for (final var thing : things.paginate()) {
64+
* // ... do something for each Thing object
65+
* }
66+
*
67+
* // As a stream
68+
* things.paginate().stream()
69+
* .map(...)
70+
* .collect(...);
71+
* }</pre>
72+
*
73+
* @return An {@link Iterable} over this collection's objects.
74+
*/
5275
public Paginator<PropertiesT> paginate() {
5376
return Paginator.of(this.query);
5477
}
5578

79+
/**
80+
* Create a Paginator over the objects in this collection.
81+
*
82+
* @param fn Lambda expression for optional parameters.
83+
* @return An {@link Iterable} over this collection's objects.
84+
*/
5685
public Paginator<PropertiesT> paginate(
5786
Function<Paginator.Builder<PropertiesT>, ObjectBuilder<Paginator<PropertiesT>>> fn) {
5887
return Paginator.of(this.query, fn);
@@ -68,7 +97,7 @@ public Paginator<PropertiesT> paginate(
6897
* collection exceeds {@link Long#MAX_VALUE} as this is unlikely to happen.
6998
*
7099
* <p>
71-
* This is a shortcut for:
100+
* This is a shorthand for:
72101
*
73102
* <pre>{@code
74103
* handle.aggregate.overAll(all -> all.includeTotalCount(true)).totalCount()
@@ -78,22 +107,30 @@ public long size() {
78107
return this.aggregate.overAll(all -> all.includeTotalCount(true)).totalCount();
79108
}
80109

110+
/** Default consistency level for requests. */
81111
public ConsistencyLevel consistencyLevel() {
82112
return defaults.consistencyLevel();
83113
}
84114

115+
/** Obtain a collection handle with a different consistency level. */
85116
public CollectionHandle<PropertiesT> withConsistencyLevel(ConsistencyLevel consistencyLevel) {
86117
return new CollectionHandle<>(this, CollectionHandleDefaults.of(with -> with.consistencyLevel(consistencyLevel)));
87118
}
88119

120+
/** Default tenant for requests. */
89121
public String tenant() {
90122
return defaults.tenant();
91123
}
92124

125+
/** Obtain a collection handle with a different target tenant. */
93126
public CollectionHandle<PropertiesT> withTenant(String tenant) {
94127
return new CollectionHandle<>(this, CollectionHandleDefaults.of(with -> with.tenant(tenant)));
95128
}
96129

130+
/**
131+
* Obtain a collection handle with different defaults
132+
* (consistency level / tenant).
133+
*/
97134
public CollectionHandle<PropertiesT> withDefaults(
98135
Function<CollectionHandleDefaults.Builder, ObjectBuilder<CollectionHandleDefaults>> fn) {
99136
return new CollectionHandle<>(this, CollectionHandleDefaults.of(fn));

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,31 @@ public CompletableFuture<Long> size() {
8585
.thenApply(AggregateResponse::totalCount);
8686
}
8787

88+
/** Default consistency level for requests. */
8889
public ConsistencyLevel consistencyLevel() {
8990
return defaults.consistencyLevel();
9091
}
9192

93+
/** Obtain a collection handle with a different consistency level. */
9294
public CollectionHandleAsync<PropertiesT> withConsistencyLevel(ConsistencyLevel consistencyLevel) {
9395
return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(
9496
def -> def.consistencyLevel(consistencyLevel)));
9597
}
9698

99+
/** Default tenant for requests. */
97100
public String tenant() {
98101
return defaults.tenant();
99102
}
100103

104+
/** Obtain a collection handle with a different target tenant. */
101105
public CollectionHandleAsync<PropertiesT> withTenant(String tenant) {
102106
return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(with -> with.tenant(tenant)));
103107
}
104108

109+
/**
110+
* Obtain a collection handle with different defaults
111+
* (consistency level / tenant).
112+
*/
105113
public CollectionHandleAsync<PropertiesT> withDefaults(
106114
Function<CollectionHandleDefaults.Builder, ObjectBuilder<CollectionHandleDefaults>> fn) {
107115
return new CollectionHandleAsync<>(this, CollectionHandleDefaults.of(fn));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public CollectionHandleDefaults build() {
5454
}
5555
}
5656

57+
/** Serialize default values to a URL query. */
5758
public Map<String, Object> queryParameters() {
5859
if (consistencyLevel == null && tenant == null) {
5960
return Collections.emptyMap();

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ public interface DataType {
1919
public static final String UUID = "uuid";
2020
public static final String UUID_ARRAY = "uuid[]";
2121

22+
/**
23+
* Scalar/array types which Weaviate and WeaviateClient recognize.
24+
*
25+
* <p>
26+
* Other data types are considered reference types, i.e. if a user creates a
27+
* property with type {@code "timestamp"}, the client will count it a
28+
* cross-reference to the {@code "timestamp"} collection.
29+
*
30+
* This is obviously wrong, so it is recommended to always create properties
31+
* using {@link Property}'s factory classes.
32+
*/
2233
public static final Set<String> KNOWN_TYPES = ImmutableSet.of(
2334
TEXT, INT, BLOB, BOOL, DATE, UUID, NUMBER,
2435
TEXT_ARRAY, INT_ARRAY, NUMBER_ARRAY, BOOL_ARRAY, DATE_ARRAY, UUID_ARRAY);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ public static Kind valueOfJson(String jsonValue) {
4242

4343
Object _self();
4444

45+
/** Configure a default Cohere generative module. */
4546
public static Generative cohere() {
4647
return CohereGenerative.of();
4748
}
4849

50+
/**
51+
* Configure a Cohere generative module.
52+
*
53+
* @param fn Lambda expression for optional parameters.
54+
*/
4955
public static Generative cohere(Function<CohereGenerative.Builder, ObjectBuilder<CohereGenerative>> fn) {
5056
return CohereGenerative.of(fn);
5157
}

0 commit comments

Comments
 (0)