23
23
import com .datastax .astra .client .exception .DataApiException ;
24
24
import com .datastax .astra .client .exception .DataApiFaultyResponseException ;
25
25
import com .datastax .astra .client .exception .TooManyDocumentsToCountException ;
26
- import com .datastax .astra .client .model .Command ;
27
- import com .datastax .astra .client .model .Document ;
28
- import com .datastax .astra .internal .ApiResponse ;
29
- import com .datastax .astra .client .model .CollectionDefinition ;
26
+ import com .datastax .astra .client .model .BulkWriteOptions ;
27
+ import com .datastax .astra .client .model .BulkWriteResult ;
28
+ import com .datastax .astra .client .model .CollectionInfo ;
30
29
import com .datastax .astra .client .model .CollectionOptions ;
30
+ import com .datastax .astra .client .model .Command ;
31
31
import com .datastax .astra .client .model .DeleteOneOptions ;
32
32
import com .datastax .astra .client .model .DeleteResult ;
33
+ import com .datastax .astra .client .model .DistinctIterable ;
34
+ import com .datastax .astra .client .model .Document ;
33
35
import com .datastax .astra .client .model .Filter ;
34
36
import com .datastax .astra .client .model .Filters ;
37
+ import com .datastax .astra .client .model .FindIterable ;
35
38
import com .datastax .astra .client .model .FindOneAndDeleteOptions ;
36
39
import com .datastax .astra .client .model .FindOneAndReplaceOptions ;
37
40
import com .datastax .astra .client .model .FindOneAndReplaceResult ;
41
44
import com .datastax .astra .client .model .InsertManyOptions ;
42
45
import com .datastax .astra .client .model .InsertManyResult ;
43
46
import com .datastax .astra .client .model .InsertOneResult ;
44
- import com .datastax .astra .client .model .DistinctIterable ;
45
- import com .datastax .astra .client .model .FindIterable ;
46
47
import com .datastax .astra .client .model .Page ;
47
- import com .datastax .astra .client .model .BulkWriteOptions ;
48
- import com .datastax .astra .client .model .BulkWriteResult ;
49
48
import com .datastax .astra .client .model .ReplaceOneOptions ;
50
49
import com .datastax .astra .client .model .Update ;
51
50
import com .datastax .astra .client .model .UpdateOneOptions ;
52
51
import com .datastax .astra .client .model .UpdateResult ;
53
52
import com .datastax .astra .internal .AbstractCommandRunner ;
53
+ import com .datastax .astra .internal .ApiResponse ;
54
54
import com .datastax .astra .internal .utils .Assert ;
55
55
import com .datastax .astra .internal .utils .JsonUtils ;
56
56
import lombok .Getter ;
78
78
79
79
/**
80
80
* A Data API collection, the main object to interact with the Data API, especially for DDL operations.
81
- * This class has a synchronous and asynchronous signature for all operations.
82
81
* <p>
83
- * A Collection is spawned from a DataApiNameSpace object, from which it inherits the details on how to reach the API server
82
+ * A Collection is spawned from a Database object, from which it inherits the details on how to reach the API server
84
83
* (endpoint, authentication). A Collection has a name, which is its unique identifier for a namespace and
85
84
* options to specialize the usage as vector collections or advanced indexing parameters.
86
85
* </p>
87
86
* <p>
88
87
* A Collection is typed object designed to work both with default @{@link Document} (wrapper for a Map) and application
89
88
* plain old java objects (pojo). The serialization is performed with Jackson and application beans can be annotated.
90
89
* </p>
90
+ * <p>
91
+ * All features are provided in synnchronous and asynchronous flavore
92
+ * </p>
91
93
* <p>Example usage:</p>
92
94
* <pre>
93
95
* {@code
@@ -120,7 +122,7 @@ public class Collection<DOC> extends AbstractCommandRunner {
120
122
private final Database database ;
121
123
122
124
/** Api Endpoint for the Database. */
123
- private final String apiEndpointCollection ;
125
+ private final String apiEndpoint ;
124
126
125
127
/**
126
128
* Full constructor.
@@ -139,7 +141,7 @@ protected Collection(Database db, String collectionName, Class<DOC> clazz) {
139
141
this .collectionName = collectionName ;
140
142
this .database = db ;
141
143
this .documentClass = clazz ;
142
- this .apiEndpointCollection = db .getApiEndpointDatabase () + "/" + collectionName ;
144
+ this .apiEndpoint = db .getApiEndpoint () + "/" + collectionName ;
143
145
}
144
146
145
147
// ----------------------------
@@ -174,7 +176,7 @@ public String getNamespaceName() {
174
176
*
175
177
* @return the full collection definition
176
178
*/
177
- public CollectionDefinition getDefinition () {
179
+ public CollectionInfo getDefinition () {
178
180
return database
179
181
.listCollections ()
180
182
.filter (col -> col .getName ().equals (collectionName ))
@@ -461,20 +463,6 @@ public Optional<DOC> findOne(Filter filter, FindOneOptions options) {
461
463
.map (getDocumentClass ()));
462
464
}
463
465
464
- /**
465
- * Finds all documents in the collection.
466
- *
467
- * @param filter
468
- * the query filter
469
- * @param options
470
- * options of find one
471
- * @return
472
- * the find iterable interface
473
- */
474
- public FindIterable <DOC > find (Filter filter , FindOptions options ) {
475
- return new FindIterable <>(this , filter , options );
476
- }
477
-
478
466
/**
479
467
* Initiates an asynchronous search to find a single document that matches the given filter criteria.
480
468
* This method leverages the functionality of to perform the
@@ -511,6 +499,20 @@ public Optional<DOC> findById(Object id) {
511
499
return findOne (Filters .eq (id ));
512
500
}
513
501
502
+ /**
503
+ * Finds all documents in the collection.
504
+ *
505
+ * @param filter
506
+ * the query filter
507
+ * @param options
508
+ * options of find one
509
+ * @return
510
+ * the find iterable interface
511
+ */
512
+ public FindIterable <DOC > find (Filter filter , FindOptions options ) {
513
+ return new FindIterable <>(this , filter , options );
514
+ }
515
+
514
516
/**
515
517
* Retrieves all documents in the collection.
516
518
* <p>
@@ -553,7 +555,29 @@ public FindIterable<DOC> find(Filter filter) {
553
555
* @return A {@link FindIterable} for iterating over the sorted and limited documents.
554
556
*/
555
557
public FindIterable <DOC > find (Filter filter , float [] vector , int limit ) {
556
- return find (filter , new FindOptions ().sortingByVector (vector ).limit (limit ));
558
+ return find (filter , FindOptions .builder ()
559
+ .withVector (vector )
560
+ .limit (limit )
561
+ .build ());
562
+ }
563
+
564
+ /**
565
+ * Finds documents in the collection that match the specified filter and sorts them based on their similarity
566
+ * to a provided vector, limiting the number of results returned.
567
+ * <p>
568
+ * This method leverage the 'vectorization' to compute the embeddings on the fly in order to execute the search.
569
+ * </p>
570
+ *
571
+ * @param filter The query filter to apply when retrieving documents.
572
+ * @param vectorize A float array representing the vector used to sort the documents.
573
+ * @param limit The maximum number of documents to return.
574
+ * @return A {@link FindIterable} for iterating over the sorted and limited documents.
575
+ */
576
+ public FindIterable <DOC > find (Filter filter , String vectorize , int limit ) {
577
+ return find (filter , FindOptions .builder ()
578
+ .withVectorize (vectorize )
579
+ .limit (limit )
580
+ .build ());
557
581
}
558
582
559
583
/**
@@ -1271,7 +1295,7 @@ public BulkWriteResult bulkWrite(List<Command> commands, BulkWriteOptions option
1271
1295
/** {@inheritDoc} */
1272
1296
@ Override
1273
1297
protected String getApiEndpoint () {
1274
- return apiEndpointCollection ;
1298
+ return apiEndpoint ;
1275
1299
}
1276
1300
1277
1301
/** {@inheritDoc} */
0 commit comments