Package com.redis.vl.langchain4j
Class RedisVLChatMemoryStore
java.lang.Object
com.redis.vl.langchain4j.RedisVLChatMemoryStore
- All Implemented Interfaces:
dev.langchain4j.store.memory.chat.ChatMemoryStore
public class RedisVLChatMemoryStore
extends Object
implements dev.langchain4j.store.memory.chat.ChatMemoryStore
LangChain4J ChatMemoryStore implementation using Redis as the backend.
This store enables persistent conversation history storage in Redis, allowing chat sessions to be resumed across application restarts and supporting multi-user scenarios.
Messages are stored as JSON in Redis Lists, with each session having its own list key. This provides efficient append and retrieval operations.
Example usage:
// Create chat memory store
UnifiedJedis jedis = RedisClient.create("localhost", 6379);
ChatMemoryStore memoryStore = new RedisVLChatMemoryStore(jedis);
// Use with LangChain4J chat memory
ChatMemory chatMemory = MessageWindowChatMemory.builder()
.id("user-123")
.maxMessages(10)
.chatMemoryStore(memoryStore)
.build();
// Or with more control
ChatMemoryStore store = RedisVLChatMemoryStore.builder()
.jedis(jedis)
.keyPrefix("chat:history:")
.ttlSeconds(3600)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for RedisVLChatMemoryStore. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new RedisVLChatMemoryStore with default prefix.RedisVLChatMemoryStore(UnifiedJedis jedis, String keyPrefix) Creates a new RedisVLChatMemoryStore with custom prefix.RedisVLChatMemoryStore(UnifiedJedis jedis, String keyPrefix, Integer ttlSeconds) Creates a new RedisVLChatMemoryStore with custom prefix and TTL. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a builder for RedisVLChatMemoryStore.voiddeleteMessages(Object memoryId) getJedis()Gets the underlying Jedis client.Gets the key prefix.List<dev.langchain4j.data.message.ChatMessage> getMessages(Object memoryId) voidupdateMessages(Object memoryId, List<dev.langchain4j.data.message.ChatMessage> messages)
-
Constructor Details
-
RedisVLChatMemoryStore
Creates a new RedisVLChatMemoryStore with default prefix.- Parameters:
jedis- The Redis client
-
RedisVLChatMemoryStore
Creates a new RedisVLChatMemoryStore with custom prefix.- Parameters:
jedis- The Redis clientkeyPrefix- The key prefix for Redis keys
-
RedisVLChatMemoryStore
Creates a new RedisVLChatMemoryStore with custom prefix and TTL.- Parameters:
jedis- The Redis clientkeyPrefix- The key prefix for Redis keysttlSeconds- Optional TTL for conversation history (null for no expiration)
-
-
Method Details
-
getMessages
- Specified by:
getMessagesin interfacedev.langchain4j.store.memory.chat.ChatMemoryStore
-
updateMessages
public void updateMessages(Object memoryId, List<dev.langchain4j.data.message.ChatMessage> messages) - Specified by:
updateMessagesin interfacedev.langchain4j.store.memory.chat.ChatMemoryStore
-
deleteMessages
- Specified by:
deleteMessagesin interfacedev.langchain4j.store.memory.chat.ChatMemoryStore
-
getJedis
Gets the underlying Jedis client.- Returns:
- The Redis client
-
getKeyPrefix
Gets the key prefix.- Returns:
- The key prefix
-
builder
Creates a builder for RedisVLChatMemoryStore.- Returns:
- A new builder instance
-