-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inference API] Prevent inference endpoints from being deleted if the…
- Loading branch information
1 parent
b6e9860
commit 89a1bd9
Showing
8 changed files
with
266 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 110399 | ||
summary: "[Inference API] Prevent inference endpoints from being deleted if they are\ | ||
\ referenced by semantic text" | ||
area: Machine Learning | ||
type: enhancement | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...n/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/SemanticTextInfoExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
* | ||
* this file was contributed to by a Generative AI | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.ml.utils; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.InferenceFieldMetadata; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class SemanticTextInfoExtractor { | ||
private static final Logger logger = LogManager.getLogger(SemanticTextInfoExtractor.class); | ||
|
||
public static Set<String> extractIndexesReferencingInferenceEndpoints(Metadata metadata, Set<String> endpointIds) { | ||
assert endpointIds.isEmpty() == false; | ||
assert metadata != null; | ||
|
||
Set<String> referenceIndices = new HashSet<>(); | ||
|
||
Map<String, IndexMetadata> indices = metadata.indices(); | ||
|
||
indices.forEach((indexName, indexMetadata) -> { | ||
if (indexMetadata.getInferenceFields() != null) { | ||
Map<String, InferenceFieldMetadata> inferenceFields = indexMetadata.getInferenceFields(); | ||
if (inferenceFields.entrySet() | ||
.stream() | ||
.anyMatch( | ||
entry -> entry.getValue().getInferenceId() != null && endpointIds.contains(entry.getValue().getInferenceId()) | ||
)) { | ||
referenceIndices.add(indexName); | ||
} | ||
} | ||
}); | ||
|
||
return referenceIndices; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.