Redis Chat Memory Store

By default, Quarkus LangChain4j keeps chat memory in the application’s memory, so conversations are lost when the application stops or restarts. The Redis chat memory store persists the chat memory of your AI services in Redis. Conversations then survive restarts, and several instances of the application can share them.

See Messages and Memory for background on how chat memory works.

Dependency

To use Redis as the chat memory store, add the following Maven dependency:

<dependency>
  <groupId>io.quarkiverse.langchain4j</groupId>
  <artifactId>quarkus-langchain4j-memory-store-redis</artifactId>
  <version>1.15.0.CR1</version>
</dependency>

Even better, if you use the Quarkus platform BOM (default for projects generated), add the Quarkus Langchain4J BOM and all dependency versions will align:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-langchain4j-bom</artifactId> (1)
                <version>${quarkus.platform.version}</version> (2)
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
      <dependency>
        <groupId>io.quarkiverse.langchain4j</groupId>
        <artifactId>quarkus-langchain4j-memory-store-redis</artifactId>
        (3)
      </dependency>
    </dependencies>
1 In your dependencyManagement section, add the quarkus-langchain4j-bom
2 Inherit the version from your platform version
3 VoilĂ , no need for version alignment anymore

This extension builds on the Quarkus Redis client. Configure the Redis connection as described in that guide, for example:

quarkus.redis.hosts=redis://localhost:6379

In dev and test mode, if no hosts are configured, the Redis Dev Services start a Redis container automatically.

Unlike the Redis document store, the chat memory store only uses basic Redis commands, so it does not need the RedisJSON or RedisSearch modules.

Usage

The extension registers a ChatMemoryStore bean backed by Redis. Because it replaces the default in-memory store, AI services use it with no code changes:

@RegisterAiService
@ApplicationScoped
public interface Assistant {

    String chat(@MemoryId String conversationId, @UserMessage String message);
}

The memory window settings (such as quarkus.langchain4j.chat-memory.memory-window.max-messages) still apply: the store only holds the messages kept by the chat memory.

To delete a conversation from Redis, use ChatMemoryRemover:

ChatMemoryRemover.remove(assistant, conversationId);

Data Format

Each conversation is stored as a Redis string:

  • the key is the memory ID, converted to a string, with no prefix

  • the value is the list of messages, serialized as a JSON array

For example, after a short conversation with memory ID 01:

> GET 01
"[{\"contents\":[{\"text\":\"Hello, my name is Ricardo\",\"type\":\"TEXT\"}],\"attributes\":{},\"type\":\"USER\"},{\"toolExecutionRequests\":[],\"text\":\"Nice to meet you Ricardo\",\"attributes\":{},\"type\":\"AI\"}]"

The memory ID is used as the key as-is, and keys never expire. If the same Redis database holds other data, choose memory IDs that cannot collide with other keys, or use a dedicated Redis client (see below).

Using a Named Redis Client

By default, the store uses the default Redis client. To use a named Redis client instead, set its name:

quarkus.redis.memory.hosts=redis://memory-host:6379
quarkus.langchain4j.memorystore.redis.client-name=memory

Configuration Reference

All of these properties are fixed at build time.

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

The name of the Redis client to use. These clients are configured by means of the redis-client extension. If unspecified, it will use the default Redis client.

Environment variable: QUARKUS_LANGCHAIN4J_MEMORYSTORE_REDIS_CLIENT_NAME

string