Bird
0
0

Given the following code snippet, what will be the output after the second question?

medium📝 component behavior Q13 of 15
LangChain - Conversational RAG
Given the following code snippet, what will be the output after the second question?
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory

llm = SomeLLM()
memory = ConversationBufferMemory()
chain = ConversationChain(llm=llm, memory=memory)

print(chain.run("What is AI?"))
print(chain.run("And how does it learn?"))
AThe memory will reset after each question
BThe second answer will ignore the first question
CThe second answer will consider the first question's context
DThe code will raise a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand ConversationBufferMemory behavior

    This memory stores conversation history and passes it to the LLM for context.
  2. Step 2: Analyze the chain.run calls

    The second call to run uses the stored history, so the answer will reflect the first question's context.
  3. Final Answer:

    The second answer will consider the first question's context -> Option C
  4. Quick Check:

    Memory stores history = context-aware answers [OK]
Quick Trick: ConversationChain with memory keeps context across calls [OK]
Common Mistakes:
  • Assuming memory resets automatically
  • Thinking each run is independent
  • Expecting syntax errors from correct code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes