@@ -342,7 +342,22 @@ public static void createInferenceEndpoints(RestClient client) throws IOExceptio
342342 }
343343 }
344344
345+ @ SuppressWarnings ("unchecked" )
345346 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+ }
346361 deleteSparseEmbeddingInferenceEndpoint (client );
347362 deleteRerankInferenceEndpoint (client );
348363 deleteCompletionInferenceEndpoint (client );
@@ -360,7 +375,7 @@ public static void createSparseEmbeddingInferenceEndpoint(RestClient client) thr
360375 }
361376
362377 public static void deleteSparseEmbeddingInferenceEndpoint (RestClient client ) throws IOException {
363- deleteInferenceEndpoint (client , "test_sparse_inference" );
378+ deleteInferenceEndpoint (client , "test_sparse_inference" , TaskType . SPARSE_EMBEDDING );
364379 }
365380
366381 public static boolean clusterHasSparseEmbeddingInferenceEndpoint (RestClient client ) throws IOException {
@@ -378,7 +393,7 @@ public static void createRerankInferenceEndpoint(RestClient client) throws IOExc
378393 }
379394
380395 public static void deleteRerankInferenceEndpoint (RestClient client ) throws IOException {
381- deleteInferenceEndpoint (client , "test_reranker" );
396+ deleteInferenceEndpoint (client , "test_reranker" , TaskType . RERANK );
382397 }
383398
384399 public static boolean clusterHasRerankInferenceEndpoint (RestClient client ) throws IOException {
@@ -396,7 +411,7 @@ public static void createCompletionInferenceEndpoint(RestClient client) throws I
396411 }
397412
398413 public static void deleteCompletionInferenceEndpoint (RestClient client ) throws IOException {
399- deleteInferenceEndpoint (client , "test_completion" );
414+ deleteInferenceEndpoint (client , "test_completion" , TaskType . COMPLETION );
400415 }
401416
402417 public static boolean clusterHasCompletionInferenceEndpoint (RestClient client ) throws IOException {
@@ -423,9 +438,9 @@ private static boolean clusterHasInferenceEndpoint(RestClient client, TaskType t
423438 return true ;
424439 }
425440
426- private static void deleteInferenceEndpoint (RestClient client , String inferenceId ) throws IOException {
441+ private static void deleteInferenceEndpoint (RestClient client , String inferenceId , TaskType taskType ) throws IOException {
427442 try {
428- client .performRequest (new Request ("DELETE" , "_inference/" + inferenceId ));
443+ client .performRequest (new Request ("DELETE" , "_inference/" + taskType + "/" + inferenceId ));
429444 } catch (ResponseException e ) {
430445 // 404 here means the endpoint was not created
431446 if (e .getResponse ().getStatusLine ().getStatusCode () != 404 ) {
0 commit comments