@@ -342,7 +342,22 @@ public static void createInferenceEndpoints(RestClient client) throws IOExceptio
342
342
}
343
343
}
344
344
345
+ @ SuppressWarnings ("unchecked" )
345
346
public static void deleteInferenceEndpoints (RestClient client ) throws IOException {
347
+ Response response = client .performRequest (new Request ("GET" , "_inference/_all" ));
348
+
349
+ try (InputStream content = response .getEntity ().getContent ()) {
350
+ XContentType xContentType = XContentType .fromMediaType (response .getEntity ().getContentType ().getValue ());
351
+ Map <String , ?> responseMap = XContentHelper .convertToMap (xContentType .xContent (), content , false );
352
+ List <Map <String , ?>> endpoints = (List <Map <String , ?>>) responseMap .get ("endpoints" );
353
+ for (Map <String , ?> endpoint : endpoints ) {
354
+ String inferenceId = (String ) endpoint .get ("inference_id" );
355
+ String taskType = (String ) endpoint .get ("task_type" );
356
+ if (inferenceId != null && taskType != null && inferenceId .startsWith ("." ) == false ) {
357
+ deleteInferenceEndpoint (client , inferenceId , TaskType .fromString (taskType ));
358
+ }
359
+ }
360
+ }
346
361
deleteSparseEmbeddingInferenceEndpoint (client );
347
362
deleteRerankInferenceEndpoint (client );
348
363
deleteCompletionInferenceEndpoint (client );
@@ -360,7 +375,7 @@ public static void createSparseEmbeddingInferenceEndpoint(RestClient client) thr
360
375
}
361
376
362
377
public static void deleteSparseEmbeddingInferenceEndpoint (RestClient client ) throws IOException {
363
- deleteInferenceEndpoint (client , "test_sparse_inference" );
378
+ deleteInferenceEndpoint (client , "test_sparse_inference" , TaskType . SPARSE_EMBEDDING );
364
379
}
365
380
366
381
public static boolean clusterHasSparseEmbeddingInferenceEndpoint (RestClient client ) throws IOException {
@@ -378,7 +393,7 @@ public static void createRerankInferenceEndpoint(RestClient client) throws IOExc
378
393
}
379
394
380
395
public static void deleteRerankInferenceEndpoint (RestClient client ) throws IOException {
381
- deleteInferenceEndpoint (client , "test_reranker" );
396
+ deleteInferenceEndpoint (client , "test_reranker" , TaskType . RERANK );
382
397
}
383
398
384
399
public static boolean clusterHasRerankInferenceEndpoint (RestClient client ) throws IOException {
@@ -396,7 +411,7 @@ public static void createCompletionInferenceEndpoint(RestClient client) throws I
396
411
}
397
412
398
413
public static void deleteCompletionInferenceEndpoint (RestClient client ) throws IOException {
399
- deleteInferenceEndpoint (client , "test_completion" );
414
+ deleteInferenceEndpoint (client , "test_completion" , TaskType . COMPLETION );
400
415
}
401
416
402
417
public static boolean clusterHasCompletionInferenceEndpoint (RestClient client ) throws IOException {
@@ -423,9 +438,9 @@ private static boolean clusterHasInferenceEndpoint(RestClient client, TaskType t
423
438
return true ;
424
439
}
425
440
426
- private static void deleteInferenceEndpoint (RestClient client , String inferenceId ) throws IOException {
441
+ private static void deleteInferenceEndpoint (RestClient client , String inferenceId , TaskType taskType ) throws IOException {
427
442
try {
428
- client .performRequest (new Request ("DELETE" , "_inference/" + inferenceId ));
443
+ client .performRequest (new Request ("DELETE" , "_inference/" + taskType + "/" + inferenceId ));
429
444
} catch (ResponseException e ) {
430
445
// 404 here means the endpoint was not created
431
446
if (e .getResponse ().getStatusLine ().getStatusCode () != 404 ) {
0 commit comments