id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
59
127
56bd758afcb3-3
previous Typesense next Weaviate Contents Connecting to Vectara from LangChain Similarity search Similarity search with score Vectara as a Retriever By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/vectara.html
62b69586a7bf-0
.ipynb .pdf OpenSearch Contents Installation similarity_search using Approximate k-NN similarity_search using Script Scoring similarity_search using Painless Scripting Using a preexisting OpenSearch instance OpenSearch# OpenSearch is a scalable, flexible, and extensible open-source software suite for search, analytic...
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/opensearch.html
62b69586a7bf-1
embeddings = OpenAIEmbeddings() similarity_search using Approximate k-NN# similarity_search using Approximate k-NN Search with Custom Parameters docsearch = OpenSearchVectorSearch.from_documents( docs, embeddings, opensearch_url="http://localhost:9200" ) # If using the default Docker installation, use thi...
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/opensearch.html
62b69586a7bf-2
print(docs[0].page_content) similarity_search using Painless Scripting# similarity_search using Painless Scripting with Custom Parameters docsearch = OpenSearchVectorSearch.from_documents(docs, embeddings, opensearch_url="http://localhost:9200", is_appx_search=False) filter = {"bool": {"filter": {"term": {"text": "smug...
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/opensearch.html
b3df40fcb74b-0
.rst .pdf How-To Guides Contents Types Usage How-To Guides# Types# The first set of examples all highlight different types of memory. ConversationBufferMemory ConversationBufferWindowMemory Entity Memory Conversation Knowledge Graph Memory ConversationSummaryMemory ConversationSummaryBufferMemory ConversationTokenBuf...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/how_to_guides.html
30f6aa6eca1f-0
.ipynb .pdf Getting Started Contents ChatMessageHistory ConversationBufferMemory Using in a chain Saving Message History Getting Started# This notebook walks through how LangChain thinks about memory. Memory involves keeping a concept of state around throughout a user’s interactions with a language model. A user’s in...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/getting_started.html
30f6aa6eca1f-1
history.messages [HumanMessage(content='hi!', additional_kwargs={}, example=False), AIMessage(content='whats up?', additional_kwargs={}, example=False)] ConversationBufferMemory# We now show how to use this simple concept in a chain. We first showcase ConversationBufferMemory which is just a wrapper around ChatMessage...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/getting_started.html
30f6aa6eca1f-2
Current conversation: Human: Hi there! AI: > Finished chain. " Hi there! It's nice to meet you. How can I help you today?" conversation.predict(input="I'm doing well! Just having a conversation with an AI.") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation betw...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/getting_started.html
30f6aa6eca1f-3
Human: Tell me about yourself. AI: > Finished chain. " Sure! I'm an AI created to help people with their everyday tasks. I'm programmed to understand natural language and provide helpful information. I'm also constantly learning and updating my knowledge base so I can provide more accurate and helpful answers." Saving ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/getting_started.html
560886d0576f-0
.ipynb .pdf ConversationSummaryBufferMemory Contents Using in a chain ConversationSummaryBufferMemory# ConversationSummaryBufferMemory combines the last two ideas. It keeps a buffer of recent interactions in memory, but rather than just completely flushing old interactions it compiles them into a summary and uses bot...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary_buffer.html
560886d0576f-1
from langchain.chains import ConversationChain conversation_with_summary = ConversationChain( llm=llm, # We set a very low max_token_limit for the purposes of testing. memory=ConversationSummaryBufferMemory(llm=OpenAI(), max_token_limit=40), verbose=True ) conversation_with_summary.predict(input="Hi, w...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary_buffer.html
560886d0576f-2
> Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary_buffer.html
560886d0576f-3
Human: Haha nope, although a lot of people confuse it for that AI: > Finished chain. ' Oh, okay. What is LangChain?' previous ConversationSummaryMemory next ConversationTokenBufferMemory Contents Using in a chain By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary_buffer.html
ad65a1b14bfe-0
.ipynb .pdf Conversation Knowledge Graph Memory Contents Using in a chain Conversation Knowledge Graph Memory# This type of memory uses a knowledge graph to recreate memory. Let’s first walk through how to use the utilities from langchain.memory import ConversationKGMemory from langchain.llms import OpenAI llm = Open...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/kg.html
ad65a1b14bfe-1
llm = OpenAI(temperature=0) from langchain.prompts.prompt import PromptTemplate from langchain.chains import ConversationChain template = """The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/kg.html
ad65a1b14bfe-2
> Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. The AI ONLY uses info...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/kg.html
25dd9f0c002d-0
.ipynb .pdf ConversationTokenBufferMemory Contents Using in a chain ConversationTokenBufferMemory# ConversationTokenBufferMemory keeps a buffer of recent interactions in memory, and uses token length rather than number of interactions to determine when to flush interactions. Let’s first walk through how to use the ut...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/token_buffer.html
25dd9f0c002d-1
> Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/token_buffer.html
25dd9f0c002d-2
AI: Sounds like a productive day! What kind of documentation are you writing? Human: For LangChain! Have you heard of it? AI: > Finished chain. " Yes, I have heard of LangChain! It is a decentralized language-learning platform that connects native speakers and learners in real time. Is that the documentation you're wr...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/token_buffer.html
132518437337-0
.ipynb .pdf ConversationBufferMemory Contents Using in a chain ConversationBufferMemory# This notebook shows how to use ConversationBufferMemory. This memory allows for storing of messages and then extracts the messages in a variable. We can first extract it as a string. from langchain.memory import ConversationBuffe...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/buffer.html
132518437337-1
Current conversation: Human: Hi there! AI: > Finished chain. " Hi there! It's nice to meet you. How can I help you today?" conversation.predict(input="I'm doing well! Just having a conversation with an AI.") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation betw...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/buffer.html
132518437337-2
Human: Tell me about yourself. AI: > Finished chain. " Sure! I'm an AI created to help people with their everyday tasks. I'm programmed to understand natural language and provide helpful information. I'm also constantly learning and updating my knowledge base so I can provide more accurate and helpful answers." And tha...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/buffer.html
34b05a2ae821-0
.ipynb .pdf Entity Memory Contents Using in a chain Inspecting the memory store Entity Memory# This notebook shows how to work with a memory module that remembers things about specific entities. It extracts information on entities (using LLMs) and builds up its knowledge about that entity over time (also using LLMs)....
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-1
'entities': {'Sam': 'Sam is working on a hackathon project with Deven.'}} Using in a chain# Let’s now use it in a chain! from langchain.chains import ConversationChain from langchain.memory import ConversationEntityMemory from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE from pydantic import BaseM...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-2
Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist. Context: {'Deven': 'Deven is wor...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-3
You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-4
You are an assistant to a human, powered by a large language model trained by OpenAI. You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like t...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-5
AI: That sounds like a great project! What kind of project are they working on? Human: They are trying to add more complex memory structures to Langchain AI: That sounds like an interesting project! What kind of memory structures are they trying to add? Last line: Human: They are adding in a key-value store for entit...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-6
Context: {'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon. They are trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation.', 'Sam': 'Sam is working on a hackathon project with Deven, t...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-7
'Deven': 'Deven is working on a hackathon project with Sam, which they are ' 'entering into a hackathon. They are trying to add more complex ' 'memory structures to Langchain, including a key-value store for ' 'entities mentioned so far in the conversation, and seem to be ' 'work...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-8
You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-9
Human: Sam is the founder of a company called Daimon. AI: That's impressive! It sounds like Sam is a very successful entrepreneur. What kind of company is Daimon? Last line: Human: Sam is the founder of a company called Daimon. You: > Finished chain. " That's impressive! It sounds like Sam is a very successful entrepr...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-10
'for entities mentioned so far in the conversation. They seem to have ' 'a great idea for how the key-value store can help, and Sam is also ' 'the founder of a successful company called Daimon.'} conversation.predict(input="What do you know about Sam?") > Entering new ConversationChain chain... Prompt a...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-11
Context: {'Deven': 'Deven is working on a hackathon project with Sam, which they are entering into a hackathon. They are trying to add more complex memory structures to Langchain, including a key-value store for entities mentioned so far in the conversation, and seem to be working hard on this project with a great idea...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
34b05a2ae821-12
Last line: Human: What do you know about Sam? You: > Finished chain. ' Sam is the founder of a successful company called Daimon. He is also working on a hackathon project with Deven to add more complex memory structures to Langchain. They seem to have a great idea for how the key-value store can help.' previous Convers...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/entity_summary_memory.html
706d9f336096-0
.ipynb .pdf ConversationSummaryMemory Contents Initializing with messages Using in a chain ConversationSummaryMemory# Now let’s take a look at using a slightly more complex type of memory - ConversationSummaryMemory. This type of memory creates a summary of the conversation over time. This can be useful for condensin...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary.html
706d9f336096-1
history.add_user_message("hi") history.add_ai_message("hi there!") memory = ConversationSummaryMemory.from_messages(llm=OpenAI(temperature=0), chat_memory=history, return_messages=True) memory.buffer '\nThe human greets the AI, to which the AI responds with a friendly greeting.' Using in a chain# Let’s walk through an ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary.html
706d9f336096-2
Human: Tell me more about it! AI: > Finished chain. " Sure! The customer is having trouble with their computer not connecting to the internet. I'm helping them troubleshoot the issue and figure out what the problem is. So far, we've tried resetting the router and checking the network settings, but the issue still persi...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/summary.html
37fe949efa70-0
.ipynb .pdf VectorStore-Backed Memory Contents Initialize your VectorStore Create your the VectorStoreRetrieverMemory Using in a chain VectorStore-Backed Memory# VectorStoreRetrieverMemory stores memories in a VectorDB and queries the top-K most “salient” docs every time it is called. This differs from most of the ot...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/vectorstore_retriever_memory.html
37fe949efa70-1
memory = VectorStoreRetrieverMemory(retriever=retriever) # When added to an agent, the memory object can save pertinent information from conversations or used tools memory.save_context({"input": "My favorite food is pizza"}, {"output": "thats good to know"}) memory.save_context({"input": "My favorite sport is soccer"},...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/vectorstore_retriever_memory.html
37fe949efa70-2
memory=memory, verbose=True ) conversation_with_summary.predict(input="Hi, my name is Perry, what's up?") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context....
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/vectorstore_retriever_memory.html
37fe949efa70-3
> Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Relevant pieces of pre...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/vectorstore_retriever_memory.html
37fe949efa70-4
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/vectorstore_retriever_memory.html
e20f14994285-0
.ipynb .pdf ConversationBufferWindowMemory Contents Using in a chain ConversationBufferWindowMemory# ConversationBufferWindowMemory keeps a list of the interactions of the conversation over time. It only uses the last K interactions. This can be useful for keeping a sliding window of the most recent interactions, so ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/buffer_window.html
e20f14994285-1
memory=ConversationBufferWindowMemory(k=2), verbose=True ) conversation_with_summary.predict(input="Hi, what's up?") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/buffer_window.html
e20f14994285-2
Current conversation: Human: Hi, what's up? AI: Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you? Human: What's their issues? AI: The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected. Human: Is...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/types/buffer_window.html
d4e21149ba29-0
.ipynb .pdf Adding Message Memory backed by a database to an Agent Adding Message Memory backed by a database to an Agent# This notebook goes over adding memory to an Agent where the memory uses an external message store. Before going through this notebook, please walkthrough the following notebooks, as this will build...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-1
{chat_history} Question: {input} {agent_scratchpad}""" prompt = ZeroShotAgent.create_prompt( tools, prefix=prefix, suffix=suffix, input_variables=["input", "chat_history", "agent_scratchpad"] ) Now we can create the ChatMessageHistory backed by the database. message_history = RedisChatMessageHistory(...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-2
Action: Search Action Input: Population of Canada Observation: The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data. · Canada ... Additional information related to Canadian population trends can be found on Statistics Canada...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-3
> Finished AgentExecutor chain. 'The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data.' To test the memory of this agent, we can ask a followup question that relies on information in the previous exchange to be answered corr...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-4
Action: Search Action Input: National Anthem of Canada Observation: Jun 7, 2010 ... https://twitter.com/CanadaImmigrantCanadian National Anthem O Canada in HQ - complete with lyrics, captions, vocals & music.LYRICS:O Canada! Nov 23, 2022 ... After 100 years of tradition, O Canada was proclaimed Canada's national anthem...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-5
Thought: I now know the final answer. Final Answer: The national anthem of Canada is called "O Canada". > Finished AgentExecutor chain. 'The national anthem of Canada is called "O Canada".' We can see that the agent remembered that the previous question was about Canada, and properly asked Google Search what the name o...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-6
Action: Search Action Input: Population of Canada Observation: The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data. · Canada ... Additional information related to Canadian population trends can be found on Statistics Canada...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-7
> Finished AgentExecutor chain. 'The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data.' agent_without_memory.run("what is their national anthem called?") > Entering new AgentExecutor chain... Thought: I should look up the an...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-8
Action: Search Action Input: national anthem of [country] Observation: Most nation states have an anthem, defined as "a song, as of praise, devotion, or patriotism"; most anthems are either marches or hymns in style. List of all countries around the world with its national anthem. ... Title and lyrics in the language o...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
d4e21149ba29-9
Thought: I now know the final answer Final Answer: The national anthem of [country] is [name of anthem]. > Finished AgentExecutor chain. 'The national anthem of [country] is [name of anthem].' previous How to add Memory to an Agent next Cassandra Chat Message History By Harrison Chase © Copyright 2023, Harri...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory_in_db.html
ea464bc5e19f-0
.ipynb .pdf Motörhead Memory Contents Setup Motörhead Memory# Motörhead is a memory server implemented in Rust. It automatically handles incremental summarization in the background and allows for stateless applications. Setup# See instructions at Motörhead for running the server locally. from langchain.memory.motorhe...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/motorhead_memory.html
ea464bc5e19f-1
Human: whats my name? AI: > Finished chain. ' You said your name is Bob. Is that correct?' llm_chain.run("whats for dinner?") > Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human. Human: hi im bob AI: Hi Bob, nice to meet you! How are you doing today? Human: wh...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/motorhead_memory.html
ea4bf13547f9-0
.ipynb .pdf Cassandra Chat Message History Cassandra Chat Message History# This notebook goes over how to use Cassandra to store chat message history. Cassandra is a distributed database that is well suited for storing large amounts of data. It is a good choice for storing chat message history because it is easy to sca...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/cassandra_chat_message_history.html
4b39e55ee880-0
.ipynb .pdf Postgres Chat Message History Postgres Chat Message History# This notebook goes over how to use Postgres to store chat message history. from langchain.memory import PostgresChatMessageHistory history = PostgresChatMessageHistory(connection_string="postgresql://postgres:mypassword@localhost/chat_history", se...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/postgres_chat_message_history.html
c413563aab54-0
.ipynb .pdf Momento Chat Message History Momento Chat Message History# This notebook goes over how to use Momento Cache to store chat message history using the MomentoChatMessageHistory class. See the Momento docs for more detail on how to get set up with Momento. Note that, by default we will create a cache if one wit...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/momento_chat_message_history.html
88e0349dc8dc-0
.ipynb .pdf How to add Memory to an LLMChain How to add Memory to an LLMChain# This notebook goes over how to use the Memory class with an LLMChain. For the purposes of this walkthrough, we will add the ConversationBufferMemory class, although this can be any memory class. from langchain.memory import ConversationBuff...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/adding_memory.html
88e0349dc8dc-1
Human: Hi there my friend AI: Hi there, how are you doing today? Human: Not too bad - how are you? Chatbot: > Finished LLMChain chain. " I'm doing great, thank you for asking!" previous VectorStore-Backed Memory next How to add memory to a Multi-Input Chain By Harrison Chase © Copyright 2023, Harrison Chase...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/adding_memory.html
1e8996e2ab17-0
.ipynb .pdf Dynamodb Chat Message History Contents DynamoDBChatMessageHistory DynamoDBChatMessageHistory with Custom Endpoint URL Agent with DynamoDB Memory Dynamodb Chat Message History# This notebook goes over how to use Dynamodb to store chat message history. First make sure you have correctly configured the AWS C...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/dynamodb_chat_message_history.html
1e8996e2ab17-1
DynamoDBChatMessageHistory with Custom Endpoint URL# Sometimes it is useful to specify the URL to the AWS endpoint to connect to. For instance, when you are running locally against Localstack. For those cases you can specify the URL via the endpoint_url parameter in the constructor. from langchain.memory.chat_message_h...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/dynamodb_chat_message_history.html
1e8996e2ab17-2
} > Finished chain. 'Hello! How can I assist you today?' agent_chain.run(input="Who owns Twitter?") > Entering new AgentExecutor chain... { "action": "python_repl", "action_input": "import requests\nfrom bs4 import BeautifulSoup\n\nurl = 'https://en.wikipedia.org/wiki/Twitter'\nresponse = requests.get(url)\nsou...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/dynamodb_chat_message_history.html
1e8996e2ab17-3
Agent with DynamoDB Memory By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 16, 2023.
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/dynamodb_chat_message_history.html
55e8240e8eb0-0
.ipynb .pdf Mongodb Chat Message History Mongodb Chat Message History# This notebook goes over how to use Mongodb to store chat message history. MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/mongodb_chat_message_history.html
dda00043d278-0
.ipynb .pdf Motörhead Memory (Managed) Contents Setup Motörhead Memory (Managed)# Motörhead is a memory server implemented in Rust. It automatically handles incremental summarization in the background and allows for stateless applications. Setup# See instructions at Motörhead for running the managed version of Motorh...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/motorhead_memory_managed.html
dda00043d278-1
You are a chatbot having a conversation with a human. Human: hi im bob AI: Hi Bob, nice to meet you! How are you doing today? Human: whats my name? AI: > Finished chain. ' You said your name is Bob. Is that correct?' llm_chain.run("whats for dinner?") > Entering new LLMChain chain... Prompt after formatting: You are a...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/motorhead_memory_managed.html
e72f8be5c6bd-0
.ipynb .pdf How to create a custom Memory class How to create a custom Memory class# Although there are a few predefined types of memory in LangChain, it is highly possible you will want to add your own type of memory that is optimal for your application. This notebook covers how to do that. For this notebook, we will ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/custom_memory.html
e72f8be5c6bd-1
return [self.memory_key] def load_memory_variables(self, inputs: Dict[str, Any]) -> Dict[str, str]: """Load the memory variables, in this case the entity key.""" # Get the input text and run through spacy doc = nlp(inputs[list(inputs.keys())[0]]) # Extract known information about ent...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/custom_memory.html
e72f8be5c6bd-2
Conversation: Human: {input} AI:""" prompt = PromptTemplate( input_variables=["entities", "input"], template=template ) And now we put it all together! llm = OpenAI(temperature=0) conversation = ConversationChain(llm=llm, prompt=prompt, verbose=True, memory=SpacyEntityMemory()) In the first example, with no prior k...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/custom_memory.html
e72f8be5c6bd-3
Conversation: Human: What do you think Harrison's favorite subject in college was? AI: > Finished ConversationChain chain. ' From what I know about Harrison, I believe his favorite subject in college was machine learning. He has expressed a strong interest in the subject and has mentioned it often.' Again, please note ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/custom_memory.html
30c727db3e46-0
.ipynb .pdf Entity Memory with SQLite storage Entity Memory with SQLite storage# In this walkthrough we’ll create a simple conversation chain which uses ConversationEntityMemory backed by a SqliteEntityStore. from langchain.chains import ConversationChain from langchain.llms import OpenAI from langchain.memory import C...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/entity_memory_with_sqlite.html
30c727db3e46-1
You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/entity_memory_with_sqlite.html
848ef5dce238-0
.ipynb .pdf Redis Chat Message History Redis Chat Message History# This notebook goes over how to use Redis to store chat message history. from langchain.memory import RedisChatMessageHistory history = RedisChatMessageHistory("foo") history.add_user_message("hi!") history.add_ai_message("whats up?") history.messages [A...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/redis_chat_message_history.html
6ba733562c16-0
.ipynb .pdf How to add Memory to an Agent How to add Memory to an Agent# This notebook goes over adding memory to an Agent. Before going through this notebook, please walkthrough the following notebooks, as this will build on top of both of them: Adding memory to an LLM Chain Custom Agents In order to add a memory to a...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-1
) memory = ConversationBufferMemory(memory_key="chat_history") We can now construct the LLMChain, with the Memory object, and then create the agent. llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt) agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True) agent_chain = AgentExecutor.from_agent...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-2
Action: Search Action Input: Population of Canada Observation: The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data. · Canada ... Additional information related to Canadian population trends can be found on Statistics Canada...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-3
> Finished AgentExecutor chain. 'The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data.' To test the memory of this agent, we can ask a followup question that relies on information in the previous exchange to be answered corr...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-4
Action: Search Action Input: National Anthem of Canada Observation: Jun 7, 2010 ... https://twitter.com/CanadaImmigrantCanadian National Anthem O Canada in HQ - complete with lyrics, captions, vocals & music.LYRICS:O Canada! Nov 23, 2022 ... After 100 years of tradition, O Canada was proclaimed Canada's national anthem...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-5
Thought: I now know the final answer. Final Answer: The national anthem of Canada is called "O Canada". > Finished AgentExecutor chain. 'The national anthem of Canada is called "O Canada".' We can see that the agent remembered that the previous question was about Canada, and properly asked Google Search what the name o...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-6
Action: Search Action Input: Population of Canada Observation: The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data. · Canada ... Additional information related to Canadian population trends can be found on Statistics Canada...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-7
> Finished AgentExecutor chain. 'The current population of Canada is 38,566,192 as of Saturday, December 31, 2022, based on Worldometer elaboration of the latest United Nations data.' agent_without_memory.run("what is their national anthem called?") > Entering new AgentExecutor chain... Thought: I should look up the an...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-8
Action: Search Action Input: national anthem of [country] Observation: Most nation states have an anthem, defined as "a song, as of praise, devotion, or patriotism"; most anthems are either marches or hymns in style. List of all countries around the world with its national anthem. ... Title and lyrics in the language o...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
6ba733562c16-9
Thought: I now know the final answer Final Answer: The national anthem of [country] is [name of anthem]. > Finished AgentExecutor chain. 'The national anthem of [country] is [name of anthem].' previous How to add memory to a Multi-Input Chain next Adding Message Memory backed by a database to an Agent By Harrison Chase...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/agent_with_memory.html
691258fc3e99-0
.ipynb .pdf How to customize conversational memory Contents AI Prefix Human Prefix How to customize conversational memory# This notebook walks through a few ways to customize conversational memory. from langchain.llms import OpenAI from langchain.chains import ConversationChain from langchain.memory import Conversati...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/conversational_customization.html
691258fc3e99-1
Current conversation: Human: Hi there! AI: Hi there! It's nice to meet you. How can I help you today? Human: What's the weather? AI: > Finished ConversationChain chain. ' The current weather is sunny and warm with a temperature of 75 degrees Fahrenheit. The forecast for the next few days is sunny with temperatures in ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/conversational_customization.html
691258fc3e99-2
> Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/conversational_customization.html
691258fc3e99-3
memory=ConversationBufferMemory(human_prefix="Friend") ) conversation.predict(input="Hi there!") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI do...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/conversational_customization.html
a3f8ce2178d9-0
.ipynb .pdf How to use multiple memory classes in the same chain How to use multiple memory classes in the same chain# It is also possible to use multiple memory classes in the same chain. To combine multiple memory classes, we can initialize the CombinedMemory class, and then use that. from langchain.llms import OpenA...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/multiple_memory.html
a3f8ce2178d9-1
Summary of conversation: Current conversation: Human: Hi! AI: > Finished chain. ' Hi there! How can I help you?' conversation.run("Can you tell me a joke?") > Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and prov...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/multiple_memory.html
63cad9945ed4-0
.ipynb .pdf Zep Memory Contents REACT Agent Chat Message History Example Initialize the Zep Chat Message History Class and initialize the Agent Add some history data Run the agent Inspect the Zep memory Vector search over the Zep memory Zep Memory# REACT Agent Chat Message History Example# This notebook demonstrates ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html
63cad9945ed4-1
session_id = str(uuid4()) # This is a unique identifier for the user # Load your OpenAI key from a .env file from dotenv import load_dotenv load_dotenv() True Initialize the Zep Chat Message History Class and initialize the Agent# ddg = DuckDuckGoSearchRun() tools = [ddg] # Set up Zep Chat History zep_chat_history = Z...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html
63cad9945ed4-2
"The most well-known adaptation of Octavia Butler's work is the FX series" " Kindred, based on her novel of the same name." ), }, {"role": "human", "content": "Who were her contemporaries?"}, { "role": "ai", "content": ( "Octavia Butler's contemporaries includ...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html
63cad9945ed4-3
), }, ] for msg in test_history: zep_chat_history.append( HumanMessage(content=msg["content"]) if msg["role"] == "human" else AIMessage(content=msg["content"]) ) Run the agent# Doing so will automatically add the input and response to the Zep memory. agent_chain.run( input="WWhat...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html
63cad9945ed4-4
Ursula K. Le Guin, Samuel R. Delany, and Joanna Russ. {'role': 'human', 'content': 'What awards did she win?', 'uuid': '9fa75c3c-edae-41e3-b9bc-9fcf16b523c9', 'created_at': '2023-05-25T15:09:41.91662Z', 'token_count': 8} {'role': 'ai', 'content': 'Octavia Butler won the Hugo Award, the Nebula Award, and the MacArthur F...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html
63cad9945ed4-5
{'role': 'human', 'content': "Write a short synopsis of Butler's book, Parable of the Sower. What is it about?", 'uuid': '5678d056-7f05-4e70-b8e5-f85efa56db01', 'created_at': '2023-05-25T15:09:41.938974Z', 'token_count': 23} {'role': 'ai', 'content': 'Parable of the Sower is a science fiction novel by Octavia Butler, p...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html
63cad9945ed4-6
{'role': 'ai', 'content': 'Parable of the Sower is a prescient novel that speaks to the challenges facing contemporary society, such as climate change, economic inequality, and the rise of authoritarianism. It is a cautionary tale that warns of the dangers of ignoring these issues and the importance of taking action to...
rtdocs_stable/api.python.langchain.com/en/stable/modules/memory/examples/zep_memory.html