Skip to content

Commit

Permalink
change name
Browse files Browse the repository at this point in the history
Signed-off-by: xinyual <[email protected]>
  • Loading branch information
xinyual committed Dec 9, 2024
1 parent 6a38c2b commit e04d9d6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CommonValue {
public static final String ML_MEMORY_MESSAGE_INDEX = ".plugins-ml-memory-message";
public static final String ML_STOP_WORDS_INDEX = ".plugins-ml-stop-words";
public static final Set<String> stopWordsIndices = ImmutableSet.of(".plugins-ml-stop-words");
public static final String TOOL_MODEL_RELATED_FIELD_PREFIX = "tools.parameters.";
public static final String TOOL_PARAMETERS_PREFIX = "tools.parameters.";

// Index mapping paths
public static final String ML_MODEL_GROUP_INDEX_MAPPING_PATH = "index-mappings/ml-model-group.json";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opensearch.ml.engine.utils;

import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX;
import static org.opensearch.ml.common.CommonValue.TOOL_MODEL_RELATED_FIELD_PREFIX;
import static org.opensearch.ml.common.CommonValue.TOOL_PARAMETERS_PREFIX;

import java.util.HashSet;
import java.util.Map;
Expand All @@ -23,12 +23,13 @@ public AgentModelsSearcher(Map<String, Tool.Factory> toolFactories) {
relatedModelIdSet.addAll(toolFactory.getAllModelKeys());
}
}

public SearchRequest constructQueryRequest(String candidateModelId) {


public SearchRequest constructQueryRequestToSearchModelId(String candidateModelId) {
SearchRequest searchRequest = new SearchRequest(ML_AGENT_INDEX);
BoolQueryBuilder shouldQuery = QueryBuilders.boolQuery();
for (String keyField : relatedModelIdSet) {
shouldQuery.should(QueryBuilders.termsQuery(TOOL_MODEL_RELATED_FIELD_PREFIX + keyField, candidateModelId));
shouldQuery.should(QueryBuilders.termsQuery(TOOL_PARAMETERS_PREFIX + keyField, candidateModelId));
}
searchRequest.source(new SearchSourceBuilder().query(shouldQuery));
return searchRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void onFailure(Exception e) {

private void checkAgentBeforeDeleteModel(String modelId, ActionListener<Boolean> actionListener) {
// check whether agent are using them
SearchRequest searchAgentRequest = agentModelsSearcher.constructQueryRequest(modelId);
SearchRequest searchAgentRequest = agentModelsSearcher.constructQueryRequestToSearchModelId(modelId);
client.search(searchAgentRequest, ActionListener.wrap(searchResponse -> {
SearchHit[] searchHits = searchResponse.getHits().getHits();
if (searchHits.length == 0) {
Expand Down Expand Up @@ -490,7 +490,7 @@ private <T> List<String> findDependentPipelines(
return dependentPipelineConfigurations;
}

// This method is to go through the pipeline configs and he configuration is a map of string to objects.
// This method is to go through the pipeline configs and the configuration is a map of string to objects.
// Objects can be a list or a map. we will search exhaustively through the configuration for any match of the candidateId.
private Boolean searchThroughConfig(Object searchCandidate, String candidateId) {
// Use a stack to store the elements to be processed
Expand All @@ -503,9 +503,9 @@ private Boolean searchThroughConfig(Object searchCandidate, String candidateId)
String currentKey = current.getLeft();
Object currentCandidate = current.getRight();

if (currentCandidate instanceof String) {
if (currentCandidate instanceof String && candidateId.equals(currentCandidate)) {
// Check for a match
if (Objects.equals(currentKey, PIPELINE_TARGET_MODEL_KEY) && Objects.equals(candidateId, currentCandidate)) {
if (PIPELINE_TARGET_MODEL_KEY.equals(currentKey)) {
return true;
}
} else if (currentCandidate instanceof List<?>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ private void prepare() throws IOException {
}).when(client).execute(eq(GetSearchPipelineAction.INSTANCE), any(), any());
configDataMap = Map
.of("single_model_id", "test_id", "list_model_id", List.of("test_id"), "test_map_id", Map.of("model_id", "test_id"));
doAnswer(invocation -> new SearchRequest()).when(agentModelsSearcher).constructQueryRequest(any());
doAnswer(invocation -> new SearchRequest()).when(agentModelsSearcher).constructQueryRequestToSearchModelId(any());

GetResponse getResponse = prepareMLModel(MLModelState.REGISTERED, null, false);
doAnswer(invocation -> {
Expand Down

0 comments on commit e04d9d6

Please sign in to comment.