From 96ac05ea34ec1a2858ccb378abfd43562be6e31d Mon Sep 17 00:00:00 2001 From: Rithin Pullela Date: Fri, 3 Jan 2025 16:21:22 -0800 Subject: [PATCH] Revert "Add application_type to ConversationMeta; update tests (#3282)" (#3315) This reverts commit d09374c3feb277a514d641dbc7bf91dce19ec303. Signed-off-by: rithin-pullela-aws --- .../common/conversation/ConversationMeta.java | 22 ++++--------------- .../conversation/ConversationMetaTests.java | 12 +++------- .../GetConversationResponseTests.java | 6 ++--- .../GetConversationTransportActionTests.java | 2 +- .../GetConversationsResponseTests.java | 6 ++--- .../GetConversationsTransportActionTests.java | 10 ++++----- ...earchConversationalMemoryHandlerTests.java | 2 +- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationMeta.java b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationMeta.java index 5d847fbcd7..21ed608654 100644 --- a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationMeta.java +++ b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationMeta.java @@ -51,8 +51,6 @@ public class ConversationMeta implements Writeable, ToXContentObject { @Getter private String user; @Getter - private String applicationType; - @Getter private Map additionalInfos; /** @@ -76,9 +74,8 @@ public static ConversationMeta fromMap(String id, Map docFields) Instant updated = Instant.parse((String) docFields.get(ConversationalIndexConstants.META_UPDATED_TIME_FIELD)); String name = (String) docFields.get(ConversationalIndexConstants.META_NAME_FIELD); String user = (String) docFields.get(ConversationalIndexConstants.USER_FIELD); - String applicationType = (String) docFields.get(ConversationalIndexConstants.APPLICATION_TYPE_FIELD); Map additionalInfos = (Map) docFields.get(ConversationalIndexConstants.META_ADDITIONAL_INFO_FIELD); - return new ConversationMeta(id, created, updated, name, user, applicationType, additionalInfos); + return new ConversationMeta(id, created, updated, name, user, additionalInfos); } /** @@ -94,14 +91,13 @@ public static ConversationMeta fromStream(StreamInput in) throws IOException { Instant updated = in.readInstant(); String name = in.readString(); String user = in.readOptionalString(); - String applicationType = in.readOptionalString(); Map additionalInfos = null; if (in.getVersion().onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_ADDITIONAL_INFO)) { if (in.readBoolean()) { additionalInfos = in.readMap(StreamInput::readString, StreamInput::readString); } } - return new ConversationMeta(id, created, updated, name, user, applicationType, additionalInfos); + return new ConversationMeta(id, created, updated, name, user, additionalInfos); } @Override @@ -111,7 +107,6 @@ public void writeTo(StreamOutput out) throws IOException { out.writeInstant(updatedTime); out.writeString(name); out.writeOptionalString(user); - out.writeOptionalString(applicationType); if (out.getVersion().onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_ADDITIONAL_INFO)) { if (additionalInfos == null) { out.writeBoolean(false); @@ -134,10 +129,6 @@ public String toString() { + updatedTime.toString() + ", user=" + user - + ", applicationType=" - + applicationType - + ", additionalInfos=" - + additionalInfos + "}"; } @@ -151,10 +142,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContentObject.Para if (this.user != null) { builder.field(ConversationalIndexConstants.USER_FIELD, this.user); } - if (this.applicationType != null && !this.applicationType.trim().isEmpty()) { - builder.field(ConversationalIndexConstants.APPLICATION_TYPE_FIELD, this.applicationType); - } - if (this.additionalInfos != null && !additionalInfos.isEmpty()) { + if (this.additionalInfos != null) { builder.field(ConversationalIndexConstants.META_ADDITIONAL_INFO_FIELD, this.additionalInfos); } builder.endObject(); @@ -171,9 +159,7 @@ public boolean equals(Object other) { && Objects.equals(this.user, otherConversation.user) && Objects.equals(this.createdTime, otherConversation.createdTime) && Objects.equals(this.updatedTime, otherConversation.updatedTime) - && Objects.equals(this.name, otherConversation.name) - && Objects.equals(this.applicationType, otherConversation.applicationType) - && Objects.equals(this.additionalInfos, otherConversation.additionalInfos); + && Objects.equals(this.name, otherConversation.name); } } diff --git a/common/src/test/java/org/opensearch/ml/common/conversation/ConversationMetaTests.java b/common/src/test/java/org/opensearch/ml/common/conversation/ConversationMetaTests.java index 7666ab3bf2..aaa52ffcff 100644 --- a/common/src/test/java/org/opensearch/ml/common/conversation/ConversationMetaTests.java +++ b/common/src/test/java/org/opensearch/ml/common/conversation/ConversationMetaTests.java @@ -30,7 +30,7 @@ public class ConversationMetaTests { @Before public void setUp() { time = Instant.now(); - conversationMeta = new ConversationMeta("test_id", time, time, "test_name", "admin", "conversational-search", null); + conversationMeta = new ConversationMeta("test_id", time, time, "test_name", "admin", null); } @Test @@ -41,7 +41,6 @@ public void test_fromSearchHit() throws IOException { content.field(ConversationalIndexConstants.META_UPDATED_TIME_FIELD, time); content.field(ConversationalIndexConstants.META_NAME_FIELD, "meta name"); content.field(ConversationalIndexConstants.USER_FIELD, "admin"); - content.field(ConversationalIndexConstants.APPLICATION_TYPE_FIELD, "conversational-search"); content.field(ConversationalIndexConstants.META_ADDITIONAL_INFO_FIELD, Map.of("test_key", "test_value")); content.endObject(); @@ -52,7 +51,6 @@ public void test_fromSearchHit() throws IOException { assertEquals(conversationMeta.getId(), "cId"); assertEquals(conversationMeta.getName(), "meta name"); assertEquals(conversationMeta.getUser(), "admin"); - assertEquals(conversationMeta.getApplicationType(), "conversational-search"); assertEquals(conversationMeta.getAdditionalInfos().get("test_key"), "test_value"); } @@ -85,7 +83,6 @@ public void test_fromStream() throws IOException { assertEquals(meta.getId(), conversationMeta.getId()); assertEquals(meta.getName(), conversationMeta.getName()); assertEquals(meta.getUser(), conversationMeta.getUser()); - assertEquals(meta.getApplicationType(), conversationMeta.getApplicationType()); } @Test @@ -96,7 +93,6 @@ public void test_ToXContent() throws IOException { Instant.ofEpochMilli(123), "test meta", "admin", - "neural-search", null ); XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent()); @@ -104,7 +100,7 @@ public void test_ToXContent() throws IOException { String content = TestHelper.xContentBuilderToString(builder); assertEquals( content, - "{\"memory_id\":\"test_id\",\"create_time\":\"1970-01-01T00:00:00.123Z\",\"updated_time\":\"1970-01-01T00:00:00.123Z\",\"name\":\"test meta\",\"user\":\"admin\",\"application_type\":\"neural-search\"}" + "{\"memory_id\":\"test_id\",\"create_time\":\"1970-01-01T00:00:00.123Z\",\"updated_time\":\"1970-01-01T00:00:00.123Z\",\"name\":\"test meta\",\"user\":\"admin\"}" ); } @@ -116,11 +112,10 @@ public void test_toString() { Instant.ofEpochMilli(123), "test meta", "admin", - "conversational-search", null ); assertEquals( - "{id=test_id, name=test meta, created=1970-01-01T00:00:00.123Z, updated=1970-01-01T00:00:00.123Z, user=admin, applicationType=conversational-search, additionalInfos=null}", + "{id=test_id, name=test meta, created=1970-01-01T00:00:00.123Z, updated=1970-01-01T00:00:00.123Z, user=admin}", conversationMeta.toString() ); } @@ -133,7 +128,6 @@ public void test_equal() { Instant.ofEpochMilli(123), "test meta", "admin", - "conversational-search", null ); assertEquals(meta.equals(conversationMeta), false); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationResponseTests.java index 08a285ec90..0b39d546f8 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationResponseTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationResponseTests.java @@ -38,7 +38,7 @@ public class GetConversationResponseTests extends OpenSearchTestCase { public void testGetConversationResponseStreaming() throws IOException { - ConversationMeta convo = new ConversationMeta("cid", Instant.now(), Instant.now(), "name", null, null, null); + ConversationMeta convo = new ConversationMeta("cid", Instant.now(), Instant.now(), "name", null, null); GetConversationResponse response = new GetConversationResponse(convo); assert (response.getConversation().equals(convo)); @@ -51,7 +51,7 @@ public void testGetConversationResponseStreaming() throws IOException { } public void testToXContent() throws IOException { - ConversationMeta convo = new ConversationMeta("cid", Instant.now(), Instant.now(), "name", null, null, null); + ConversationMeta convo = new ConversationMeta("cid", Instant.now(), Instant.now(), "name", null, null); GetConversationResponse response = new GetConversationResponse(convo); XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent()); response.toXContent(builder, ToXContent.EMPTY_PARAMS); @@ -68,7 +68,7 @@ public void testToXContent() throws IOException { public void testToXContent_withAdditionalInfo() throws IOException { Map additionalInfos = Map.of("key1", "value1"); - ConversationMeta convo = new ConversationMeta("cid", Instant.now(), Instant.now(), "name", null, null, additionalInfos); + ConversationMeta convo = new ConversationMeta("cid", Instant.now(), Instant.now(), "name", null, additionalInfos); GetConversationResponse response = new GetConversationResponse(convo); XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent()); response.toXContent(builder, ToXContent.EMPTY_PARAMS); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationTransportActionTests.java index aa85a8507d..558ecd9b65 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationTransportActionTests.java @@ -107,7 +107,7 @@ public void setup() throws IOException { } public void testGetConversation() { - ConversationMeta result = new ConversationMeta("test-cid", Instant.now(), Instant.now(), "name", null, null, null); + ConversationMeta result = new ConversationMeta("test-cid", Instant.now(), Instant.now(), "name", null, null); doAnswer(invocation -> { ActionListener listener = invocation.getArgument(1); listener.onResponse(result); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java index 71982e6a76..b28ed26d0f 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java @@ -46,9 +46,9 @@ public class GetConversationsResponseTests extends OpenSearchTestCase { public void setup() { conversations = List .of( - new ConversationMeta("0", Instant.now(), Instant.now(), "name0", "user0", null, null), - new ConversationMeta("1", Instant.now(), Instant.now(), "name1", "user0", null, null), - new ConversationMeta("2", Instant.now(), Instant.now(), "name2", "user2", null, null) + new ConversationMeta("0", Instant.now(), Instant.now(), "name0", "user0", null), + new ConversationMeta("1", Instant.now(), Instant.now(), "name1", "user0", null), + new ConversationMeta("2", Instant.now(), Instant.now(), "name2", "user2", null) ); } diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java index 257c74f1bb..a866167d37 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java @@ -114,8 +114,8 @@ public void testGetConversations() { log.info("testing get conversations transport"); List testResult = List .of( - new ConversationMeta("testcid1", Instant.now(), Instant.now(), "", null, null, null), - new ConversationMeta("testcid2", Instant.now(), Instant.now(), "testname", null, null, null) + new ConversationMeta("testcid1", Instant.now(), Instant.now(), "", null, null), + new ConversationMeta("testcid2", Instant.now(), Instant.now(), "testname", null, null) ); doAnswer(invocation -> { ActionListener> listener = invocation.getArgument(2); @@ -132,9 +132,9 @@ public void testGetConversations() { public void testPagination() { List testResult = List .of( - new ConversationMeta("testcid1", Instant.now(), Instant.now(), "", null, null, null), - new ConversationMeta("testcid2", Instant.now(), Instant.now(), "testname", null, null, null), - new ConversationMeta("testcid3", Instant.now(), Instant.now(), "testname", null, null, null) + new ConversationMeta("testcid1", Instant.now(), Instant.now(), "", null, null), + new ConversationMeta("testcid2", Instant.now(), Instant.now(), "testname", null, null), + new ConversationMeta("testcid3", Instant.now(), Instant.now(), "testname", null, null) ); doAnswer(invocation -> { ActionListener> listener = invocation.getArgument(2); diff --git a/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java index fc63811d2c..903be08338 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java @@ -315,7 +315,7 @@ public void testSearchInteractions_Future() { } public void testGetAConversation_Future() { - ConversationMeta response = new ConversationMeta("cid", Instant.now(), Instant.now(), "boring name", null, null, null); + ConversationMeta response = new ConversationMeta("cid", Instant.now(), Instant.now(), "boring name", null, null); doAnswer(invocation -> { ActionListener listener = invocation.getArgument(1); listener.onResponse(response);