Skip to content

Commit

Permalink
update index name and error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Jan 15, 2024
1 parent 985f1d9 commit 3d6b01f
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/opensearch/agent/ToolPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Collection<Object> createComponents(
this.clusterService = clusterService;
this.xContentRegistry = xContentRegistry;

mlClients = new MLClients(client, xContentRegistry);
mlClients = new MLClients(client, xContentRegistry, clusterService);
indicesHelper = new IndicesHelper(clusterService, client, mlClients);
SkillsClusterManagerEventListener clusterManagerEventListener = new SkillsClusterManagerEventListener(

Check warning on line 77 in src/main/java/org/opensearch/agent/ToolPlugin.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/ToolPlugin.java#L75-L77

Added lines #L75 - L77 were not covered by tests
clusterService,
Expand All @@ -94,7 +94,7 @@ public Collection<Object> createComponents(
SearchAnomalyDetectorsTool.Factory.getInstance().init(client);
SearchAnomalyResultsTool.Factory.getInstance().init(client);
SearchMonitorsTool.Factory.getInstance().init(client);
IndexRoutingTool.Factory.getInstance().init(client, xContentRegistry);
IndexRoutingTool.Factory.getInstance().init(client, xContentRegistry, clusterService);

Check warning on line 97 in src/main/java/org/opensearch/agent/ToolPlugin.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/ToolPlugin.java#L97

Added line #L97 was not covered by tests

return List.of(clusterManagerEventListener);

Check warning on line 99 in src/main/java/org/opensearch/agent/ToolPlugin.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/ToolPlugin.java#L99

Added line #L99 was not covered by tests
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class IndicesHelper {
}

Check warning on line 56 in src/main/java/org/opensearch/agent/indices/IndicesHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/indices/IndicesHelper.java#L56

Added line #L56 was not covered by tests

public void initIndexSummaryEmbeddingIndex(ActionListener<Boolean> listener) {
initIndexIfAbsent(SkillsIndexEnum.SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX, listener);
initIndexIfAbsent(SkillsIndexEnum.SKILLS_INDEX_SUMMARY, listener);
}

Check warning on line 60 in src/main/java/org/opensearch/agent/indices/IndicesHelper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/indices/IndicesHelper.java#L59-L60

Added lines #L59 - L60 were not covered by tests

public void initIndexIfAbsent(SkillsIndexEnum skillsIndexEnum, ActionListener<Boolean> listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
@Getter
public enum SkillsIndexEnum {

SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX(
".index_summary_embedding_index",
"/.index_summary_embedding_index_setting.json",
"/.index_summary_embedding_index_mapping.json",
SKILLS_INDEX_SUMMARY(

Check warning on line 18 in src/main/java/org/opensearch/agent/indices/SkillsIndexEnum.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/indices/SkillsIndexEnum.java#L18

Added line #L18 was not covered by tests
".plugins-skills-index-summary",
"/.plugins-skills-index-summary-setting.json",
"/.plugins-skills-index-summary-mapping.json",
0
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void run() {
embeddingModelIds.removeAll(EMBEDDING_MODEL_IDS);

Check warning on line 56 in src/main/java/org/opensearch/agent/job/AgentMonitorJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/AgentMonitorJob.java#L54-L56

Added lines #L54 - L56 were not covered by tests
if (!embeddingModelIds.isEmpty()) {
IndexSummaryEmbeddingJob job = new IndexSummaryEmbeddingJob(client, clusterService, indicesHelper, mlClients);
job.setAdhocModelIds(embeddingModelIds);
threadPool.schedule(job, TimeValue.timeValueSeconds(5), GENERIC);

Check warning on line 60 in src/main/java/org/opensearch/agent/job/AgentMonitorJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/AgentMonitorJob.java#L58-L60

Added lines #L58 - L60 were not covered by tests
}
}, exception -> log.info("Query agent for index routing tool failed.", exception)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.opensearch.agent.job;

import static org.opensearch.agent.indices.SkillsIndexEnum.SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX;
import static org.opensearch.agent.indices.SkillsIndexEnum.SKILLS_INDEX_SUMMARY;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,7 +63,7 @@ public class IndexSummaryEmbeddingJob implements Runnable {
private IndicesHelper indicesHelper;
private MLClients mlClients;

public static String INDEX_SUMMARY_EMBEDDING_INDEX = ".index_summary_embedding_index";
public static String INDEX_SUMMARY_EMBEDDING_INDEX = SKILLS_INDEX_SUMMARY.getIndexName();
public static String INDEX_SUMMARY_EMBEDDING_FIELD_PREFIX = "index_summary_embedding";
public static String INDEX_NAME_FIELD = "index_name";
public static String DATA_STREAM_FIELD = "data_stream";
Expand All @@ -79,6 +79,7 @@ public class IndexSummaryEmbeddingJob implements Runnable {
public static String INDEX_EMBEDDING = "embedding";
public static String SENTENCE_EMBEDDING = "sentence_embedding";
public static int DEFAULT_TIMEOUT_SECOND = 30;
public static int TOKEN_LIMIT = 8192;

Check warning on line 82 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L74-L82

Added lines #L74 - L82 were not covered by tests

@Setter
private List<String> adhocIndexName;
Expand All @@ -96,6 +97,7 @@ public IndexSummaryEmbeddingJob(Client client, ClusterService clusterService, In

@Override
public void run() {
// TODO to distribute to other nodes to execute the workload other than cluster manager node
// search agent with IndexRoutingTool
mlClients.getModelIdsForIndexRoutingTool(adhocModelIds, ActionListener.wrap(embeddingModelIds -> {

Check warning on line 102 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L102

Added line #L102 was not covered by tests
// no embedding model
Expand Down Expand Up @@ -205,9 +207,19 @@ private List<Map<String, Object>> getAllIndexMappingAndSampleData() {
SearchResponse searchResponse = searchFuture.get(DEFAULT_TIMEOUT_SECOND, TimeUnit.SECONDS);

Check warning on line 207 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L206-L207

Added lines #L206 - L207 were not covered by tests

List<String> documents = new ArrayList<>();
// TODO add token limit check
int tokenNumber = 0;

Check warning on line 210 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L209-L210

Added lines #L209 - L210 were not covered by tests
for (SearchHit hit : searchResponse.getHits()) {
documents.add(Strings.toString(MediaTypeRegistry.JSON, hit));
String docContent = Strings.toString(MediaTypeRegistry.JSON, hit);
int tokens = countToken(docContent);

Check warning on line 213 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L212-L213

Added lines #L212 - L213 were not covered by tests
if (tokenNumber + tokens > TOKEN_LIMIT) {
// at least 1 sample data
if (documents.isEmpty()) {
documents.add(docContent);

Check warning on line 217 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L217

Added line #L217 was not covered by tests
}
break;
}
documents.add(docContent);
tokenNumber += tokens;
}

Check warning on line 223 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L221-L223

Added lines #L221 - L223 were not covered by tests

String indexSummary = String.format(Locale.ROOT, "Index Mappings:%s\\nSample data:\\n%s", mapping, documents);

Check warning on line 225 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L225

Added line #L225 was not covered by tests
Expand All @@ -224,6 +236,20 @@ private List<Map<String, Object>> getAllIndexMappingAndSampleData() {
return indexSummaryList;

Check warning on line 236 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L236

Added line #L236 was not covered by tests
}

/**
* 1 token ~= 4 chars in English
* 1 token ~= ¾ words
* 100 tokens ~= 75 words
* @param sentence
* @return
*/
private int countToken(String sentence) {
if (sentence == null) {
return 0;

Check warning on line 248 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L248

Added line #L248 was not covered by tests
}
return sentence.getBytes(StandardCharsets.UTF_8).length / 4;

Check warning on line 250 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L250

Added line #L250 was not covered by tests
}

private void indexSummaryVector(String writeIndex, List<Map<String, Object>> docs, String modelId) {
// init index and mapping
indicesHelper.initIndexSummaryEmbeddingIndex(ActionListener.wrap(initialed -> {

Check warning on line 255 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L255

Added line #L255 was not covered by tests
Expand All @@ -240,7 +266,7 @@ private void indexSummaryVector(String writeIndex, List<Map<String, Object>> doc
}

Check warning on line 266 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L265-L266

Added lines #L265 - L266 were not covered by tests

private void BulkUpdateVectorField(String writeIndex, List<Map<String, Object>> docs, String modelId) {
indicesHelper.addNewVectorField(SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX.getIndexName(), modelId, ActionListener.wrap(r -> {
indicesHelper.addNewVectorField(SKILLS_INDEX_SUMMARY.getIndexName(), modelId, ActionListener.wrap(r -> {

Check warning on line 269 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L269

Added line #L269 was not covered by tests
if (r) {
bulkWrite(writeIndex, docs, modelId);

Check warning on line 271 in src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/IndexSummaryEmbeddingJob.java#L271

Added line #L271 was not covered by tests
} else {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/opensearch/agent/job/MLClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.opensearch.agent.tools.IndexRoutingTool;
import org.opensearch.client.Client;
import org.opensearch.client.Requests;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.action.ActionFuture;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.XContentHelper;
Expand All @@ -35,6 +36,7 @@
import org.opensearch.index.IndexNotFoundException;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.TermQueryBuilder;
import org.opensearch.ml.common.CommonValue;
import org.opensearch.ml.common.FunctionName;
import org.opensearch.ml.common.MLTaskState;
import org.opensearch.ml.common.agent.MLAgent;
Expand Down Expand Up @@ -64,9 +66,12 @@ public class MLClients {

private NamedXContentRegistry xContentRegistry;

public MLClients(Client client, NamedXContentRegistry xContentRegistry) {
private ClusterService clusterService;

public MLClients(Client client, NamedXContentRegistry xContentRegistry, ClusterService clusterService) {
this.client = client;
this.xContentRegistry = xContentRegistry;
this.clusterService = clusterService;
}

Check warning on line 75 in src/main/java/org/opensearch/agent/job/MLClients.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/MLClients.java#L71-L75

Added lines #L71 - L75 were not covered by tests

public <T> T getEmbeddingResult(String modelId, List<String> texts, boolean deploy, Function<MLTaskResponse, T> parser) {
Expand Down Expand Up @@ -123,6 +128,10 @@ public void getModelIdsForIndexRoutingTool(List<String> adhocModelIds, ActionLis
}

Check warning on line 128 in src/main/java/org/opensearch/agent/job/MLClients.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/MLClients.java#L128

Added line #L128 was not covered by tests

public void getModelIdsForIndexRoutingTool(ActionListener<List<String>> listener) {
if (!clusterService.state().metadata().hasIndex(CommonValue.ML_AGENT_INDEX)) {
listener.onResponse(Collections.emptyList());
return;

Check warning on line 133 in src/main/java/org/opensearch/agent/job/MLClients.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/MLClients.java#L132-L133

Added lines #L132 - L133 were not covered by tests
}
// search agent with IndexRoutingTool
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
String termQueryKey = String.format(Locale.ROOT, "%s.%s", MLAgent.TOOLS_FIELD, MLToolSpec.TOOL_TYPE_FIELD);
Expand All @@ -143,7 +152,7 @@ public void getModelIdsForIndexRoutingTool(ActionListener<List<String>> listener
}
listener.onResponse(new ArrayList<>(embeddingModelIds));
}, ex -> {

Check warning on line 154 in src/main/java/org/opensearch/agent/job/MLClients.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/MLClients.java#L151-L154

Added lines #L151 - L154 were not covered by tests
if (ExceptionsHelper.unwrap(ex) instanceof IndexNotFoundException) {
if (ExceptionsHelper.unwrapCause(ex) instanceof IndexNotFoundException) {
listener.onResponse(Collections.emptyList());

Check warning on line 156 in src/main/java/org/opensearch/agent/job/MLClients.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/MLClients.java#L156

Added line #L156 was not covered by tests
} else {
listener.onFailure(ex);

Check warning on line 158 in src/main/java/org/opensearch/agent/job/MLClients.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/MLClients.java#L158

Added line #L158 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.opensearch.agent.job;

import static org.opensearch.agent.indices.SkillsIndexEnum.SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX;
import static org.opensearch.agent.indices.SkillsIndexEnum.SKILLS_INDEX_SUMMARY;
import static org.opensearch.threadpool.ThreadPool.Names.GENERIC;

import java.util.List;
Expand Down Expand Up @@ -122,10 +122,9 @@ public void clusterChanged(ClusterChangedEvent event) {
threadPool.schedule(job, TimeValue.timeValueSeconds(30), GENERIC);

Check warning on line 122 in src/main/java/org/opensearch/agent/job/SkillsClusterManagerEventListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/SkillsClusterManagerEventListener.java#L121-L122

Added lines #L121 - L122 were not covered by tests
}

if (!event.indicesDeleted().isEmpty()
&& clusterService.state().metadata().hasIndex(SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX.getIndexName())) {
if (!event.indicesDeleted().isEmpty() && clusterService.state().metadata().hasIndex(SKILLS_INDEX_SUMMARY.getIndexName())) {
List<String> indexNames = event.indicesDeleted().stream().map(Index::getName).collect(Collectors.toList());
job.bulkDelete(SKILLS_INDEX_SUMMARY_EMBEDDING_INDEX.getIndexName(), indexNames);
job.bulkDelete(SKILLS_INDEX_SUMMARY.getIndexName(), indexNames);

Check warning on line 127 in src/main/java/org/opensearch/agent/job/SkillsClusterManagerEventListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/SkillsClusterManagerEventListener.java#L126-L127

Added lines #L126 - L127 were not covered by tests
}
}
}

Check warning on line 130 in src/main/java/org/opensearch/agent/job/SkillsClusterManagerEventListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/job/SkillsClusterManagerEventListener.java#L130

Added line #L130 was not covered by tests
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.opensearch.agent.job.MLClients;
import org.opensearch.agent.tools.utils.LLMProvider;
import org.opensearch.client.Client;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.io.Streams;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -75,6 +76,8 @@ public class IndexRoutingTool extends VectorDBTool {

private final MLClients mlClients;

private final ClusterService clusterService;

@Setter
private String prompt;

Expand All @@ -84,7 +87,8 @@ public IndexRoutingTool(
Integer docSize,
Integer k,
String embeddingModelId,
String inferenceModelId
String inferenceModelId,
ClusterService clusterService
) {
super(

Check warning on line 93 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L93

Added line #L93 was not covered by tests
client,
Expand All @@ -101,8 +105,9 @@ public IndexRoutingTool(
embeddingModelId,
Optional.ofNullable(k).orElse(DEFAULT_K)

Check warning on line 106 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L106

Added line #L106 was not covered by tests
);
this.mlClients = new MLClients(client, xContentRegistry);
this.mlClients = new MLClients(client, xContentRegistry, clusterService);
this.inferenceModelId = inferenceModelId;
this.clusterService = clusterService;
}

Check warning on line 111 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L108-L111

Added lines #L108 - L111 were not covered by tests

@Override
Expand All @@ -128,6 +133,11 @@ protected Parser<SearchResponse, Object> searchResponseParser() {
@Override
public <T> void run(Map<String, String> parameters, ActionListener<T> listener) {
log.debug("input={}", parameters.get(INPUT_FIELD));

Check warning on line 135 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L135

Added line #L135 was not covered by tests
if (!clusterService.state().metadata().hasIndex(IndexSummaryEmbeddingJob.INDEX_SUMMARY_EMBEDDING_INDEX)) {
log.debug("Index summary index not exists, return not sure directly");
listener.onResponse((T) "Not sure");
return;

Check warning on line 139 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L137-L139

Added lines #L137 - L139 were not covered by tests
}
// get index of knn-index
super.run(parameters, ActionListener.wrap(res -> {
List<Map<String, Object>> summaries = (List<Map<String, Object>>) res;

Check warning on line 143 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L142-L143

Added lines #L142 - L143 were not covered by tests
Expand Down Expand Up @@ -240,6 +250,8 @@ public static class Factory implements Tool.Factory<IndexRoutingTool> {
private Client client;
private NamedXContentRegistry xContentRegistry;

private ClusterService clusterService;

private static IndexRoutingTool.Factory INSTANCE;

public static IndexRoutingTool.Factory getInstance() {
Expand All @@ -255,9 +267,10 @@ public static IndexRoutingTool.Factory getInstance() {
}
}

public void init(Client client, NamedXContentRegistry xContentRegistry) {
public void init(Client client, NamedXContentRegistry xContentRegistry, ClusterService clusterService) {
this.client = client;
this.xContentRegistry = xContentRegistry;
this.clusterService = clusterService;
}

Check warning on line 274 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L271-L274

Added lines #L271 - L274 were not covered by tests

@Override
Expand All @@ -282,7 +295,15 @@ public IndexRoutingTool create(Map<String, Object> params) {

Integer docSize = params.containsKey(DOC_SIZE_FIELD) ? Integer.parseInt((String) params.get(DOC_SIZE_FIELD)) : DEFAULT_K;
Integer k = params.containsKey(K_FIELD) ? Integer.parseInt((String) params.get(K_FIELD)) : DEFAULT_K;
IndexRoutingTool tool = new IndexRoutingTool(client, xContentRegistry, docSize, k, embeddingModelId, inferenceModelId);
IndexRoutingTool tool = new IndexRoutingTool(

Check warning on line 298 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L298

Added line #L298 was not covered by tests
client,
xContentRegistry,
docSize,
k,
embeddingModelId,
inferenceModelId,
clusterService
);
tool.setPrompt(llmProvider.getPromptFormat().replace("${prompt}", promptTemplate));

Check warning on line 307 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L307

Added line #L307 was not covered by tests

return tool;

Check warning on line 309 in src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/IndexRoutingTool.java#L309

Added line #L309 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public enum LLMProvider {
OPENAI("${prompt}"),
ANTHROPIC("\\n\\nHuman: ${prompt} \\n\\nAssistant:"),
ANTHROPIC("\n\nHuman: ${prompt} \n\nAssistant:"),
MISTRAL("<s>[INST] ${prompt} [/INST]"),
NONE("${prompt}");

Check warning on line 22 in src/main/java/org/opensearch/agent/tools/utils/LLMProvider.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/agent/tools/utils/LLMProvider.java#L19-L22

Added lines #L19 - L22 were not covered by tests

Expand Down

0 comments on commit 3d6b01f

Please sign in to comment.