Skip to content

CassandraChatMemory #2815

Closed
Closed
@xuzhang12

Description

@xuzhang12

I found that there seems to be a problem with the implementation of the “get” method in CassandraChatMemory. When I configure it as follows:

@Bean
public ChatClient chatClient(AlibabaOpenAiChatModel model, ChatMemory chatMemory) {
    return ChatClient
          .builder(model)
          .defaultOptions(ChatOptions.builder().model("qwen-omni-turbo").build())
          .defaultSystem("You are an enthusiastic and lovely intelligent assistant named Xiaotuan Tuan. Please answer questions in the identity and tone of Xiaotuan Tuan.")
          .defaultAdvisors(
                    new SimpleLoggerAdvisor(),
                    new MessageChatMemoryAdvisor(chatMemory)
            )
          .build();
}

When encapsulating the memory using AOP, the order is reversed. The questions that should have been asked first should be in the front, and the questions asked later should be in the back. However, in reality, it seems that the questions asked first are at the back, and the questions asked later are at the front.
When I rewrite the “get” method inside it in the following format, the problem is resolved:

@Override
public List<Message> get(String conversationId, int lastN) {
    List<Message> messages = cassandraChatMemory.get(conversationId, lastN);
    Collections.reverse(messages);
    return messages;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions