> fn) {
+ return new CollectionHandle<>(restTransport, grpcTransport, collection, CollectionHandleDefaults.of(fn));
+ }
+
+ /**
+ * Create a new Weaviate collection with default configuration.
+ *
+ * {@code
+ * // Define a record class that represents an object in collection.
+ * record Song(
+ * String title;
+ * int yearReleased;
+ * String[] genres;
+ * ) {}
+ *
+ * client.collections.create(Song.class);
+ * }
+ *
+ * @param cls Class that represents an object in the collection.
+ * @return the configuration of the created collection.
+ * @throws WeaviateApiException in case the server returned with an
+ * error status code.
+ * @throws IOException in case the request was not sent successfully
+ * due to a malformed request, a networking error
+ * or the server being unavailable.
+ * @see io.weaviate.client6.v1.api.collections.annotations.Collection
+ * @see io.weaviate.client6.v1.api.collections.annotations.Property
+ */
+ public CollectionConfig create(Class cls) throws IOException {
+ var collection = CollectionDescriptor.ofClass(cls);
+ return create(CollectionConfig.of(collection.collectionName(), collection.configFn()));
+ }
+
+ /**
+ * Create and configure a new Weaviate collection. See
+ * {@link CollectionConfig.Builder} for available options.
+ *
+ * @param cls Class that represents an object in the collection.
+ * @param fn Lamda expression for optional parameters.
+ * @return the configuration of the created collection.
+ * @throws WeaviateApiException in case the server returned with an
+ * error status code.
+ * @throws IOException in case the request was not sent successfully
+ * due to a malformed request, a networking error
+ * or the server being unavailable.
+ * @see io.weaviate.client6.v1.api.collections.annotations.Collection
+ * @see io.weaviate.client6.v1.api.collections.annotations.Property
+ * @see WeaviateCollectionsClient#create(Class)
+ */
+ public CollectionConfig create(
+ Class cls,
+ Function> fn) throws IOException {
+ var collection = CollectionDescriptor.ofClass(cls);
+ var configFn = ObjectBuilder.partial(fn, collection.configFn());
+ return create(CollectionConfig.of(collection.collectionName(), configFn));
}
/**
* Create a new Weaviate collection with default configuration.
*
+ * @param collectionName Collection name.
* @return the configuration of the created collection.
* @throws WeaviateApiException in case the server returned with an
* error status code.
@@ -59,14 +144,16 @@ public CollectionHandle