@@ -303,25 +303,26 @@ public JedisPooled getJedis() {
303
303
304
304
@ Override
305
305
public void add (List <Document > documents ) {
306
- Pipeline pipeline = this .jedis .pipelined ();
307
- for (Document document : documents ) {
308
- var embedding = this .embeddingClient .embed (document );
309
- document .setEmbedding (embedding );
310
-
311
- var fields = new HashMap <String , Object >();
312
- fields .put (this .config .embeddingFieldName , embedding );
313
- fields .put (this .config .contentFieldName , document .getContent ());
314
- fields .putAll (document .getMetadata ());
315
- pipeline .jsonSetWithEscape (key (document .getId ()), JSON_SET_PATH , fields );
316
- }
317
- List <Object > responses = pipeline .syncAndReturnAll ();
318
- Optional <Object > errResponse = responses .stream ().filter (Predicate .not (RESPONSE_OK )).findAny ();
319
- if (errResponse .isPresent ()) {
320
- String message = MessageFormat .format ("Could not add document: {0}" , errResponse .get ());
321
- if (logger .isErrorEnabled ()) {
322
- logger .error (message );
306
+ try (Pipeline pipeline = this .jedis .pipelined ()) {
307
+ for (Document document : documents ) {
308
+ var embedding = this .embeddingClient .embed (document );
309
+ document .setEmbedding (embedding );
310
+
311
+ var fields = new HashMap <String , Object >();
312
+ fields .put (this .config .embeddingFieldName , embedding );
313
+ fields .put (this .config .contentFieldName , document .getContent ());
314
+ fields .putAll (document .getMetadata ());
315
+ pipeline .jsonSetWithEscape (key (document .getId ()), JSON_SET_PATH , fields );
316
+ }
317
+ List <Object > responses = pipeline .syncAndReturnAll ();
318
+ Optional <Object > errResponse = responses .stream ().filter (Predicate .not (RESPONSE_OK )).findAny ();
319
+ if (errResponse .isPresent ()) {
320
+ String message = MessageFormat .format ("Could not add document: {0}" , errResponse .get ());
321
+ if (logger .isErrorEnabled ()) {
322
+ logger .error (message );
323
+ }
324
+ throw new RuntimeException (message );
323
325
}
324
- throw new RuntimeException (message );
325
326
}
326
327
}
327
328
@@ -331,19 +332,20 @@ private String key(String id) {
331
332
332
333
@ Override
333
334
public Optional <Boolean > delete (List <String > idList ) {
334
- Pipeline pipeline = this .jedis .pipelined ();
335
- for (String id : idList ) {
336
- pipeline .jsonDel (key (id ));
337
- }
338
- List <Object > responses = pipeline .syncAndReturnAll ();
339
- Optional <Object > errResponse = responses .stream ().filter (Predicate .not (RESPONSE_DEL_OK )).findAny ();
340
- if (errResponse .isPresent ()) {
341
- if (logger .isErrorEnabled ()) {
342
- logger .error ("Could not delete document: {}" , errResponse .get ());
335
+ try (Pipeline pipeline = this .jedis .pipelined ()) {
336
+ for (String id : idList ) {
337
+ pipeline .jsonDel (key (id ));
338
+ }
339
+ List <Object > responses = pipeline .syncAndReturnAll ();
340
+ Optional <Object > errResponse = responses .stream ().filter (Predicate .not (RESPONSE_DEL_OK )).findAny ();
341
+ if (errResponse .isPresent ()) {
342
+ if (logger .isErrorEnabled ()) {
343
+ logger .error ("Could not delete document: {}" , errResponse .get ());
344
+ }
345
+ return Optional .of (false );
343
346
}
344
- return Optional .of (false );
347
+ return Optional .of (true );
345
348
}
346
- return Optional .of (true );
347
349
}
348
350
349
351
@ Override
0 commit comments