diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java index efb025b07b..b6620bf8e2 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/memory/MLMemoryManager.java @@ -176,14 +176,14 @@ void innerGetFinalInteractions(String conversationId, int lastNInteraction, Acti searchRequest.source(searchSourceBuilder); searchRequest.source().size(lastNInteraction); - searchRequest.source().sort(ConversationalIndexConstants.INTERACTIONS_CREATE_TIME_FIELD, SortOrder.ASC); + searchRequest.source().sort(ConversationalIndexConstants.INTERACTIONS_CREATE_TIME_FIELD, SortOrder.DESC); try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { ActionListener> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore()); ActionListener al = ActionListener.wrap(response -> { List result = new LinkedList(); for (SearchHit hit : response.getHits()) { - result.add(Interaction.fromSearchHit(hit)); + result.add(0, Interaction.fromSearchHit(hit)); } internalListener.onResponse(result); }, e -> { internalListener.onFailure(e); });