Prev Next

AI / LangGraph LangChain Interview questions II

What are the different memory types in LangChain?

LangChain provides several memory classes that differ in how they store and compress conversation history. Choosing the right one involves balancing context quality, token cost, and retrieval precision.

Memory TypeHow It WorksBest For
ConversationBufferMemoryStores every message verbatimShort conversations where full context matters
ConversationBufferWindowMemoryKeeps only the last k messagesLong conversations; avoids context overflow
ConversationSummaryMemoryUses an LLM to summarise older messagesVery long sessions; quality over token savings
ConversationSummaryBufferMemorySummarises messages beyond a token limit; keeps recent messages verbatimBalance between detail and cost
VectorStoreRetrieverMemoryStores messages as embeddings; retrieves semantically relevant past contextLong-running assistants that need to recall specific facts
ConversationEntityMemoryExtracts and tracks named entities (people, places, concepts) from conversationPersonal assistants that must remember facts about people/topics

In LCEL-based applications, the memory pattern has shifted from these classes towards explicitly managing a messages list in chain state (with RunnableWithMessageHistory for automatic persistence per session ID), or using LangGraph's checkpointing for full state persistence.

Which memory type keeps only the last k conversation messages to avoid context overflow?
When would VectorStoreRetrieverMemory be more useful than ConversationBufferMemory?

More Related questions...

Show more question and Answers...


Comments & Discussions