0
0
LangChainframework~10 mins

Memory-augmented retrieval in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the memory class from LangChain.

LangChain
from langchain.memory import [1]
Drag options to blanks, or click blank then click option'
ARetrievalQA
BOpenAI
CConversationBufferMemory
DVectorStore
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like RetrievalQA or OpenAI.
Forgetting to import any memory class.
2fill in blank
medium

Complete the code to create a memory object that stores chat history.

LangChain
memory = [1]()
Drag options to blanks, or click blank then click option'
AConversationBufferMemory
BRetrievalQA
COpenAI
DVectorStoreRetriever
Attempts:
3 left
💡 Hint
Common Mistakes
Using classes meant for retrieval or language models instead of memory.
Calling a class that requires parameters when none are given.
3fill in blank
hard

Fix the error in the code to create a retrieval-augmented chain with memory.

LangChain
from langchain.chains import ConversationalRetrievalChain
from langchain.memory import ConversationBufferMemory

retriever = VectorStoreRetriever()
qa_chain = ConversationalRetrievalChain.from_llm(llm=OpenAI(), retriever=retriever, memory=[1])
Drag options to blanks, or click blank then click option'
ARetrievalQA()
BConversationBufferMemory
Cmemory
DConversationBufferMemory()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the class name without parentheses.
Passing an undefined variable.
4fill in blank
hard

Fill both blanks to create a memory-augmented retrieval chain that uses chat history and a retriever.

LangChain
from langchain.memory import [1]
from langchain.chains import ConversationalRetrievalChain

memory = [2]()
retriever = VectorStoreRetriever()
qa = ConversationalRetrievalChain.from_llm(llm=OpenAI(), retriever=retriever, memory=memory)
Drag options to blanks, or click blank then click option'
AConversationBufferMemory
BRetrievalQA
DOpenAI
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong class.
Not creating an instance before passing to the chain.
5fill in blank
hard

Fill all three blanks to build a retrieval-augmented chain with memory and run a query.

LangChain
from langchain.memory import [1]
from langchain.chains import ConversationalRetrievalChain

memory = [2]()
retriever = VectorStoreRetriever()
qa = ConversationalRetrievalChain.from_llm(llm=[3](), retriever=retriever, memory=memory)
result = qa.run("What is LangChain?")
Drag options to blanks, or click blank then click option'
AConversationBufferMemory
COpenAI
DRetrievalQA
Attempts:
3 left
💡 Hint
Common Mistakes
Not instantiating memory or the language model.
Using wrong classes for memory or LLM.