Skip to content

Commit d878310

Browse files
committed
fix support of vector, remove javadocs warning
1 parent 41f8cd9 commit d878310

Some content is hidden

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

41 files changed

+563
-28
lines changed

astra-db-java-tools/src/main/java/com/datastax/astra/tool/loader/rag/ingestion/RagEmbeddingsModels.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.datastax.astra.tool.loader.rag.ingestion;
22

33
public enum RagEmbeddingsModels {
4+
/** Embedding models */
45
NVIDIA_NEMO("nvidia", "NV-Embed-QA", 1024),
56
OPENAI_ADA002("open-ai", "text-embedding-ada-002", 1536),
67
OPENAI_3_SMALL("open-ai", "text-embedding-3-small", 1536),

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

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,8 @@ public CollectionFindCursor<T, T> find(Filter filter, CollectionFindOptions opti
10171017
* options of find one
10181018
* @param newDocType
10191019
* new class for return objects if projected
1020+
* @param <R>
1021+
* type of new class for return objects if projected
10201022
* @return
10211023
* the find iterable interface
10221024
*/
@@ -1061,49 +1063,123 @@ public CollectionFindCursor<T, T> findAll() {
10611063
return find(null, new CollectionFindOptions());
10621064
}
10631065

1066+
/**
1067+
* Fine document with pagination with no projection.
1068+
* @param filter
1069+
* filter on documents
1070+
* @param options
1071+
* options lilke sorting
1072+
* @return
1073+
* a page of results
1074+
*/
10641075
public Page<T> findPage(Filter filter, CollectionFindOptions options) {
10651076
return findPage(filter, options, getDocumentClass());
10661077
}
10671078

1068-
10691079
// -----------------------------
10701080
// --- Find and Rerank ----
10711081
// -----------------------------
10721082

10731083
/**
1074-
* Finds all documents in the collection.
1084+
* Finds and reranks all documents in the collection using the specified options.
1085+
* This is a convenience method equivalent to calling {@link #findAndRerank(Filter, CollectionFindAndRerankOptions)} with a {@code null} filter.
10751086
*
10761087
* @param options
1077-
* options of find one
1088+
* the options used to customize the find and rerank operation
10781089
* @return
1079-
* the find iterable interface
1090+
* a {@link CollectionFindAndRerankCursor} to iterate over the reranked documents
1091+
*
1092+
* <p>Example usage:</p>
1093+
* <pre>
1094+
* {@code
1095+
* CollectionFindAndRerankOptions options = new CollectionFindAndRerankOptions();
1096+
* CollectionFindAndRerankCursor<Document, Document> cursor = collection.findAndRerank(options);
1097+
* }
1098+
* </pre>
10801099
*/
10811100
@BetaPreview
10821101
public CollectionFindAndRerankCursor<T,T> findAndRerank(CollectionFindAndRerankOptions options) {
10831102
return findAndRerank(null, options, getDocumentClass());
10841103
}
10851104

10861105
/**
1087-
* Finds all documents in the collection.
1106+
* Finds and reranks documents in the collection that match the given filter using the specified options.
10881107
*
10891108
* @param filter
1090-
* the query filter
1109+
* the query filter to apply to the collection
10911110
* @param options
1092-
* options of find one
1111+
* the options used to customize the find and rerank operation
10931112
* @return
1094-
* the find iterable interface
1113+
* a {@link CollectionFindAndRerankCursor} to iterate over the reranked documents
1114+
*
1115+
* <p>Example usage:</p>
1116+
* <pre>
1117+
* {@code
1118+
* Filter filter = Filters.eq("status", "active");
1119+
* CollectionFindAndRerankOptions options = new CollectionFindAndRerankOptions();
1120+
* CollectionFindAndRerankCursor<Document, Document> cursor = collection.findAndRerank(filter, options);
1121+
* }
1122+
* </pre>
10951123
*/
10961124
@BetaPreview
10971125
public CollectionFindAndRerankCursor<T,T> findAndRerank(Filter filter, CollectionFindAndRerankOptions options) {
10981126
return findAndRerank(filter, options, getDocumentClass());
10991127
}
11001128

1129+
/**
1130+
* Finds and reranks documents in the collection that match the given filter using the specified options,
1131+
* mapping the resulting documents to the specified target type.
1132+
*
1133+
* @param filter
1134+
* the query filter to apply to the collection
1135+
* @param options
1136+
* the options used to customize the find and rerank operation
1137+
* @param newRowType
1138+
* the target class type to map the results to
1139+
* @param <R>
1140+
* the type of the result rows after mapping
1141+
* @return
1142+
* a {@link CollectionFindAndRerankCursor} to iterate over the reranked documents mapped to {@code R}
1143+
*
1144+
* <p>Example usage:</p>
1145+
* <pre>
1146+
* {@code
1147+
* Filter filter = Filters.eq("type", "book");
1148+
* CollectionFindAndRerankOptions options = new CollectionFindAndRerankOptions();
1149+
* CollectionFindAndRerankCursor<Document, Book> cursor = collection.findAndRerank(filter, options, Book.class);
1150+
* }
1151+
* </pre>
1152+
*/
11011153
@BetaPreview
11021154
public <R> CollectionFindAndRerankCursor<T, R> findAndRerank(Filter filter, CollectionFindAndRerankOptions options, Class<R> newRowType) {
11031155
return new CollectionFindAndRerankCursor<>(this, filter, options, newRowType);
11041156
}
11051157

11061158

1159+
/**
1160+
* Finds and reranks documents in the collection using the given filter and options,
1161+
* and returns a paginated result containing reranked items mapped to the specified result type.
1162+
*
1163+
* @param filter
1164+
* the query filter to apply to the collection
1165+
* @param options
1166+
* the options used to customize the find and rerank operation
1167+
* @param newRowType
1168+
* the target class type to map the results to
1169+
* @param <R>
1170+
* the type of the result items after mapping
1171+
* @return
1172+
* a {@link Page} of {@link RerankResult} objects containing the paginated reranked results
1173+
*
1174+
* <p>Example usage:</p>
1175+
* <pre>
1176+
* {@code
1177+
* Filter filter = Filters.gt("score", 50);
1178+
* CollectionFindAndRerankOptions options = new CollectionFindAndRerankOptions().limit(10);
1179+
* Page<RerankResult<Book>> page = collection.findAndRerankPage(filter, options, Book.class);
1180+
* }
1181+
* </pre>
1182+
*/
11071183
@BetaPreview
11081184
public <R> Page<RerankResult<R>> findAndRerankPage(Filter filter, CollectionFindAndRerankOptions options, Class<R> newRowType) {
11091185
Command findAndRerankCommand = Command
@@ -1181,6 +1257,8 @@ public <R> Page<RerankResult<R>> findAndRerankPage(Filter filter, CollectionFind
11811257
* This list, along with the maximum page size and the next page state, is used to construct the {@link Page} object returned by the method.
11821258
* </p>
11831259
*
1260+
* @param <R> type of the result rows after mapping
1261+
* @param newRowType The class type to which the documents should be mapped.
11841262
* @param filter The filter criteria used to select documents from the collection.
11851263
* @param options The {@link CollectionFindOptions} providing additional query parameters, such as sorting and pagination.
11861264
* @return A {@link Page} object containing the documents that match the query, along with pagination information.

astra-db-java/src/main/java/com/datastax/astra/client/collections/commands/options/CollectionFindAndRerankOptions.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ public CollectionFindAndRerankOptions sort(Sort... sorts) {
113113
return this;
114114
}
115115

116+
/**
117+
* Return the sort clause as an arryr
118+
*
119+
* @return
120+
* Sort clause
121+
*/
116122
public Sort[] getSortArray() {
117123
return this.sort;
118124
}
@@ -189,9 +195,14 @@ public CollectionFindAndRerankOptions rerankOn(String rerankOn) {
189195
return this;
190196
}
191197

192-
193-
public CollectionFindAndRerankOptions rerankQuery(String $lexical) {
194-
this.rerankQuery = rerankOn;
198+
/**
199+
* Add a rerankQuery clause in the find block
200+
*
201+
* @param rerankQuery value for rerankQuery options
202+
* @return current command
203+
*/
204+
public CollectionFindAndRerankOptions rerankQuery(String rerankQuery) {
205+
this.rerankQuery = rerankQuery;
195206
return this;
196207
}
197208
}

astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/CollectionDefinition.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ public LexicalOptions getLexical() {
346346
return lexical;
347347
}
348348

349+
/**
350+
* Builder pattern, disabled lexical
351+
*
352+
* @return
353+
* self reference
354+
*/
349355
public CollectionDefinition disableLexical() {
350356
if (getLexical() == null) {
351357
lexical(new LexicalOptions().enabled(false));
@@ -443,6 +449,11 @@ public CollectionDefinition rerank(String provider, String model) {
443449
return this;
444450
}
445451

452+
/**
453+
* Builder pattern, disable reranking
454+
*
455+
* @return self reference
456+
*/
446457
public CollectionDefinition disableRerank() {
447458
if (getRerank() == null) {
448459
rerank = new CollectionRerankOptions().enabled(false);

astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/documents/Document.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.datastax.astra.client.core.vector.DataAPIVector;
4343
import com.datastax.astra.client.core.vectorize.Vectorize;
4444
import com.datastax.astra.client.exceptions.InvalidFieldExpressionException;
45+
import com.datastax.astra.client.exceptions.UnexpectedDataAPIResponseException;
4546
import com.datastax.astra.internal.serdes.DataAPISerializer;
4647
import com.datastax.astra.internal.serdes.collections.DocumentSerializer;
4748
import com.datastax.astra.internal.utils.Assert;
@@ -444,10 +445,31 @@ public Optional<String> getVectorize() {
444445
* vector list
445446
*/
446447
@JsonIgnore
448+
@SuppressWarnings("unchecked")
447449
public Optional<DataAPIVector> getVector() {
448-
return Optional
449-
.ofNullable((float[]) documentMap.get(DataAPIKeywords.VECTOR.getKeyword()))
450-
.map(DataAPIVector::new);
450+
if (!documentMap.containsKey(DataAPIKeywords.VECTOR.getKeyword())) {
451+
return Optional.empty();
452+
}
453+
454+
Object o = documentMap.get(DataAPIKeywords.VECTOR.getKeyword());
455+
456+
// Get a vector from a list of doubles
457+
if (o instanceof DataAPIVector) {
458+
return Optional.of((DataAPIVector) o);
459+
} else if (o instanceof ArrayList<?> list && !list.isEmpty() && list.get(0) instanceof Double) {
460+
ArrayList<Double> a = (ArrayList<Double>) list;
461+
float[] floatArray = new float[a.size()];
462+
for (int i = 0; i < a.size(); i++) {
463+
floatArray[i] = a.get(i).floatValue();
464+
}
465+
return Optional.of(new DataAPIVector(floatArray));
466+
} else if (o instanceof float[] array) {
467+
// Get a vector from a float array
468+
return Optional.of(new DataAPIVector(array));
469+
} else {
470+
throw new UnexpectedDataAPIResponseException("Could not parse $vector of type " + o.getClass().getName() +
471+
" to a DataAPIVector. Expected a list of Double, a float array or binary data");
472+
}
451473
}
452474

453475
/**
@@ -712,6 +734,21 @@ public <T> List<T> getList(@NonNull final String key, @NonNull final Class<T> cl
712734
return constructValuesList(key, clazz, null);
713735
}
714736

737+
/**
738+
* Gets the list value of the given key, casting the list elements to the given {@code Class<T>}. This is useful to avoid having
739+
* casts in client code, though the effect is the same.
740+
*
741+
* @param <K>
742+
* type of the key
743+
* @param <V>
744+
* type of the value
745+
* @param key the key
746+
* @param keyClass the non-null class to cast the list value to
747+
* @param valueClass the type of the value class
748+
* @return the list value of the given key, or null if the instance does not contain this key.
749+
* @throws ClassCastException if the elements in the list value of the given key is not of type T or the value is not a list
750+
* @since 3.10
751+
*/
715752
public <K,V> Map<K,V> getMap(@NonNull final String key, @NonNull final Class<K> keyClass, @NonNull final Class<V> valueClass) {
716753
return constructValuesMap(key, keyClass, valueClass, null);
717754
}
@@ -823,6 +860,9 @@ public String toJson() {
823860
* Check if the given dot-delimited path exists as a key (final segment).
824861
* e.g. containsKey("foo.bar") returns true if "bar" is present in the Map
825862
* located at "foo".
863+
*
864+
* @param key for key
865+
* @return if the key is present
826866
*/
827867
public boolean containsKey(String key) {
828868
Assert.hasLength(key, "Field name should not be null");
@@ -838,6 +878,14 @@ public boolean containsKey(String key) {
838878
return true;
839879
}
840880

881+
/**
882+
* Check if the given dot-delimited path exists as a key (final segment).
883+
* e.g. containsKey("foo.bar") returns true if "bar" is present in the Map
884+
* located at "foo".
885+
*
886+
* @param fieldPathSegment for key
887+
* @return if the key is present
888+
*/
841889
public Object get(final String[] fieldPathSegment) {
842890
return get(EscapeUtils.escapeFieldNames(fieldPathSegment));
843891
}

astra-db-java/src/main/java/com/datastax/astra/client/core/hybrid/HybridLimits.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public HybridLimits(Map<String, Integer> mapOfLimits) {
6767
*
6868
* @param limit
6969
* lexical limit.
70+
* @return
71+
* self reference
7072
*/
7173
public HybridLimits lexical(Integer limit) {
7274
if (mapOfLimits == null) {
@@ -81,6 +83,8 @@ public HybridLimits lexical(Integer limit) {
8183
*
8284
* @param limit
8385
* vector limit.
86+
* @return
87+
* self reference
8488
*/
8589
public HybridLimits vector(Integer limit) {
8690
if (mapOfLimits == null) {

0 commit comments

Comments
 (0)