A chain will interact with its memory system twice in a given run.AFTER receiving the initial user inputs but BEFORE executing the core logic, a chain will READ from its memory system and augment the user inputs.AFTER executing the core logic but BEFORE returning the answer, a chain will WRITE the inputs and outputs of the current run to memory, so that they can be referred to in future runs.Building memory into a system‚ÄãThe two core design decisions in any memory system are:How state is storedHow state is queriedStoring: List of chat messages‚ÄãUnderlying any memory is a history of all chat interactions.
Even if these are not all used directly, they need to be stored in some form.
One of the key parts of the LangChain memory module is a series of integrations for storing these chat messages,
from in-memory lists to persistent databases.Chat message storage: How to work with Chat Messages, and the various integrations offered.Querying: Data structures and algorithms on top of chat messages‚ÄãKeeping a list of chat messages is fairly straight-forward.
What is less straight-forward are the data structures and algorithms built on top of chat messages that serve a view of those messages that is most useful.A very simply memory system might just return the most recent messages each run. A slightly more complex memory system might return a succinct summary of the past K messages.
An even more sophisticated system might extract entities from stored messages and only return information about entities referenced in the current run.Each application can have different requirements for how memory is queried. The memory module should make it easy to both get started with simple memory systems and write your own custom systems if needed.Memory types: The various data structures and algorithms that make up the memory types LangChain supportsGet started‚ÄãLet's take a look at what Memory actually looks like in LangChain.
Most LLM applications have a conversational interface. An essential component of a conversation is being able to refer to information introduced earlier in the conversation.
Most LLM applications have a conversational interface. An essential component of a conversation is being able to refer to information introduced earlier in the conversation. ->: A chain will interact with its memory system twice in a given run.AFTER receiving the initial user inputs but BEFORE executing the core logic, a chain will READ from its memory system and augment the user inputs.AFTER executing the core logic but BEFORE returning the answer, a chain will WRITE the inputs and outputs of the current run to memory, so that they can be referred to in future runs.Building memory into a system‚ÄãThe two core design decisions in any memory system are:How state is storedHow state is queriedStoring: List of chat messages‚ÄãUnderlying any memory is a history of all chat interactions.
Even if these are not all used directly, they need to be stored in some form.
One of the key parts of the LangChain memory module is a series of integrations for storing these chat messages,
from in-memory lists to persistent databases.Chat message storage: How to work with Chat Messages, and the various integrations offered.Querying: Data structures and algorithms on top of chat messages‚ÄãKeeping a list of chat messages is fairly straight-forward.
What is less straight-forward are the data structures and algorithms built on top of chat messages that serve a view of those messages that is most useful.A very simply memory system might just return the most recent messages each run. A slightly more complex memory system might return a succinct summary of the past K messages.
An even more sophisticated system might extract entities from stored messages and only return information about entities referenced in the current run.Each application can have different requirements for how memory is queried. The memory module should make it easy to both get started with simple memory systems and write your own custom systems if needed.Memory types: The various data structures and algorithms that make up the memory types LangChain supportsGet started‚ÄãLet's take a look at what Memory actually looks like in LangChain.