Replies: 2 comments
-
Hey there, @snavid! How can I assist you today? I found some similar issues and discussions that might help you resolve the problem with storing and retrieving conversation history in Redis using
To resolve the issue of storing and retrieving conversation history in Redis using
If the stored history appears empty and retrieves an empty list, ensure the following:
Here is a complete example: from langchain_redis import RedisChatMessageHistory
from langchain_core.messages import AIMessage, HumanMessage
# Instantiate the RedisChatMessageHistory
history = RedisChatMessageHistory(
session_id="your-session-id",
redis_url="redis://localhost:6379"
)
# Add messages
history.add_user_message("Hello, AI assistant!")
history.add_ai_message("Hello! How can I assist you today?")
# Retrieve messages
print("Chat History:")
for message in history.messages:
print(f"{type(message).__name__}: {message.content}") By following these steps, you should be able to store and retrieve conversation history in Redis effectively [8][9][10]. |
Beta Was this translation helpful? Give feedback.
-
Hey, I just had the same problem. Turns out you shouldn't use any special characters like '-' in keys. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I'm working on storing conversation history in a Redis database, but I'm encountering an issue. Specifically, the stored history appears to be empty, and when attempting to access it, the application retrieves an empty list.
Here are some details about my setup and issue:
Redis Connection: The Redis database is connected correctly.
The conversation history stored in Redis is not appearing as expected.
When accessing the stored history, I receive an empty list.
Configuration and Code:
[FT.CREATE chat_history ON HASH PREFIX 1 chat_history: SCHEMA session_id TEXT SORTABLE message TEXT SORTABLE timestamp NUMERIC SORTABLE
.] on redis cli.
Questions:
Are there any specific Redis configurations or settings that I might be missing?
System Info
python 311
Docker image redis
windows 11
Beta Was this translation helpful? Give feedback.
All reactions