JdbcChatMemoryRepository is a ChatMemoryRepository implementation that stores conversational history in a relational database through JDBC, allowing chat memory to survive application restarts. section 5.4.1
Configure it by:
- Providing a relational database and JDBC driver, such as PostgreSQL. section 5.4.1
- Creating the repository with a DataSource and PostgresChatMemoryRepositoryDialect. section 5.4.1
- Enabling schema initialization with spring.ai.chat.memory.repository.jdbc.initialize-schema=always. section 5.4.1
@Bean
ChatMemoryRepository chatMemoryRepository(DataSource dataSource) {
return JdbcChatMemoryRepository.builder()
.dialect(new PostgresChatMemoryRepositoryDialect())
.dataSource(dataSource)
.build();
}
The repository bean connects JDBC chat memory to the application’s DataSource and selects the PostgreSQL dialect. section 5.4.1
Conversation continuity
Two requests using the same conversation identifier let the assistant answer a follow-up question using earlier chat history. section 5.4.1
