liveBook · Manning

JdbcChatMemoryRepository

As explained in Spring AI in Action

JdbcChatMemoryRepository is a Spring AI ChatMemoryRepository implementation that persists chat history through JDBC in a relational database.

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

How Spring AI in Action covers it

How deep it goes
Shows database setup, bean construction, dialect selection, schema initialization, and conversation-level usage.
Examples
Uses PostgreSQL configuration and repeated HTTP requests with a shared conversation identifier.
What it assumes
Assumes a configured DataSource and existing ChatMemory integration.
What you can do after
Operate/configure persistent chat memory by registering a JDBC repository and connecting it to a relational DataSource.
How it connects
Connects ChatMemoryRepository, MessageWindowChatMemory, DataSource, JDBC, and PostgreSQL.

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.