Bird
0
0

How can you programmatically clear the chat history stored in a ConversationBufferMemory instance?

hard📝 Application Q9 of 15
LangChain - Conversational RAG
How can you programmatically clear the chat history stored in a ConversationBufferMemory instance?
ARe-initialize the ConversationBufferMemory instance
BCall <code>memory.reset()</code> method
CSet <code>memory.history = []</code>
DCall the <code>clear()</code> method on <code>memory.chat_memory</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify how history is stored

    Chat messages are stored inside the chat_memory attribute of ConversationBufferMemory.
  2. Step 2: Use clear method on chat_memory

    Calling clear() on chat_memory empties the stored messages properly.
  3. Final Answer:

    Call the clear() method on memory.chat_memory -> Option D
  4. Quick Check:

    Clear chat_memory with clear() method [OK]
Quick Trick: Use chat_memory.clear() to empty history [OK]
Common Mistakes:
  • Trying to reset memory directly without chat_memory
  • Assigning empty list to history attribute
  • Assuming reset() method exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes