Skip to content

Commit

Permalink
use DSEC order for the interaction history in chat agent
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt committed Nov 29, 2023
1 parent 06c0380 commit 4db5897
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Interaction>> internalListener = ActionListener.runBefore(listener, () -> threadContext.restore());
ActionListener<SearchResponse> al = ActionListener.wrap(response -> {
List<Interaction> result = new LinkedList<Interaction>();
for (SearchHit hit : response.getHits()) {
result.add(Interaction.fromSearchHit(hit));
result.add(0, Interaction.fromSearchHit(hit));
}
internalListener.onResponse(result);
}, e -> { internalListener.onFailure(e); });
Expand Down

0 comments on commit 4db5897

Please sign in to comment.