Memory in @LangChainAI is a big deal.
It was a lot to go through, but I broke it into bite-size chunks.
• 4 Memory Types Explained
• How to use Memory in a Chain
• How to add Memory to an Agent
Save this ↓
ConversationBufferMemory:
• Memory allows for storing of messages
• Extracts the messages in a variable.
Pro: Basic to understand/pickup
ConversationBufferWindowMemory:
• Only uses the last K messages.
Pro: Useful to keep the memory history small
ConversationSummaryMemory
• Creates a summary of the conversation over time.
Pro: Useful for condensing information from the conversation over time.
VectorStore-Backed Memory
• Stores memories in a VectorDB
• Queries the top-K most relevant docs
Pro:
- Doesn’t explicitly track the order of messages
- AI can remember relevant pieces of information that it was told earlier
How to Add Memory to a Chain
1) Setup Prompt and Memory
2) Initialize LLMChain
3) Call the LLMChain
How to Add Memory to an Agent
1) Create an LLMChain with memory.
2) Use the LLMChain to create a custom Agent.
How to Add Memory to Multi-Input Chain:
Last but not least:
It's also possible to combine memory classes in the same chain:
That's it!
Will be making a lot more demo projects with memory in the upcoming weeks! 🫡
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
