0
0
LangChainframework~30 mins

Memory-augmented retrieval in LangChain - Mini Project: Build & Apply

Choose your learning style9 modes available
Memory-augmented retrieval with LangChain
📖 Scenario: You are building a simple chatbot that remembers previous conversations to answer questions better. You will use LangChain's memory feature to store chat history and retrieve it during new queries.
🎯 Goal: Create a LangChain chatbot that uses memory to recall past messages and improve responses.
📋 What You'll Learn
Create a list called chat_history with two example messages
Create a variable called memory using ConversationBufferMemory
Create a ChatOpenAI instance called chat with model name gpt-3.5-turbo
Create a ConversationChain called conversation using chat and memory
💡 Why This Matters
🌍 Real World
Chatbots that remember past conversations provide better, more personalized answers. This is useful in customer support, virtual assistants, and interactive apps.
💼 Career
Understanding memory-augmented retrieval is key for building advanced conversational AI systems used in many tech companies.
Progress0 / 4 steps
1
Set up initial chat history
Create a list called chat_history with these two dictionaries exactly: {'role': 'user', 'content': 'Hello!'} and {'role': 'assistant', 'content': 'Hi! How can I help you?'}.
LangChain
Need a hint?

Use a Python list with two dictionaries inside. Each dictionary has keys 'role' and 'content'.

2
Create ConversationBufferMemory
Create a variable called memory by instantiating ConversationBufferMemory with memory_key='chat_history' and return_messages=True.
LangChain
Need a hint?

Import ConversationBufferMemory from langchain.memory and create memory with the specified parameters.

3
Create ChatOpenAI instance
Create a variable called chat by instantiating ChatOpenAI with model_name='gpt-3.5-turbo'.
LangChain
Need a hint?

Import ChatOpenAI from langchain.chat_models and create chat with the given model name.

4
Create ConversationChain with memory
Create a variable called conversation by instantiating ConversationChain with llm=chat and memory=memory.
LangChain
Need a hint?

Import ConversationChain from langchain.chains and create conversation with the given parameters.