liveBook · Manning

VectorStoreChatMemoryAdvisor

As explained in Spring AI in Action

VectorStoreChatMemoryAdvisor is a Spring AI advisor that stores chat messages as embeddings in a vector store and retrieves relevant messages as conversational context.

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

How Spring AI in Action covers it

How deep it goes
Explains vector-store persistence, embeddings, similarity retrieval, prompt injection, and concise ChatClient configuration.
Examples
Uses a Board Game Buddy application and a ChatClient bean combining vector-store memory with document question answering.
What it assumes
Assumes familiarity with Spring AI ChatClient and VectorStore while contrasting advisor strategies from simpler chat-memory implementations.
What you can do after
Build it from scratch by registering a VectorStore-backed advisor and controlling conversation retrieval with request attributes.
How it connects
Connects conversational memory with RAG, ChatClient, VectorStore, QuestionAnswerAdvisor, and system prompts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.