VectorStoreChatMemoryAdvisor adds conversational memory to a Spring AI ChatClient by storing chat messages as embeddings and retrieving relevant history for each prompt. section 5.1 section 5.4.2
Its implementation provides:
- Similarity search over chat messages, rather than simply replaying the newest messages. section 5.4.2
- Relevant history injected into a system prompt as a string. section 5.1
- Conversation-specific control through CONVERSATION_ID and configurable chat-memory size. section 5.4.2
Registering the advisor
Provide the existing VectorStore to VectorStoreChatMemoryAdvisor.builder(vectorStore).build() and register it as a ChatClient default advisor, alongside QuestionAnswerAdvisor when conversations also use documents. section 5.4.2
Listing 5.4 Storing long-term memory in a vector store
@Bean
ChatClient chatClient(ChatClient.Builder chatClientBuilder,
VectorStore vectorStore) {
return chatClientBuilder
.defaultAdvisors(
VectorStoreChatMemoryAdvisor.builder(vectorStore).build(), #1
QuestionAnswerAdvisor.builder(vectorStore)
.searchRequest(SearchRequest.builder().build()).build())
.build();
}
Shows the concise ChatClient configuration for combining vector-store chat memory with document question answering. section 5.4.2
