Bird
0
0

What will be the output of print(memory.load_memory_variables({})) after this code?

medium📝 Predict Output Q5 of 15
LangChain - Conversational RAG
What will be the output of print(memory.load_memory_variables({})) after this code?
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory(return_messages=False)
memory.chat_memory.add_user_message('How are you?')
memory.chat_memory.add_ai_message('I am fine.')
A{"history": "Human: How are you?\nAI: I am fine."}
B{"history": ["Human: How are you?", "AI: I am fine."]}
C{"history": ""}
DAn error because return_messages is False
Step-by-Step Solution
Solution:
  1. Step 1: Understand return_messages=False effect

    When return_messages is False, the history is returned as a single string with messages separated by newlines.
  2. Step 2: Check message format

    Messages are prefixed with 'Human:' and 'AI:' and joined by newline characters.
  3. Final Answer:

    {"history": "Human: How are you?\nAI: I am fine."} -> Option A
  4. Quick Check:

    return_messages False returns string history [OK]
Quick Trick: False return_messages returns string joined by newlines [OK]
Common Mistakes:
  • Expecting list instead of string
  • Assuming empty history
  • Thinking it causes an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes