Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryChat MessagesMemory typesConversation BufferConversation Buffer WindowEntityConversation Knowledge GraphConversation SummaryConversation Summary BufferConversation Token BufferBacked by a Vector StoreMemory in LLMChainMemory in the Multi-Input ChainMemory in AgentMessage Memory in Agent backed by a databaseCustomizing Conversational MemoryCustom MemoryMultiple Memory classesAgentsCallbacksModulesSecurityGuidesMoreModulesMemoryMemory typesConversation Knowledge GraphOn this pageConversation Knowledge GraphThis type of memory uses a knowledge graph to recreate memory.Using memory with LLM‚Äãfrom langchain.memory import ConversationKGMemoryfrom langchain.llms import OpenAIllm = OpenAI(temperature=0)memory = ConversationKGMemory(llm=llm)memory.save_context({"input": "say hi to sam"}, {"output": "who is sam"})memory.save_context({"input": "sam is a friend"}, {"output": "okay"})memory.load_memory_variables({"input": "who is sam"})    {'history': 'On Sam: Sam is friend.'}We can also get the history as a list of messages (this is useful if you are using this with a chat model).memory = ConversationKGMemory(llm=llm, return_messages=True)memory.save_context({"input": "say hi to sam"}, {"output": "who is sam"})memory.save_context({"input": "sam is a friend"}, {"output": "okay"})memory.load_memory_variables({"input": "who is sam"})    {'history': [SystemMessage(content='On Sam: Sam is friend.', additional_kwargs={})]}We can also more modularly get current entities from a new message (will use previous messages as context).memory.get_current_entities("what's Sams favorite color?")    ['Sam']We can also more modularly get knowledge triplets from a new message (will use previous
This type of memory uses a knowledge graph to recreate memory.
This type of memory uses a knowledge graph to recreate memory. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryChat MessagesMemory typesConversation BufferConversation Buffer WindowEntityConversation Knowledge GraphConversation SummaryConversation Summary BufferConversation Token BufferBacked by a Vector StoreMemory in LLMChainMemory in the Multi-Input ChainMemory in AgentMessage Memory in Agent backed by a databaseCustomizing Conversational MemoryCustom MemoryMultiple Memory classesAgentsCallbacksModulesSecurityGuidesMoreModulesMemoryMemory typesConversation Knowledge GraphOn this pageConversation Knowledge GraphThis type of memory uses a knowledge graph to recreate memory.Using memory with LLM‚Äãfrom langchain.memory import ConversationKGMemoryfrom langchain.llms import OpenAIllm = OpenAI(temperature=0)memory = ConversationKGMemory(llm=llm)memory.save_context({"input": "say hi to sam"}, {"output": "who is sam"})memory.save_context({"input": "sam is a friend"}, {"output": "okay"})memory.load_memory_variables({"input": "who is sam"})    {'history': 'On Sam: Sam is friend.'}We can also get the history as a list of messages (this is useful if you are using this with a chat model).memory = ConversationKGMemory(llm=llm, return_messages=True)memory.save_context({"input": "say hi to sam"}, {"output": "who is sam"})memory.save_context({"input": "sam is a friend"}, {"output": "okay"})memory.load_memory_variables({"input": "who is sam"})    {'history': [SystemMessage(content='On Sam: Sam is friend.', additional_kwargs={})]}We can also more modularly get current entities from a new message (will use previous messages as context).memory.get_current_entities("what's Sams favorite color?")    ['Sam']We can also more modularly get knowledge triplets from a new message (will use previous