From 3fc5c82c37428ad36c5babe6aca76e2960280267 Mon Sep 17 00:00:00 2001 From: Xun Zhang Date: Wed, 22 Nov 2023 12:37:40 -0800 Subject: [PATCH] rename the conversation and interaction indices to memory meta and message Signed-off-by: Xun Zhang --- .../ConversationalIndexConstants.java | 4 +- .../ml/engine/tools/IndexMappingTool.java | 33 +++++++++------- .../engine/tools/IndexMappingToolTests.java | 39 +++++++++---------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java index 3650bae8c7..971ed8c171 100644 --- a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java +++ b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java @@ -26,7 +26,7 @@ public class ConversationalIndexConstants { /** Version of the meta index schema */ public final static Integer META_INDEX_SCHEMA_VERSION = 1; /** Name of the conversational metadata index */ - public final static String META_INDEX_NAME = ".plugins-ml-conversation-meta"; + public final static String META_INDEX_NAME = ".plugins-ml-memory-meta"; /** Name of the metadata field for initial timestamp */ public final static String META_CREATED_FIELD = "create_time"; /** Name of the metadata field for name of the conversation */ @@ -59,7 +59,7 @@ public class ConversationalIndexConstants { /** Version of the interactions index schema */ public final static Integer INTERACTIONS_INDEX_SCHEMA_VERSION = 1; /** Name of the conversational interactions index */ - public final static String INTERACTIONS_INDEX_NAME = ".plugins-ml-conversation-interactions"; + public final static String INTERACTIONS_INDEX_NAME = ".plugins-ml-memory-message"; /** Name of the interaction field for the conversation Id */ public final static String INTERACTIONS_CONVERSATION_ID_FIELD = "conversation_id"; /** Name of the interaction field for the human input */ diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/IndexMappingTool.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/IndexMappingTool.java index d36e590cb4..99a7955cd0 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/IndexMappingTool.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/IndexMappingTool.java @@ -5,8 +5,14 @@ package org.opensearch.ml.engine.tools; -import lombok.Getter; -import lombok.Setter; +import static org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest.DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT; +import static org.opensearch.ml.common.utils.StringUtils.gson; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + import org.apache.logging.log4j.util.Strings; import org.opensearch.action.admin.indices.get.GetIndexRequest; import org.opensearch.action.admin.indices.get.GetIndexResponse; @@ -20,13 +26,9 @@ import org.opensearch.ml.common.spi.tools.Parser; import org.opensearch.ml.common.spi.tools.Tool; import org.opensearch.ml.common.spi.tools.ToolAnnotation; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import static org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest.DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT; -import static org.opensearch.ml.common.utils.StringUtils.gson; +import lombok.Getter; +import lombok.Setter; @ToolAnnotation(IndexMappingTool.NAME) public class IndexMappingTool implements Tool { @@ -74,7 +76,7 @@ public void run(Map parameters, ActionListener listener) listener.onResponse(empty); return; } - + final String[] indices = indexList.toArray(Strings.EMPTY_ARRAY); final IndicesOptions indicesOptions = IndicesOptions.strictExpand(); @@ -96,16 +98,16 @@ public void onResponse(GetIndexResponse getIndexResponse) { StringBuilder sb = new StringBuilder(); for (String index : getIndexResponse.indices()) { sb.append("index: ").append(index).append("\n\n"); - + MappingMetadata mapping = getIndexResponse.mappings().get(index); if (mapping != null) { sb.append("mappings:\n"); - for (Entry entry: mapping.sourceAsMap().entrySet()) { - sb.append(entry.getKey()).append("=").append(entry.getValue()).append('\n'); - } + for (Entry entry : mapping.sourceAsMap().entrySet()) { + sb.append(entry.getKey()).append("=").append(entry.getValue()).append('\n'); + } sb.append("\n\n"); } - + Settings settings = getIndexResponse.settings().get(index); if (settings != null) { sb.append("settings:\n").append(settings.toDelimitedString('\n')).append("\n\n"); @@ -126,7 +128,8 @@ public void onFailure(final Exception e) { } }; - final GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indices) + final GetIndexRequest getIndexRequest = new GetIndexRequest() + .indices(indices) .indicesOptions(indicesOptions) .local(local) .clusterManagerNodeTimeout(clusterManagerNodeTimeout); diff --git a/ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/IndexMappingToolTests.java b/ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/IndexMappingToolTests.java index 1c6c441b1c..9585b0b953 100644 --- a/ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/IndexMappingToolTests.java +++ b/ml-algorithms/src/test/java/org/opensearch/ml/engine/tools/IndexMappingToolTests.java @@ -5,14 +5,12 @@ package org.opensearch.ml.engine.tools; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opensearch.core.action.ActionListener; -import org.opensearch.core.common.Strings; -import org.opensearch.ml.common.spi.tools.Tool; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.Collections; @@ -21,6 +19,11 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.opensearch.action.admin.indices.get.GetIndexResponse; import org.opensearch.client.AdminClient; import org.opensearch.client.Client; @@ -29,13 +32,9 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.json.JsonXContent; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; +import org.opensearch.core.action.ActionListener; +import org.opensearch.core.common.Strings; +import org.opensearch.ml.common.spi.tools.Tool; public class IndexMappingToolTests { @@ -68,7 +67,6 @@ public void setup() { emptyParams = Collections.emptyMap(); } - @Test public void testRunAsyncNoIndexParams() throws Exception { Tool tool = IndexMappingTool.Factory.getInstance().create(Collections.emptyMap()); @@ -80,7 +78,7 @@ public void testRunAsyncNoIndexParams() throws Exception { future.join(); assertEquals("There were no results searching the index parameter [null].", future.get()); } - + @Test public void testRunAsyncNoIndices() throws Exception { Tool tool = IndexMappingTool.Factory.getInstance().create(Collections.emptyMap()); @@ -92,7 +90,7 @@ public void testRunAsyncNoIndices() throws Exception { future.join(); assertEquals("There were no results searching the index parameter [null].", future.get()); } - + @Test public void testRunAsyncNoResults() throws Exception { @SuppressWarnings("unchecked") @@ -164,9 +162,8 @@ public void testRunAsyncIndexMapping() throws Exception { assertTrue(responseList.contains("mappings:")); assertTrue( - responseList.contains( - "mappings={year={full_name=year, mapping={year={type=text}}}, age={full_name=age, mapping={age={type=integer}}}}" - ) + responseList + .contains("mappings={year={full_name=year, mapping={year={type=text}}}, age={full_name=age, mapping={age={type=integer}}}}") ); assertTrue(responseList.contains("settings:"));