4444 *
4545 * @author Christian Tzolov
4646 * @author Eddú Meléndez
47+ * @author Ilayaperumal Gopinathan
4748 */
4849public class ChromaApi {
4950
@@ -187,6 +188,17 @@ public void upsertEmbeddings(String collectionId, AddEmbeddingsRequest embedding
187188 .toBodilessEntity ();
188189 }
189190
191+ public int deleteEmbeddings (String collectionId , SimpleDeleteEmbeddingsRequest deleteRequest ) {
192+ return this .restClient .post ()
193+ .uri ("/api/v1/collections/{collection_id}/delete" , collectionId )
194+ .headers (this ::httpHeaders )
195+ .body (deleteRequest )
196+ .retrieve ()
197+ .toEntity (String .class )
198+ .getStatusCode ()
199+ .value ();
200+ }
201+
190202 public int deleteEmbeddings (String collectionId , DeleteEmbeddingsRequest deleteRequest ) {
191203 return this .restClient .post ()
192204 .uri ("/api/v1/collections/{collection_id}/delete" , collectionId )
@@ -219,6 +231,17 @@ public QueryResponse queryCollection(String collectionId, QueryRequest queryRequ
219231 .getBody ();
220232 }
221233
234+ public QueryResponse simpleQueryCollection (String collectionId , SimpleQueryRequest queryRequest ) {
235+
236+ return this .restClient .post ()
237+ .uri ("/api/v1/collections/{collection_id}/query" , collectionId )
238+ .headers (this ::httpHeaders )
239+ .body (queryRequest )
240+ .retrieve ()
241+ .toEntity (QueryResponse .class )
242+ .getBody ();
243+ }
244+
222245 //
223246 // Chroma Client API (https://docs.trychroma.com/js_reference/Client)
224247 //
@@ -234,6 +257,18 @@ public GetEmbeddingResponse getEmbeddings(String collectionId, GetEmbeddingsRequ
234257 .getBody ();
235258 }
236259
260+ public GetEmbeddingResponse getEmbeddings (String collectionId ,
261+ GetSimpleEmbeddingsRequest getSimpleEmbeddingsRequest ) {
262+
263+ return this .restClient .post ()
264+ .uri ("/api/v1/collections/{collection_id}/get" , collectionId )
265+ .headers (this ::httpHeaders )
266+ .body (getSimpleEmbeddingsRequest )
267+ .retrieve ()
268+ .toEntity (GetEmbeddingResponse .class )
269+ .getBody ();
270+ }
271+
237272 // Utils
238273 public Map <String , Object > where (String text ) {
239274 try {
@@ -331,9 +366,14 @@ public AddEmbeddingsRequest(String id, float[] embedding, Map<String, Object> me
331366 */
332367 public record DeleteEmbeddingsRequest (List <String > ids , Map <String , Object > where ) {
333368
334- public DeleteEmbeddingsRequest (List <String > ids ) {
335- this (ids , Map .of ());
336- }
369+ }
370+
371+ /**
372+ * Request to delete embedding from a collection.
373+ *
374+ * @param ids The ids of the embeddings to delete. (Optional)
375+ */
376+ public record SimpleDeleteEmbeddingsRequest (List <String > ids ) {
337377
338378 }
339379
@@ -351,10 +391,6 @@ public DeleteEmbeddingsRequest(List<String> ids) {
351391 public record GetEmbeddingsRequest (List <String > ids , Map <String , Object > where , int limit , int offset ,
352392 List <Include > include ) {
353393
354- public GetEmbeddingsRequest (List <String > ids ) {
355- this (ids , Map .of (), 10 , 0 , Include .all );
356- }
357-
358394 public GetEmbeddingsRequest (List <String > ids , Map <String , Object > where ) {
359395 this (ids , where , 10 , 0 , Include .all );
360396 }
@@ -365,6 +401,27 @@ public GetEmbeddingsRequest(List<String> ids, Map<String, Object> where, int lim
365401
366402 }
367403
404+ /**
405+ * Get embeddings from a collection.
406+ *
407+ * @param ids IDs of the embeddings to get.
408+ * @param limit Limit on the number of collection embeddings to get.
409+ * @param offset Offset on the embeddings to get.
410+ * @param include A list of what to include in the results. Can contain "embeddings",
411+ * "metadatas", "documents", "distances". Ids are always included. Defaults to
412+ * [metadatas, documents, distances].
413+ */
414+ public record GetSimpleEmbeddingsRequest (List <String > ids , int limit , int offset , List <Include > include ) {
415+
416+ public GetSimpleEmbeddingsRequest (List <String > ids ) {
417+ this (ids , 10 , 0 , Include .all );
418+ }
419+
420+ public GetSimpleEmbeddingsRequest (List <String > ids , Map <String , Object > where ) {
421+ this (ids , 10 , 0 , Include .all );
422+ }
423+ }
424+
368425 /**
369426 * Object containing the get embedding results.
370427 *
@@ -424,6 +481,47 @@ public enum Include {
424481
425482 }
426483
484+ /**
485+ * Request to get the nResults nearest neighbor embeddings for provided
486+ * queryEmbeddings.
487+ *
488+ * @param queryEmbeddings The embeddings to get the closes neighbors of.
489+ * @param nResults The number of neighbors to return for each query_embedding or
490+ * query_texts.
491+ * @param include A list of what to include in the results. Can contain "embeddings",
492+ * "metadatas", "documents", "distances". Ids are always included. Defaults to
493+ * [metadatas, documents, distances].
494+ */
495+ public record SimpleQueryRequest (@ JsonProperty ("query_embeddings" ) List <float []> queryEmbeddings ,
496+ @ JsonProperty ("n_results" ) int nResults , List <Include > include ) {
497+
498+ /**
499+ * Convenience to query for a single embedding instead of a batch of embeddings.
500+ */
501+ public SimpleQueryRequest (float [] queryEmbedding , int nResults ) {
502+ this (List .of (queryEmbedding ), nResults , Include .all );
503+ }
504+
505+ public enum Include {
506+
507+ @ JsonProperty ("metadatas" )
508+ METADATAS ,
509+
510+ @ JsonProperty ("documents" )
511+ DOCUMENTS ,
512+
513+ @ JsonProperty ("distances" )
514+ DISTANCES ,
515+
516+ @ JsonProperty ("embeddings" )
517+ EMBEDDINGS ;
518+
519+ public static final List <Include > all = List .of (METADATAS , DOCUMENTS , DISTANCES , EMBEDDINGS );
520+
521+ }
522+
523+ }
524+
427525 /**
428526 * A QueryResponse object containing the query results.
429527 *
0 commit comments