@@ -21,6 +21,14 @@ public WeaviateCollectionsClient(RestTransport restTransport, GrpcTransport grpc
2121 this .grpcTransport = grpcTransport ;
2222 }
2323
24+ /**
25+ * Obtain a handle to send requests to a particular collection.
26+ * The returned object is thread-safe.
27+ *
28+ * @param cls Class that represents an object in the collection.
29+ * @return a handle for a collection with {@code Class<PropertiesT>}
30+ * properties.
31+ */
2432 public <PropertiesT extends Record > CollectionHandle <PropertiesT > use (Class <PropertiesT > cls ) {
2533 return use (CollectionDescriptor .ofClass (cls ), CollectionHandleDefaults .none ());
2634 }
@@ -29,6 +37,22 @@ public <PropertiesT extends Record> CollectionHandle<PropertiesT> use(Class<Prop
2937 * Obtain a handle to send requests to a particular collection.
3038 * The returned object is thread-safe.
3139 *
40+ * @param cls Class that represents an object in the collection.
41+ * @param fn Lamda expression for optional parameters.
42+ * @return a handle for a collection with {@code Class<PropertiesT>}
43+ * properties.
44+ */
45+ public <PropertiesT extends Record > CollectionHandle <PropertiesT > use (
46+ Class <PropertiesT > cls ,
47+ Function <CollectionHandleDefaults .Builder , ObjectBuilder <CollectionHandleDefaults >> fn ) {
48+ return use (CollectionDescriptor .ofClass (cls ), fn );
49+ }
50+
51+ /**
52+ * Obtain a handle to send requests to a particular collection.
53+ * The returned object is thread-safe.
54+ *
55+ * @param collectionName Name of the collection.
3256 * @return a handle for a collection with {@code Map<String, Object>}
3357 * properties.
3458 */
@@ -40,6 +64,8 @@ public CollectionHandle<Map<String, Object>> use(String collectionName) {
4064 * Obtain a handle to send requests to a particular collection.
4165 * The returned object is thread-safe.
4266 *
67+ * @param collectionName Name of the collection.
68+ * @param fn Lamda expression for optional parameters.
4369 * @return a handle for a collection with {@code Map<String, Object>}
4470 * properties.
4571 */
@@ -54,39 +80,90 @@ private <PropertiesT> CollectionHandle<PropertiesT> use(CollectionDescriptor<Pro
5480 return new CollectionHandle <>(restTransport , grpcTransport , collection , CollectionHandleDefaults .of (fn ));
5581 }
5682
83+ /**
84+ * Create a new Weaviate collection with default configuration.
85+ *
86+ * <pre>{@code
87+ * // Define a record class that represents an object in collection.
88+ * record Song(
89+ * String title;
90+ * int yearReleased;
91+ * String[] genres;
92+ * ) {}
93+ *
94+ * client.collections.create(Song.class);
95+ * }</pre>
96+ *
97+ * @param cls Class that represents an object in the collection.
98+ * @return the configuration of the created collection.
99+ * @throws WeaviateApiException in case the server returned with an
100+ * error status code.
101+ * @throws IOException in case the request was not sent successfully
102+ * due to a malformed request, a networking error
103+ * or the server being unavailable.
104+ * @see io.weaviate.client6.v1.api.collections.annotations.Collection
105+ * @see io.weaviate.client6.v1.api.collections.annotations.Property
106+ */
57107 public <PropertiesT extends Record > CollectionConfig create (Class <PropertiesT > cls ) throws IOException {
58108 var collection = CollectionDescriptor .ofClass (cls );
59109 return create (CollectionConfig .of (collection .name (), collection .configFn ()));
60110 }
61111
112+ /**
113+ * Create and configure a new Weaviate collection. See
114+ * {@link CollectionConfig.Builder} for available options.
115+ *
116+ * @param cls Class that represents an object in the collection.
117+ * @param fn Lamda expression for optional parameters.
118+ * @return the configuration of the created collection.
119+ * @throws WeaviateApiException in case the server returned with an
120+ * error status code.
121+ * @throws IOException in case the request was not sent successfully
122+ * due to a malformed request, a networking error
123+ * or the server being unavailable.
124+ * @see io.weaviate.client6.v1.api.collections.annotations.Collection
125+ * @see io.weaviate.client6.v1.api.collections.annotations.Property
126+ * @see WeaviateCollectionsClient#create(Class)
127+ */
128+ public <PropertiesT extends Record > CollectionConfig create (
129+ Class <PropertiesT > cls ,
130+ Function <CollectionConfig .Builder , ObjectBuilder <CollectionConfig >> fn ) throws IOException {
131+ var collection = CollectionDescriptor .ofClass (cls );
132+ var configFn = ObjectBuilder .partial (fn , collection .configFn ());
133+ return create (CollectionConfig .of (collection .name (), configFn ));
134+ }
135+
62136 /**
63137 * Create a new Weaviate collection with default configuration.
64138 *
139+ * @param collectionName Collection name.
65140 * @return the configuration of the created collection.
66141 * @throws WeaviateApiException in case the server returned with an
67142 * error status code.
68143 * @throws IOException in case the request was not sent successfully
69144 * due to a malformed request, a networking error
70145 * or the server being unavailable.
71146 */
72- public CollectionConfig create (String name ) throws IOException {
73- return create (CollectionConfig .of (name ));
147+ public CollectionConfig create (String collectionName ) throws IOException {
148+ return create (CollectionConfig .of (collectionName ));
74149 }
75150
76151 /**
77152 * Create and configure a new Weaviate collection. See
78153 * {@link CollectionConfig.Builder} for available options.
79154 *
155+ * @param collectionName Collection name.
156+ * @param fn Lamda expression for optional parameters.
80157 * @return the configuration of the created collection.
81158 * @throws WeaviateApiException in case the server returned with an
82159 * error status code.
83160 * @throws IOException in case the request was not sent successfully
84161 * due to a malformed request, a networking error
85162 * or the server being unavailable.
86163 */
87- public CollectionConfig create (String name ,
164+ public CollectionConfig create (String collectionName ,
88165 Function <CollectionConfig .Builder , ObjectBuilder <CollectionConfig >> fn ) throws IOException {
89- return create (CollectionConfig .of (name , fn ));
166+ return create (CollectionConfig .of (collectionName , fn ));
90167 }
91168
92169 /**
@@ -107,15 +184,16 @@ public CollectionConfig create(CollectionConfig collection) throws IOException {
107184 /**
108185 * Fetch Weaviate collection configuration.
109186 *
187+ * @param collectionName Collection name.
110188 * @return the collection configuration if one with this name exists.
111189 * @throws WeaviateApiException in case the server returned with an
112190 * error status code.
113191 * @throws IOException in case the request was not sent successfully
114192 * due to a malformed request, a networking error
115193 * or the server being unavailable.
116194 */
117- public Optional <CollectionConfig > getConfig (String name ) throws IOException {
118- return this .restTransport .performRequest (new GetConfigRequest (name ), GetConfigRequest ._ENDPOINT );
195+ public Optional <CollectionConfig > getConfig (String collectionName ) throws IOException {
196+ return this .restTransport .performRequest (new GetConfigRequest (collectionName ), GetConfigRequest ._ENDPOINT );
119197 }
120198
121199 /**
@@ -135,14 +213,15 @@ public List<CollectionConfig> list() throws IOException {
135213 /**
136214 * Delete a Weaviate collection.
137215 *
216+ * @param collectionName Collection name.
138217 * @throws WeaviateApiException in case the server returned with an
139218 * error status code.
140219 * @throws IOException in case the request was not sent successfully
141220 * due to a malformed request, a networking error
142221 * or the server being unavailable.
143222 */
144- public void delete (String name ) throws IOException {
145- this .restTransport .performRequest (new DeleteCollectionRequest (name ), DeleteCollectionRequest ._ENDPOINT );
223+ public void delete (String collectionName ) throws IOException {
224+ this .restTransport .performRequest (new DeleteCollectionRequest (collectionName ), DeleteCollectionRequest ._ENDPOINT );
146225 }
147226
148227 /**
@@ -163,13 +242,14 @@ public void deleteAll() throws IOException {
163242 /**
164243 * Check if a collection with this name exists.
165244 *
245+ * @param collectionName Collection name.
166246 * @throws WeaviateApiException in case the server returned with an
167247 * error status code.
168248 * @throws IOException in case the request was not sent successfully
169249 * due to a malformed request, a networking error
170250 * or the server being unavailable.
171251 */
172- public boolean exists (String name ) throws IOException {
173- return getConfig (name ).isPresent ();
252+ public boolean exists (String collectionName ) throws IOException {
253+ return getConfig (collectionName ).isPresent ();
174254 }
175255}
0 commit comments