Where does the new MemorySaver() of @langchain/langgraph actually store the chat history ? #6157
Unanswered
DevDeepakBhattarai
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The Here's an example of how to configure and use import { Redis } from "@upstash/redis";
import { BufferMemory } from "langchain/memory";
import { UpstashRedisChatMessageHistory } from "@langchain/community/stores/message/upstash_redis";
import { ChatOpenAI } from "langchain/openai";
import { ConversationChain } from "langchain/chains";
// Create your own Redis client
const client = new Redis({
url: "https://ADD_YOURS_HERE.upstash.io",
token: "********",
});
const memory = new BufferMemory({
chatHistory: new UpstashRedisChatMessageHistory({
sessionId: new Date().toISOString(),
sessionTTL: 300,
client, // You can reuse your existing Redis client
}),
});
const model = new ChatOpenAI({
model: "gpt-3.5-turbo",
temperature: 0,
});
const chain = new ConversationChain({ llm: model, memory });
const res1 = await chain.invoke({ input: "Hi! I'm Jim." });
console.log({ res1 });
const res2 = await chain.invoke({ input: "What did I just say my name was?" });
console.log({ res2 }); In this example:
This setup allows you to store and retrieve chat history in Redis using the persistence feature of Langgraph [1]. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 am trying to build a Chatbot with tool calling support using Langgraph. I am currently using the
ConversationSummaryBufferMemory
to summarize and store my messages in Upstash Redis. How can I change this approach use the Persistence feature of Langgraph.Is saving my chat history in Redis even possible using Langgraph persistence feature.
It would be great if someone could help me
System Info
pnpm 9.4.0
node 18
window 10
Beta Was this translation helpful? Give feedback.
All reactions