Skip to content

Commit 9019cdc

Browse files
removing experimental from the Conversation memory feature (opensearch-project#2592) (opensearch-project#2600)
* removing experimental from the Conversation memory feature Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * reflecting another unit test Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> --------- Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> (cherry picked from commit c4cf1b2) Co-authored-by: Dhrubo Saha <dhrubo@amazon.com>
1 parent 93a1162 commit 9019cdc

21 files changed

+82
-116
lines changed

common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ConversationalIndexConstants {
4040
/** Mappings for the conversational metadata index */
4141
public final static String META_MAPPING = "{\n"
4242
+ " \"_meta\": {\n"
43-
+ " \"schema_version\": " + META_INDEX_SCHEMA_VERSION + "\n"
43+
+ " \"schema_version\": " + META_INDEX_SCHEMA_VERSION + "\n"
4444
+ " },\n"
4545
+ " \"properties\": {\n"
4646
+ " \""
@@ -86,7 +86,7 @@ public class ConversationalIndexConstants {
8686
/** Mappings for the interactions index */
8787
public final static String INTERACTIONS_MAPPINGS = "{\n"
8888
+ " \"_meta\": {\n"
89-
+ " \"schema_version\": " + INTERACTIONS_INDEX_SCHEMA_VERSION + "\n"
89+
+ " \"schema_version\": " + INTERACTIONS_INDEX_SCHEMA_VERSION + "\n"
9090
+ " },\n"
9191
+ " \"properties\": {\n"
9292
+ " \""
@@ -122,4 +122,6 @@ public class ConversationalIndexConstants {
122122
/** Feature Flag setting for conversational memory */
123123
public static final Setting<Boolean> ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting
124124
.boolSetting("plugins.ml_commons.memory_feature_enabled", true, Setting.Property.NodeScope, Setting.Property.Dynamic);
125-
}
125+
126+
public static final String ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE = "The Conversation Memory feature is not enabled. To enable, please update the setting " + ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey();
127+
}

memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import org.opensearch.OpenSearchException;
2123
import org.opensearch.action.support.ActionFilters;
2224
import org.opensearch.action.support.HandledTransportAction;
@@ -72,13 +74,7 @@ public CreateConversationTransportAction(
7274
@Override
7375
protected void doExecute(Task task, CreateConversationRequest request, ActionListener<CreateConversationResponse> actionListener) {
7476
if (!featureIsEnabled) {
75-
actionListener
76-
.onFailure(
77-
new OpenSearchException(
78-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
79-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
80-
)
81-
);
77+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8278
return;
8379
}
8480
String name = request.getName();

memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import java.util.HashMap;
2123
import java.util.Map;
2224

@@ -44,8 +46,8 @@
4446
@Log4j2
4547
public class CreateInteractionTransportAction extends HandledTransportAction<CreateInteractionRequest, CreateInteractionResponse> {
4648

47-
private ConversationalMemoryHandler cmHandler;
48-
private Client client;
49+
private final ConversationalMemoryHandler cmHandler;
50+
private final Client client;
4951

5052
private volatile boolean featureIsEnabled;
5153

@@ -77,13 +79,7 @@ public CreateInteractionTransportAction(
7779
@Override
7880
protected void doExecute(Task task, CreateInteractionRequest request, ActionListener<CreateInteractionResponse> actionListener) {
7981
if (!featureIsEnabled) {
80-
actionListener
81-
.onFailure(
82-
new OpenSearchException(
83-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
84-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
85-
)
86-
);
82+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8783
return;
8884
}
8985
String cid = request.getConversationId();
@@ -95,18 +91,18 @@ protected void doExecute(Task task, CreateInteractionRequest request, ActionList
9591
String parintIid = request.getParentIid();
9692
Integer traceNumber = request.getTraceNumber();
9793
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
98-
ActionListener<CreateInteractionResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
94+
ActionListener<CreateInteractionResponse> internalListener = ActionListener.runBefore(actionListener, context::restore);
9995
ActionListener<String> al = ActionListener.wrap(iid -> {
10096
cmHandler.updateConversation(cid, new HashMap<>(), getUpdateResponseListener(cid, iid, internalListener));
10197
log.info("Updating the memory {} after the message {} is created", cid, iid);
102-
}, e -> { internalListener.onFailure(e); });
98+
}, internalListener::onFailure);
10399
if (parintIid == null || traceNumber == null) {
104100
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al);
105101
} else {
106102
cmHandler.createInteraction(cid, inp, prompt, rsp, ogn, additionalInfo, al, parintIid, traceNumber);
107103
}
108104
} catch (Exception e) {
109-
log.error("Failed to create message for memory " + cid, e);
105+
log.error("Failed to create message for memory {}", cid, e);
110106
actionListener.onFailure(e);
111107
}
112108
}

memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import org.opensearch.OpenSearchException;
2123
import org.opensearch.action.support.ActionFilters;
2224
import org.opensearch.action.support.HandledTransportAction;
@@ -72,13 +74,7 @@ public DeleteConversationTransportAction(
7274
@Override
7375
public void doExecute(Task task, DeleteConversationRequest request, ActionListener<DeleteConversationResponse> listener) {
7476
if (!featureIsEnabled) {
75-
listener
76-
.onFailure(
77-
new OpenSearchException(
78-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
79-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
80-
)
81-
);
77+
listener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8278
return;
8379
}
8480
String conversationId = request.getId();

memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationTransportAction.java

+8-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import org.opensearch.OpenSearchException;
2123
import org.opensearch.action.support.ActionFilters;
2224
import org.opensearch.action.support.HandledTransportAction;
@@ -39,8 +41,8 @@
3941
*/
4042
@Log4j2
4143
public class GetConversationTransportAction extends HandledTransportAction<GetConversationRequest, GetConversationResponse> {
42-
private Client client;
43-
private ConversationalMemoryHandler cmHandler;
44+
private final Client client;
45+
private final ConversationalMemoryHandler cmHandler;
4446

4547
private volatile boolean featureIsEnabled;
4648

@@ -72,25 +74,18 @@ public GetConversationTransportAction(
7274
@Override
7375
public void doExecute(Task task, GetConversationRequest request, ActionListener<GetConversationResponse> actionListener) {
7476
if (!featureIsEnabled) {
75-
actionListener
76-
.onFailure(
77-
new OpenSearchException(
78-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
79-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
80-
)
81-
);
77+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8278
return;
8379
} else {
8480
String conversationId = request.getConversationId();
8581
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
86-
ActionListener<GetConversationResponse> internalListener = ActionListener
87-
.runBefore(actionListener, () -> context.restore());
82+
ActionListener<GetConversationResponse> internalListener = ActionListener.runBefore(actionListener, context::restore);
8883
ActionListener<ConversationMeta> al = ActionListener.wrap(conversationMeta -> {
8984
internalListener.onResponse(new GetConversationResponse(conversationMeta));
90-
}, e -> { internalListener.onFailure(e); });
85+
}, internalListener::onFailure);
9186
cmHandler.getConversation(conversationId, al);
9287
} catch (Exception e) {
93-
log.error("Failed to get memory " + conversationId, e);
88+
log.error("Failed to get memory {}", conversationId, e);
9489
actionListener.onFailure(e);
9590
}
9691

memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import java.util.List;
2123

2224
import org.opensearch.OpenSearchException;
@@ -42,8 +44,8 @@
4244
@Log4j2
4345
public class GetConversationsTransportAction extends HandledTransportAction<GetConversationsRequest, GetConversationsResponse> {
4446

45-
private Client client;
46-
private ConversationalMemoryHandler cmHandler;
47+
private final Client client;
48+
private final ConversationalMemoryHandler cmHandler;
4749

4850
private volatile boolean featureIsEnabled;
4951

@@ -75,19 +77,13 @@ public GetConversationsTransportAction(
7577
@Override
7678
public void doExecute(Task task, GetConversationsRequest request, ActionListener<GetConversationsResponse> actionListener) {
7779
if (!featureIsEnabled) {
78-
actionListener
79-
.onFailure(
80-
new OpenSearchException(
81-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
82-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
83-
)
84-
);
80+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8581
return;
8682
}
8783
int maxResults = request.getMaxResults();
8884
int from = request.getFrom();
8985
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
90-
ActionListener<GetConversationsResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
86+
ActionListener<GetConversationsResponse> internalListener = ActionListener.runBefore(actionListener, context::restore);
9187
ActionListener<List<ConversationMeta>> al = ActionListener.wrap(conversations -> {
9288
internalListener
9389
.onResponse(new GetConversationsResponse(conversations, from + maxResults, conversations.size() == maxResults));

memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionTransportAction.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import org.opensearch.OpenSearchException;
2123
import org.opensearch.action.support.ActionFilters;
2224
import org.opensearch.action.support.HandledTransportAction;
@@ -37,8 +39,8 @@
3739
@Log4j2
3840
public class GetInteractionTransportAction extends HandledTransportAction<GetInteractionRequest, GetInteractionResponse> {
3941

40-
private Client client;
41-
private ConversationalMemoryHandler cmHandler;
42+
private final Client client;
43+
private final ConversationalMemoryHandler cmHandler;
4244

4345
private volatile boolean featureIsEnabled;
4446

@@ -70,24 +72,18 @@ public GetInteractionTransportAction(
7072
@Override
7173
public void doExecute(Task task, GetInteractionRequest request, ActionListener<GetInteractionResponse> actionListener) {
7274
if (!featureIsEnabled) {
73-
actionListener
74-
.onFailure(
75-
new OpenSearchException(
76-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
77-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
78-
)
79-
);
75+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8076
return;
8177
}
8278
String interactionId = request.getInteractionId();
8379
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
84-
ActionListener<GetInteractionResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
80+
ActionListener<GetInteractionResponse> internalListener = ActionListener.runBefore(actionListener, context::restore);
8581
ActionListener<Interaction> al = ActionListener.wrap(interaction -> {
8682
internalListener.onResponse(new GetInteractionResponse(interaction));
87-
}, e -> { internalListener.onFailure(e); });
83+
}, internalListener::onFailure);
8884
cmHandler.getInteraction(interactionId, al);
8985
} catch (Exception e) {
90-
log.error("Failed to get message " + interactionId, e);
86+
log.error("Failed to get message {}", interactionId, e);
9187
actionListener.onFailure(e);
9288
}
9389
}

memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import java.util.List;
2123

2224
import org.opensearch.OpenSearchException;
@@ -42,8 +44,8 @@
4244
@Log4j2
4345
public class GetInteractionsTransportAction extends HandledTransportAction<GetInteractionsRequest, GetInteractionsResponse> {
4446

45-
private Client client;
46-
private ConversationalMemoryHandler cmHandler;
47+
private final Client client;
48+
private final ConversationalMemoryHandler cmHandler;
4749

4850
private volatile boolean featureIsEnabled;
4951

@@ -75,26 +77,20 @@ public GetInteractionsTransportAction(
7577
@Override
7678
public void doExecute(Task task, GetInteractionsRequest request, ActionListener<GetInteractionsResponse> actionListener) {
7779
if (!featureIsEnabled) {
78-
actionListener
79-
.onFailure(
80-
new OpenSearchException(
81-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
82-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
83-
)
84-
);
80+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8581
return;
8682
}
8783
int maxResults = request.getMaxResults();
8884
int from = request.getFrom();
8985
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
90-
ActionListener<GetInteractionsResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
86+
ActionListener<GetInteractionsResponse> internalListener = ActionListener.runBefore(actionListener, context::restore);
9187
ActionListener<List<Interaction>> al = ActionListener.wrap(interactions -> {
9288
internalListener
9389
.onResponse(new GetInteractionsResponse(interactions, from + maxResults, interactions.size() == maxResults));
94-
}, e -> { internalListener.onFailure(e); });
90+
}, internalListener::onFailure);
9591
cmHandler.getInteractions(request.getConversationId(), from, maxResults, al);
9692
} catch (Exception e) {
97-
log.error("Failed to get messages for memory " + request.getConversationId(), e);
93+
log.error("Failed to get messages for memory {}", request.getConversationId(), e);
9894
actionListener.onFailure(e);
9995
}
10096

memory/src/main/java/org/opensearch/ml/memory/action/conversation/SearchConversationsTransportAction.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import org.opensearch.OpenSearchException;
2123
import org.opensearch.action.search.SearchRequest;
2224
import org.opensearch.action.search.SearchResponse;
@@ -71,13 +73,7 @@ public SearchConversationsTransportAction(
7173
@Override
7274
public void doExecute(Task task, SearchRequest request, ActionListener<SearchResponse> actionListener) {
7375
if (!featureIsEnabled) {
74-
actionListener
75-
.onFailure(
76-
new OpenSearchException(
77-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
78-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
79-
)
80-
);
76+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8177
return;
8278
} else {
8379
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {

memory/src/main/java/org/opensearch/ml/memory/action/conversation/SearchInteractionsTransportAction.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.opensearch.ml.memory.action.conversation;
1919

20+
import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE;
21+
2022
import org.opensearch.OpenSearchException;
2123
import org.opensearch.action.search.SearchResponse;
2224
import org.opensearch.action.support.ActionFilters;
@@ -37,8 +39,8 @@
3739
@Log4j2
3840
public class SearchInteractionsTransportAction extends HandledTransportAction<SearchInteractionsRequest, SearchResponse> {
3941

40-
private ConversationalMemoryHandler cmHandler;
41-
private Client client;
42+
private final ConversationalMemoryHandler cmHandler;
43+
private final Client client;
4244

4345
private volatile boolean featureIsEnabled;
4446

@@ -70,17 +72,11 @@ public SearchInteractionsTransportAction(
7072
@Override
7173
public void doExecute(Task task, SearchInteractionsRequest request, ActionListener<SearchResponse> actionListener) {
7274
if (!featureIsEnabled) {
73-
actionListener
74-
.onFailure(
75-
new OpenSearchException(
76-
"The experimental Conversation Memory feature is not enabled. To enable, please update the setting "
77-
+ ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()
78-
)
79-
);
75+
actionListener.onFailure(new OpenSearchException(ML_COMMONS_MEMORY_FEATURE_DISABLED_MESSAGE));
8076
return;
8177
} else {
8278
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) {
83-
ActionListener<SearchResponse> internalListener = ActionListener.runBefore(actionListener, () -> context.restore());
79+
ActionListener<SearchResponse> internalListener = ActionListener.runBefore(actionListener, context::restore);
8480
cmHandler.searchInteractions(request.getConversationId(), request, internalListener);
8581
} catch (Exception e) {
8682
log.error("Failed to search memories", e);

0 commit comments

Comments
 (0)