Skip to content

Commit 52b69e0

Browse files
committed
Update Samples
1 parent 91e32c0 commit 52b69e0

File tree

9 files changed

+102
-90
lines changed

9 files changed

+102
-90
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/Collection.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
import java.time.Instant;
6868
import java.util.ArrayList;
69+
import java.util.Arrays;
6970
import java.util.List;
7071
import java.util.Map;
7172
import java.util.Optional;
@@ -532,6 +533,7 @@ public final CompletableFuture<InsertOneResult> insertOneAsync(T document, float
532533
* directly within the document. This is achieved through a specified expression, which the service translates
533534
* into vector embeddings. These embeddings can then be utilized for advanced database operations that leverage
534535
* vector similarity.
536+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
535537
*
536538
* <p><b>Note:</b> As with the base {@code insertOne} method, providing an {@code _id} field that matches an existing
537539
* document's {@code _id} in the collection will cause the insertion to fail with an error. If the {@code _id} field
@@ -573,6 +575,7 @@ public final InsertOneResult insertOne(T document, String vectorize) {
573575
* provides an asynchronous counterpart to {@link #insertOne(T document, String vectorize)}, allowing for
574576
* non-blocking operations while a document, along with its vectorization based on the provided string, is
575577
* inserted into the collection.
578+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
576579
*
577580
* <p>Utilizing this method facilitates the insertion of documents in scenarios where application responsiveness
578581
* is crucial. It allows the application to continue with other tasks while the document insertion, including
@@ -845,6 +848,39 @@ public InsertManyResult insertMany(List<? extends T> documents) {
845848
return insertMany(documents, new InsertManyOptions());
846849
}
847850

851+
/**
852+
* Inserts a batch of documents into the collection using default insertion options. This method is a
853+
* simplified version of {@link #insertMany(List, InsertManyOptions)}, intended for use cases where
854+
* default settings for concurrency, chunk size, and insertion order are sufficient. It provides an
855+
* efficient way to insert multiple documents concurrently, optimizing the insertion process with
856+
* predefined settings.
857+
*
858+
* <p>The default {@link InsertManyOptions} used by this method assumes non-concurrent (sequential)
859+
* insertion, with no specific chunk size or timeout constraints. This is suitable for general use
860+
* cases where the simplicity of invocation is prioritized over the customization of insertion
861+
* parameters. For more advanced control over the insertion process, including the ability to specify
862+
* concurrency levels, chunk sizes, and operation timeouts, use the overloaded
863+
* {@link #insertMany(List, InsertManyOptions)} method.</p>
864+
*
865+
* <p>This method leverages the same underlying insertion logic as its overloaded counterpart,
866+
* ensuring consistent behavior and error handling. It automatically handles validation of the
867+
* input documents list, chunking of documents based on default settings, and aggregation of
868+
* insertion results into a single {@link InsertManyResult}.</p>
869+
*
870+
* <p><b>Usage:</b> Ideal for inserting a collection of documents without the need for custom
871+
* insertion options. Simplifies the insertion process for basic use cases.</p>
872+
*
873+
* @param documents A list of documents to be inserted. Must not be null or empty, and no document should
874+
* be null.
875+
* @return An {@link InsertManyResult} object containing the IDs of all successfully inserted documents.
876+
* @throws IllegalArgumentException if the documents list is null or empty, or if any document is null.
877+
* @throws RuntimeException if there is an error in merging the results of concurrent insertions.
878+
*/
879+
@SafeVarargs
880+
public final InsertManyResult insertMany(T... documents) {
881+
return insertMany(Arrays.asList(documents), new InsertManyOptions());
882+
}
883+
848884
/**
849885
* Asynchronously inserts a batch of documents into the collection using default insertion options. This method
850886
* provides an asynchronous alternative to {@link #insertMany(List)}, facilitating non-blocking operations while
@@ -1196,6 +1232,7 @@ public FindIterable<T> find(float[] vector, int limit) {
11961232
/**
11971233
* Finds documents in the collection that match the specified filter and sorts them based on their similarity
11981234
* to a provided vector, limiting the number of results returned.
1235+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
11991236
* <p>
12001237
* This method leverage the 'vectorization' to compute the embeddings on the fly in order to execute the search.
12011238
* </p>
@@ -1206,7 +1243,7 @@ public FindIterable<T> find(float[] vector, int limit) {
12061243
* @return A {@link FindIterable} for iterating over the sorted and limited documents.
12071244
*/
12081245
public FindIterable<T> find(Filter filter, String vectorize, int limit) {
1209-
return find(filter, FindOptions.Builder.vectorize(vectorize).limit(limit));
1246+
return find(filter, FindOptions.Builder.sort(vectorize).limit(limit));
12101247
}
12111248

12121249
/**

astra-db-java/src/main/java/com/datastax/astra/client/model/FindOneAndDeleteOptions.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public FindOneAndDeleteOptions sort(Sort... sort) {
6464
}
6565

6666
/**
67-
* Add a criteria with $vectorize in the sort clause
67+
* Add a criteria with $vectorize in the sort clause.
68+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
6869
*
6970
* @param vectorize an expression to look for vectorization
7071
* @param sorts The sort criteria to be applied to the findOne operation.
@@ -139,12 +140,13 @@ public static FindOneAndDeleteOptions projection(Projection... projection) {
139140

140141
/**
141142
* Initializes the building process with vectorize options.
143+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
142144
*
143145
* @param vectorize The vectorize criteria to be applied to the findOne operation
144146
* @param sorts The sort criteria to be applied to the findOne operation.
145147
* @return A new {@link FindOneAndDeleteOptions} instance configured with the provided vectorize criteria.
146148
*/
147-
public static FindOneAndDeleteOptions vectorize(String vectorize, Sort... sorts) {
149+
public static FindOneAndDeleteOptions sort(String vectorize, Sort... sorts) {
148150
return new FindOneAndDeleteOptions().sort(vectorize, sorts);
149151
}
150152

@@ -155,7 +157,7 @@ public static FindOneAndDeleteOptions vectorize(String vectorize, Sort... sorts)
155157
* @param sorts The sort criteria to be applied to the findOne operation.
156158
* @return A new {@link FindOneAndDeleteOptions} instance configured with the provided vector criteria.
157159
*/
158-
public static FindOneAndDeleteOptions vector(float[] vector, Sort... sorts) {
160+
public static FindOneAndDeleteOptions sort(float[] vector, Sort... sorts) {
159161
return new FindOneAndDeleteOptions().sort(vector, sorts);
160162
}
161163
}

astra-db-java/src/main/java/com/datastax/astra/client/model/FindOneAndReplaceOptions.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ public FindOneAndReplaceOptions sort(Sort... sort) {
7676

7777
/**
7878
* Add a criteria with $vectorize in the sort clause
79+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
7980
*
8081
* @param vectorize an expression to look for vectorization
8182
* @param sorts The sort criteria to be applied to the findOne operation.
8283
* @return current command
8384
*/
84-
public FindOneAndReplaceOptions vectorize(String vectorize, Sort ... sorts) {
85+
public FindOneAndReplaceOptions sort(String vectorize, Sort ... sorts) {
8586
setSort(Sorts.vectorize(vectorize));
8687
if (sorts != null) {
8788
getSort().putAll(OptionsUtils.sort(sorts));
@@ -96,7 +97,7 @@ public FindOneAndReplaceOptions vectorize(String vectorize, Sort ... sorts) {
9697
* @param sorts The sort criteria to be applied to the findOne operation.
9798
* @return current command
9899
*/
99-
public FindOneAndReplaceOptions vector(float[] vector, Sort... sorts) {
100+
public FindOneAndReplaceOptions sort(float[] vector, Sort... sorts) {
100101
setSort(Sorts.vector(vector));
101102
if (sorts != null) {
102103
getSort().putAll(OptionsUtils.sort(sorts));
@@ -215,13 +216,14 @@ public static FindOneAndReplaceOptions upsert(Boolean upsert) {
215216

216217
/**
217218
* Initializes the building process with vectorize options.
219+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
218220
*
219221
* @param vectorize The vectorize criteria to be applied to the findOne operation
220222
* @param sorts The sort criteria to be applied to the findOne operation.
221223
* @return A new {@link FindOneAndReplaceOptions} instance configured with the provided vectorize criteria.
222224
*/
223-
public static FindOneAndReplaceOptions vectorize(String vectorize, Sort... sorts) {
224-
return new FindOneAndReplaceOptions().vectorize(vectorize, sorts);
225+
public static FindOneAndReplaceOptions sort(String vectorize, Sort... sorts) {
226+
return new FindOneAndReplaceOptions().sort(vectorize, sorts);
225227
}
226228

227229
/**
@@ -231,8 +233,8 @@ public static FindOneAndReplaceOptions vectorize(String vectorize, Sort... sorts
231233
* @param sorts The sort criteria to be applied to the findOne operation.
232234
* @return A new {@link FindOneAndReplaceOptions} instance configured with the provided vector criteria.
233235
*/
234-
public static FindOneAndReplaceOptions vector(float[] vector, Sort... sorts) {
235-
return new FindOneAndReplaceOptions().vector(vector, sorts);
236+
public static FindOneAndReplaceOptions sort(float[] vector, Sort... sorts) {
237+
return new FindOneAndReplaceOptions().sort(vector, sorts);
236238
}
237239
}
238240

astra-db-java/src/main/java/com/datastax/astra/client/model/FindOneAndUpdateOptions.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public FindOneAndUpdateOptions sort(Sort... sort) {
8282
* @param sorts The sort criteria to be applied to the findOne operation.
8383
* @return current command
8484
*/
85-
public FindOneAndUpdateOptions vectorize(String vectorize, Sort ... sorts) {
85+
public FindOneAndUpdateOptions sort(String vectorize, Sort ... sorts) {
8686
setSort(Sorts.vectorize(vectorize));
8787
if (sorts != null) {
8888
getSort().putAll(OptionsUtils.sort(sorts));
@@ -97,7 +97,7 @@ public FindOneAndUpdateOptions vectorize(String vectorize, Sort ... sorts) {
9797
* @param sorts The sort criteria to be applied to the findOne operation.
9898
* @return current command
9999
*/
100-
public FindOneAndUpdateOptions vector(float[] vector, Sort... sorts) {
100+
public FindOneAndUpdateOptions sort(float[] vector, Sort... sorts) {
101101
setSort(Sorts.vector(vector));
102102
if (sorts != null) {
103103
getSort().putAll(OptionsUtils.sort(sorts));
@@ -220,8 +220,8 @@ public static FindOneAndUpdateOptions upsert(Boolean upsert) {
220220
* @param sorts The sort criteria to be applied to the findOne operation.
221221
* @return A new {@link FindOneAndUpdateOptions} instance configured with the provided vectorize criteria.
222222
*/
223-
public static FindOneAndUpdateOptions vectorize(String vectorize, Sort... sorts) {
224-
return new FindOneAndUpdateOptions().vectorize(vectorize, sorts);
223+
public static FindOneAndUpdateOptions sort(String vectorize, Sort... sorts) {
224+
return new FindOneAndUpdateOptions().sort(vectorize, sorts);
225225
}
226226

227227
/**
@@ -231,8 +231,8 @@ public static FindOneAndUpdateOptions vectorize(String vectorize, Sort... sorts)
231231
* @param sorts The sort criteria to be applied to the findOne operation.
232232
* @return A new {@link FindOneAndUpdateOptions} instance configured with the provided vector criteria.
233233
*/
234-
public static FindOneAndUpdateOptions vector(float[] vector, Sort... sorts) {
235-
return new FindOneAndUpdateOptions().vector(vector, sorts);
234+
public static FindOneAndUpdateOptions sort(float[] vector, Sort... sorts) {
235+
return new FindOneAndUpdateOptions().sort(vector, sorts);
236236
}
237237
}
238238

astra-db-java/src/main/java/com/datastax/astra/client/model/FindOneOptions.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public FindOneOptions sort(Sort... sort) {
7070

7171
/**
7272
* Add a criteria with $vectorize in the sort clause
73+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
7374
*
7475
* @param vectorize an expression to look for vectorization
7576
* @param sorts The sort criteria to be applied to the findOne operation.
@@ -156,6 +157,7 @@ public static FindOneOptions sort(float[] vector, Sort... sort) {
156157

157158
/**
158159
* Initializes the building process with sorting options.
160+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
159161
*
160162
* @param vectorize string to be vectorized in the findOne operation.
161163
* @param sort The sort criteria to be applied to the findOne operation.
@@ -184,26 +186,5 @@ public static FindOneOptions includeSimilarity() {
184186
return new FindOneOptions().includeSimilarity();
185187
}
186188

187-
/**
188-
* Initializes the building process with vectorize options.
189-
*
190-
* @param vectorize The vectorize criteria to be applied to the findOne operation
191-
* @param sorts The sort criteria to be applied to the findOne operation.
192-
* @return A new {@link FindOneOptions} instance configured with the provided vectorize criteria.
193-
*/
194-
public static FindOneOptions vectorize(String vectorize, Sort... sorts) {
195-
return new FindOneOptions().sort(vectorize, sorts);
196-
}
197-
198-
/**
199-
* Initializes the building process with vector options.
200-
*
201-
* @param vector The vector criteria to be applied to the findOne operation
202-
* @param sorts The sort criteria to be applied to the findOne operation.
203-
* @return A new {@link FindOneOptions} instance configured with the provided vector criteria.
204-
*/
205-
public static FindOneOptions vector(float[] vector, Sort... sorts) {
206-
return new FindOneOptions().sort(vector, sorts);
207-
}
208189
}
209190
}

astra-db-java/src/main/java/com/datastax/astra/client/model/FindOptions.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public FindOptions sort(Sort... sort) {
8585
}
8686

8787
/**
88-
* Add a criteria with $vectorize in the sort clause
88+
* Add a criteria with $vectorize in the sort clause.
89+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
8990
*
9091
* @param vectorize an expression to look for vectorization
9192
* @param sorts The sort criteria to be applied to the findOne operation.
@@ -211,6 +212,7 @@ public static FindOptions sort(float[] vector, Sort... sort) {
211212

212213
/**
213214
* Initializes the building process with sorting options.
215+
* <p><i style='color: orange;'><b>Note</b> : This feature is under current development.</i></p>
214216
*
215217
* @param vectorize string to be vectorized in the findOne operation.
216218
* @param sort The sort criteria to be applied to the findOne operation.
@@ -259,26 +261,5 @@ public static FindOptions limit(int limit) {
259261
return new FindOptions().limit(limit);
260262
}
261263

262-
/**
263-
* Initializes the building process with vectorize options.
264-
*
265-
* @param vectorize The vectorize criteria to be applied to the findOne operation
266-
* @param sort The sort criteria to be applied to the findOne operation.
267-
* @return A new {@link FindOneOptions} instance configured with the provided vectorize criteria.
268-
*/
269-
public static FindOptions vectorize(String vectorize, Sort ... sort) {
270-
return new FindOptions().sort(vectorize, sort);
271-
}
272-
273-
/**
274-
* Initializes the building process with vector options.
275-
*
276-
* @param vector The vector criteria to be applied to the findOne operation
277-
* @param sort The sort criteria to be applied to the findOne operation.
278-
* @return A new {@link FindOneOptions} instance configured with the provided vector criteria.
279-
*/
280-
public static FindOptions vector(float[] vector, Sort ... sort) {
281-
return new FindOptions().sort(vector, sort);
282-
}
283264
}
284265
}

astra-db-java/src/test/java/com/datastax/astra/test/integration/collection/VectorizePreviewITTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.UUID;
1717
import java.util.stream.Collectors;
1818

19-
import static com.datastax.astra.client.model.FindOptions.Builder.vectorize;
19+
import static com.datastax.astra.client.model.FindOptions.Builder.sort;
2020
import static org.assertj.core.api.Assertions.assertThat;
2121

2222
/**
@@ -69,7 +69,7 @@ void shouldInsertOneDocumentWithVectorize() {
6969
@Test
7070
void testFindVectorize() {
7171
List<Document> doclist = collectionVectorize
72-
.find(vectorize("Life is too short for Javascript"))
72+
.find(sort("Life is too short for Javascript"))
7373
.all();
7474
assertThat(doclist).isNotNull().isNotEmpty();
7575
}

0 commit comments

Comments
 (0)