@@ -82,33 +82,41 @@ public Object delete() throws ApiException {
8282 return this .delete (null , null , null );
8383 }
8484
85- public Object upsert (List <List < Float >> embeddings , List <Map <String , String >> metadatas , List <String > documents , List <String > ids ) throws ApiException {
85+ public Object upsert (List <Embedding > embeddings , List <Map <String , String >> metadatas , List <String > documents , List <String > ids ) throws ChromaException {
8686 AddEmbedding req = new AddEmbedding ();
87- List <List < Float > > _embeddings = embeddings ;
87+ List <Embedding > _embeddings = embeddings ;
8888 if (_embeddings == null ) {
89- _embeddings = this .embeddingFunction .createEmbedding (documents );
89+ _embeddings = this .embeddingFunction .embedDocuments (documents );
9090 }
9191 req .setEmbeddings ((List <Object >) (Object ) _embeddings );
9292 req .setMetadatas ((List <Map <String , Object >>) (Object ) metadatas );
9393 req .setDocuments (documents );
9494 req .incrementIndex (true );
9595 req .setIds (ids );
96- return api .upsert (req , this .collectionId );
96+ try {
97+ return api .upsert (req , this .collectionId );
98+ } catch (ApiException e ) {
99+ throw new ChromaException (e );
100+ }
97101 }
98102
99103
100- public Object add (List <List < Float >> embeddings , List <Map <String , String >> metadatas , List <String > documents , List <String > ids ) throws ApiException {
104+ public Object add (List <Embedding > embeddings , List <Map <String , String >> metadatas , List <String > documents , List <String > ids ) throws ChromaException {
101105 AddEmbedding req = new AddEmbedding ();
102- List <List < Float > > _embeddings = embeddings ;
106+ List <Embedding > _embeddings = embeddings ;
103107 if (_embeddings == null ) {
104- _embeddings = this .embeddingFunction .createEmbedding (documents );
108+ _embeddings = this .embeddingFunction .embedDocuments (documents );
105109 }
106110 req .setEmbeddings ((List <Object >) (Object ) _embeddings );
107111 req .setMetadatas ((List <Map <String , Object >>) (Object ) metadatas );
108112 req .setDocuments (documents );
109113 req .incrementIndex (true );
110114 req .setIds (ids );
111- return api .add (req , this .collectionId );
115+ try {
116+ return api .add (req , this .collectionId );
117+ } catch (ApiException e ) {
118+ throw new ChromaException (e );
119+ }
112120 }
113121
114122 public Integer count () throws ApiException {
@@ -161,23 +169,27 @@ public Object update(String newName, Map<String, Object> newMetadata) throws Api
161169 return resp ;
162170 }
163171
164- public Object updateEmbeddings (List <List < Float >> embeddings , List <Map <String , String >> metadatas , List <String > documents , List <String > ids ) throws ApiException {
172+ public Object updateEmbeddings (List <Embedding > embeddings , List <Map <String , String >> metadatas , List <String > documents , List <String > ids ) throws ChromaException {
165173 UpdateEmbedding req = new UpdateEmbedding ();
166- List <List < Float > > _embeddings = embeddings ;
174+ List <Embedding > _embeddings = embeddings ;
167175 if (_embeddings == null ) {
168- _embeddings = this .embeddingFunction .createEmbedding (documents );
176+ _embeddings = this .embeddingFunction .embedDocuments (documents );
169177 }
170178 req .setEmbeddings ((List <Object >) (Object ) _embeddings );
171179 req .setDocuments (documents );
172180 req .setMetadatas ((List <Object >) (Object ) metadatas );
173181 req .setIds (ids );
174- return api .update (req , this .collectionId );
182+ try {
183+ return api .update (req , this .collectionId );
184+ } catch (ApiException e ) {
185+ throw new ChromaException (e );
186+ }
175187 }
176188
177189
178- public QueryResponse query (List <String > queryTexts , Integer nResults , Map <String , Object > where , Map <String , Object > whereDocument , List <QueryEmbedding .IncludeEnum > include ) throws ApiException {
190+ public QueryResponse query (List <String > queryTexts , Integer nResults , Map <String , Object > where , Map <String , Object > whereDocument , List <QueryEmbedding .IncludeEnum > include ) throws ChromaException {
179191 QueryEmbedding body = new QueryEmbedding ();
180- body .queryEmbeddings ((List <Object >) (Object ) this .embeddingFunction .createEmbedding (queryTexts ));
192+ body .queryEmbeddings ((List <Object >) (Object ) this .embeddingFunction .embedDocuments (queryTexts ));
181193 body .nResults (nResults );
182194 body .include (include );
183195 if (where != null ) {
@@ -186,9 +198,13 @@ public QueryResponse query(List<String> queryTexts, Integer nResults, Map<String
186198 if (whereDocument != null ) {
187199 body .whereDocument (whereDocument .entrySet ().stream ().collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue )));
188200 }
189- Gson gson = new Gson ();
190- String json = gson .toJson (api .getNearestNeighbors (body , this .collectionId ));
191- return new Gson ().fromJson (json , QueryResponse .class );
201+ try {
202+ Gson gson = new Gson ();
203+ String json = gson .toJson (api .getNearestNeighbors (body , this .collectionId ));
204+ return new Gson ().fromJson (json , QueryResponse .class );
205+ } catch (ApiException e ) {
206+ throw new ChromaException (e );
207+ }
192208 }
193209
194210 public static class QueryResponse {
0 commit comments