id
stringlengths
14
16
text
stringlengths
45
2.05k
source
stringlengths
53
111
6512e81bd3f4-4
"question": "What profession does Nicholas Ray and Elia Kazan have in common?", "answer": "Thought 1: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common.\nAction 1: Search[Nicholas Ray]\nObservation 1: Nicholas Ray (born Raymond Nicholas Kienzle Jr., A...
https://langchain.readthedocs.io/en/latest/use_cases/generate_examples.html
6512e81bd3f4-5
"question": "Which magazine was started first Arthur’s Magazine or First for Women?", "answer": "Thought 1: I need to search Arthur’s Magazine and First for Women, and find which was started first.\nAction 1: Search[Arthur’s Magazine]\nObservation 1: Arthur’s Magazine (1844-1846) was an American literary periodical...
https://langchain.readthedocs.io/en/latest/use_cases/generate_examples.html
6512e81bd3f4-6
"answer": "Thought 1: I need to search Pavel Urysohn and Leonid Levin, find their types of work, then find if they are the same.\nAction 1: Search[Pavel Urysohn]\nObservation 1: Pavel Samuilovich Urysohn (February 3, 1898 - August 17, 1924) was a Soviet mathematician who is best known for his contributions in dimension...
https://langchain.readthedocs.io/en/latest/use_cases/generate_examples.html
6512e81bd3f4-7
'Action 2: Search[Missouri orogeny]', 'Observation 2: The Missouri orogeny was a major tectonic event that occurred in the late Pennsylvanian and early Permian period (about 300 million years ago).', 'Thought 3: The Illinois orogeny is hypothesized and occurred in the Late Paleozoic and the Missouri orogeny was a maj...
https://langchain.readthedocs.io/en/latest/use_cases/generate_examples.html
d1358bb189d0-0
.ipynb .pdf Model Comparison Model Comparison# Constructing your language model application will likely involved choosing between many different options of prompts, models, and even chains to use. When doing so, you will want to compare these different options on different inputs in an easy, flexible, and intuitive way...
https://langchain.readthedocs.io/en/latest/use_cases/model_laboratory.html
d1358bb189d0-1
pink prompt = PromptTemplate(template="What is the capital of {state}?", input_variables=["state"]) model_lab_with_prompt = ModelLaboratory.from_llms(llms, prompt=prompt) model_lab_with_prompt.compare("New York") Input: New York OpenAI Params: {'model': 'text-davinci-002', 'temperature': 0.0, 'max_tokens': 256, 'top_p'...
https://langchain.readthedocs.io/en/latest/use_cases/model_laboratory.html
d1358bb189d0-2
names = [str(open_ai_llm), str(cohere_llm)] model_lab = ModelLaboratory(chains, names=names) model_lab.compare("What is the hometown of the reigning men's U.S. Open champion?") Input: What is the hometown of the reigning men's U.S. Open champion? OpenAI Params: {'model': 'text-davinci-002', 'temperature': 0.0, 'max_tok...
https://langchain.readthedocs.io/en/latest/use_cases/model_laboratory.html
d1358bb189d0-3
> Finished chain. So the final answer is: Carlos Alcaraz previous SQL Question Answering Benchmarking: Chinook next Installation By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/use_cases/model_laboratory.html
80e7d89b4c2e-0
.md .pdf Question Answering Contents Document Question Answering Adding in sources Additional Related Resources Question Answering# Question answering in this context refers to question answering over your document data. For question answering over other types of data, like SQL databases or APIs, please see here For ...
https://langchain.readthedocs.io/en/latest/use_cases/question_answering.html
80e7d89b4c2e-1
from langchain.chains.question_answering import load_qa_chain chain = load_qa_chain(llm, chain_type="stuff") chain.run(input_documents=docs, question=query) The following resources exist: Question Answering Notebook: A notebook walking through how to accomplish this task. VectorDB Question Answering Notebook: A noteboo...
https://langchain.readthedocs.io/en/latest/use_cases/question_answering.html
80e7d89b4c2e-2
CombineDocuments Chains: A conceptual overview of specific types of chains by which you can accomplish this task. Data Augmented Generation: An overview of data augmented generation, which is the general concept of combining external data with LLMs (of which this is a subset). previous Data Augmented Generation next Su...
https://langchain.readthedocs.io/en/latest/use_cases/question_answering.html
04133414ca55-0
.md .pdf Agents Agents# Agents are systems that use a language model to interact with other tools. These can be used to do more grounded question/answering, interact with APIs, or even take actions. These agents can be used to power the next generation of personal assistants - systems that intelligently understand what...
https://langchain.readthedocs.io/en/latest/use_cases/agents.html
1b3c40134265-0
.md .pdf Chatbots Chatbots# Since language models are good at producing text, that makes them ideal for creating chatbots. Aside from the base prompts/LLMs, an important concept to know for Chatbots is memory. Most chat based applications rely on remembering what happened in previous interactions, which is memory is de...
https://langchain.readthedocs.io/en/latest/use_cases/chatbots.html
51c56b9b1fdb-0
.md .pdf Data Augmented Generation Contents Overview Related Literature Fetching Text Splitting Relevant Documents Augmenting Use Cases Data Augmented Generation# Overview# Language models are trained on large amounts of unstructured data, which makes them fantastic at general purpose text generation. However, there ...
https://langchain.readthedocs.io/en/latest/use_cases/combine_docs.html
51c56b9b1fdb-1
RAG: Retrieval Augmented Generation. This paper introduces RAG models where the parametric memory is a pre-trained seq2seq model and the non-parametric memory is a dense vector index of Wikipedia, accessed with a pre-trained neural retriever. REALM: Retrieval-Augmented Language Model Pre-Training. To capture knowledge ...
https://langchain.readthedocs.io/en/latest/use_cases/combine_docs.html
51c56b9b1fdb-2
and task the language model with summarizing it. Document Retrieval: One of the more common use cases involves fetching relevant documents or pieces of text from a large corpus of data. A common example of this is question answering over a private collection of documents. API Querying: Another common way to fetch data ...
https://langchain.readthedocs.io/en/latest/use_cases/combine_docs.html
51c56b9b1fdb-3
One concrete example of this is vector stores for document retrieval, often used for semantic search or question answering. With this method, larger documents are split up into smaller chunks and then each chunk of text is passed to an embedding function which creates an embedding for that piece of text. Those are embe...
https://langchain.readthedocs.io/en/latest/use_cases/combine_docs.html
51c56b9b1fdb-4
Text Splitting Relevant Documents Augmenting Use Cases By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/use_cases/combine_docs.html
c14da507fa0e-0
.md .pdf Summarization Summarization# Summarization involves creating a smaller summary of multiple longer documents. This can be useful for distilling long documents into the core pieces of information. The recommended way to get started using a summarization chain is: from langchain.chains.summarize import load_summa...
https://langchain.readthedocs.io/en/latest/use_cases/summarization.html
0a060ca34199-0
.md .pdf Querying Tabular Data Contents Document Loading Querying Chains Agents Querying Tabular Data# Lots of data and information is stored in tabular data, whether it be csvs, excel sheets, or SQL tables. This page covers all resources available in LangChain for working with data in this format. Document Loading# ...
https://langchain.readthedocs.io/en/latest/use_cases/tabular.html
ca869ba4fc0d-0
.ipynb .pdf Using Hugging Face Datasets Contents Setup Examples Predictions Evaluation Using Hugging Face Datasets# This example shows how to use Hugging Face datasets to evaluate models. Specifically, we show how to load examples to evaluate models on from Hugging Face’s dataset package. Setup# For demonstration pur...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/huggingface_datasets.html
ca869ba4fc0d-1
'You will not digest the watermelon seeds', 'The watermelon seeds will be excreted'], 'incorrect_answers': ['You grow watermelons in your stomach', 'You get sick', 'You have bad dreams', 'You die', 'You get indigestion', 'You fall unconscious', 'You digest the watermelon seeds'], 'source': 'https://wond...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/huggingface_datasets.html
ca869ba4fc0d-2
from langchain.evaluation.qa import QAEvalChain llm = OpenAI(temperature=0) eval_chain = QAEvalChain.from_llm(llm) graded_outputs = eval_chain.evaluate(examples, predictions, question_key="question", answer_key="best_answer", prediction_key="text") graded_outputs [{'text': ' INCORRECT'}, {'text': ' INCORRECT'}, {'tex...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/huggingface_datasets.html
ed403ac882a6-0
.ipynb .pdf QA Generation QA Generation# This notebook shows how to use the QAGenerationChain to come up with question-answer pairs over a specific document. This is important because often times you may not have data to evaluate your question-answer system over, so this is a cheap and lightweight way to generate it! f...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_generation.html
e5e48de863db-0
.ipynb .pdf Question Answering Benchmarking: State of the Union Address Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Question Answering Benchmarking: State of the Union Address# Here we go over how to benchmark performance on a question answering task over ...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
e5e48de863db-1
Dataset json downloaded and prepared to /Users/harrisonchase/.cache/huggingface/datasets/LangChainDatasets___json/LangChainDatasets--question-answering-state-of-the-union-a7e5a3b2db4f440d/0.0.0/0f7e3662623656454fcd2b650f34e886a7db4b9104504885bd462096cc7a9f51. Subsequent calls will reuse this data. Setting up a chain# N...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
e5e48de863db-2
Make many predictions# Now we can make predictions predictions = chain.apply(dataset) Evaluate performance# Now we can evaluate the predictions. The first thing we can do is look at them by eye. predictions[0] {'question': 'What is the purpose of the NATO Alliance?', 'answer': 'The purpose of the NATO Alliance is to s...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
e5e48de863db-3
'grade': ' INCORRECT'} previous Question Answering Benchmarking: Paul Graham Essay next QA Generation Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_sota.html
63c27553568f-0
.ipynb .pdf LLM Math Contents Setting up a chain LLM Math# Evaluating chains that know how to do math. # Comment this out if you are NOT using tracing import os os.environ["LANGCHAIN_HANDLER"] = "langchain" from langchain.evaluation.loading import load_dataset dataset = load_dataset("llm-math") Downloading and prepar...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/llm_math.html
63c27553568f-1
sum(correct) / len(correct) 1.0 for i, example in enumerate(dataset): print("input: ", example["question"]) print("expected output :", example["answer"]) print("prediction: ", numeric_output[i]) input: 5 expected output : 5.0 prediction: 5.0 input: 5 + 3 expected output : 8.0 prediction: 8.0 input: 2^3...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/llm_math.html
63c27553568f-2
next Question Answering Benchmarking: Paul Graham Essay Contents Setting up a chain By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/llm_math.html
24903b74c020-0
.ipynb .pdf Agent VectorDB Question Answering Benchmarking Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Agent VectorDB Question Answering Benchmarking# Here we go over how to benchmark performance on a question answering task using an agent to route between...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
24903b74c020-1
dataset[-1] {'question': 'What is the purpose of YC?', 'answer': 'The purpose of YC is to cause startups to be founded that would not otherwise have existed.', 'steps': [{'tool': 'Paul Graham QA System', 'tool_input': None}, {'tool': None, 'tool_input': 'What is the purpose of YC?'}]} Setting up a chain# Now we nee...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
24903b74c020-2
We can now set up an agent to route between them. from langchain.agents import initialize_agent, Tool tools = [ Tool( name = "State of Union QA System", func=chain_sota.run, description="useful for when you need to answer questions about the most recent state of the union address. Input shou...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
24903b74c020-3
'output': 'The purpose of the NATO Alliance is to promote peace and security in the North Atlantic region by providing a collective defense against potential threats.'} Next, we can use a language model to score them programatically from langchain.evaluation.qa import QAEvalChain llm = OpenAI(temperature=0) eval_chain ...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_vectordb_sota_pg.html
0a27933eb75f-0
.ipynb .pdf Agent Benchmarking: Search + Calculator Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Agent Benchmarking: Search + Calculator# Here we go over how to benchmark performance of an agent on tasks where it has access to a calculator and a search tool...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_benchmarking.html
0a27933eb75f-1
Make a prediction# First, we can make predictions one datapoint at a time. Doing it at this level of granularity allows use to explore the outputs in detail, and also is a lot cheaper than running over multiple datapoints agent.run(dataset[0]['question']) '38,630,316 people live in Canada as of 2023.' Make many predict...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_benchmarking.html
0a27933eb75f-2
eval_chain = QAEvalChain.from_llm(llm) graded_outputs = eval_chain.evaluate(dataset, predictions, question_key="question", prediction_key="output") We can add in the graded output to the predictions dict and then get a count of the grades. for i, prediction in enumerate(predictions): prediction['grade'] = graded_ou...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_benchmarking.html
0a27933eb75f-3
(AgentAction(tool='Search', tool_input='Isaac Carew age', log=' I need to find out Isaac\'s age\nAction: Search\nAction Input: "Isaac Carew age"'), '36 years'), (AgentAction(tool='Calculator', tool_input='36^.43', log=' I need to calculate 36 raised to the .43 power\nAction: Calculator\nAction Input: 36^.43'), ...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/agent_benchmarking.html
261f56248a7f-0
.ipynb .pdf Question Answering Contents Setup Examples Predictions Evaluation Customize Prompt Comparing to other evaluation metrics Question Answering# This notebook covers how to evaluate generic question answering problems. This is a situation where you have an example containing a question and its corresponding g...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/question_answering.html
261f56248a7f-1
predictions = chain.apply(examples) predictions [{'text': ' 11 tennis balls'}, {'text': ' No, this sentence is not plausible. Joao Moutinho is a professional soccer player, not an American football player, so it is not likely that he would be catching a screen pass in the NFC championship.'}] Evaluation# We can see th...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/question_answering.html
261f56248a7f-2
Real Answer: No Predicted Answer: No, this sentence is not plausible. Joao Moutinho is a professional soccer player, not an American football player, so it is not likely that he would be catching a screen pass in the NFC championship. Predicted Grade: CORRECT Customize Prompt# You can also customize the prompt that i...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/question_answering.html
261f56248a7f-3
for i, eg in enumerate(examples): eg['id'] = str(i) eg['answers'] = {"text": [eg['answer']], "answer_start": [0]} predictions[i]['id'] = str(i) predictions[i]['prediction_text'] = predictions[i]['text'] for p in predictions: del p['text'] new_examples = examples.copy() for eg in new_examples: de...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/question_answering.html
08aa7d09d9c1-0
.ipynb .pdf SQL Question Answering Benchmarking: Chinook Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance SQL Question Answering Benchmarking: Chinook# Here we go over how to benchmark performance on a question answering task over a SQL database. It is highly r...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/sql_qa_benchmarking_chinook.html
08aa7d09d9c1-1
{'question': 'How many employees are there?', 'answer': '8'} Setting up a chain# This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository. Note that here we load a simple c...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/sql_qa_benchmarking_chinook.html
08aa7d09d9c1-2
llm = OpenAI(temperature=0) eval_chain = QAEvalChain.from_llm(llm) graded_outputs = eval_chain.evaluate(predicted_dataset, predictions, question_key="question", prediction_key="result") We can add in the graded output to the predictions dict and then get a count of the grades. for i, prediction in enumerate(predictions...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/sql_qa_benchmarking_chinook.html
f84b8d1bb9c8-0
.ipynb .pdf Benchmarking Template Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Benchmarking Template# This is an example notebook that can be used to create a benchmarking notebook for a task of your choice. Evaluation is really hard, and so we greatly welc...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/benchmarking_template.html
f84b8d1bb9c8-1
# Othertimes you may want to write a for loop to catch errors Evaluate performance# Any guide to evaluating performance in a more systematic manner goes here. previous Agent VectorDB Question Answering Benchmarking next Data Augmented Question Answering Contents Loading the data Setting up a chain Make a prediction...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/benchmarking_template.html
7303eb6fa45b-0
.ipynb .pdf Question Answering Benchmarking: Paul Graham Essay Contents Loading the data Setting up a chain Make a prediction Make many predictions Evaluate performance Question Answering Benchmarking: Paul Graham Essay# Here we go over how to benchmark performance on a question answering task over a Paul Graham essa...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_pg.html
7303eb6fa45b-1
Now we can create a question answering chain. from langchain.chains import VectorDBQA from langchain.llms import OpenAI chain = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type="stuff", vectorstore=vectorstore, input_key="question") Make a prediction# First, we can make predictions one datapoint at a time. Doing it ...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_pg.html
7303eb6fa45b-2
from collections import Counter Counter([pred['grade'] for pred in predictions]) Counter({' CORRECT': 12, ' INCORRECT': 10}) We can also filter the datapoints to the incorrect examples and look at them. incorrect = [pred for pred in predictions if pred['grade'] == " INCORRECT"] incorrect[0] {'question': 'What did the a...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/qa_benchmarking_pg.html
6d63260414e0-0
.ipynb .pdf Data Augmented Question Answering Contents Setup Examples Evaluate Evaluate with Other Metrics Data Augmented Question Answering# This notebook uses some generic prompts/language models to evaluate an question answering system that uses other sources of data besides what is in the model. For example, this...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-1
"answer": "Nothing" } ] # Generated examples from langchain.evaluation.qa import QAGenerateChain example_gen_chain = QAGenerateChain.from_llm(OpenAI()) new_examples = example_gen_chain.apply_and_parse([{"doc": t} for t in texts[:5]]) new_examples [{'query': 'According to the document, what did Vladimir Putin miscal...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-2
eval_chain = QAEvalChain.from_llm(llm) graded_outputs = eval_chain.evaluate(examples, predictions) for i, eg in enumerate(examples): print(f"Example {i}:") print("Question: " + predictions[i]['query']) print("Real Answer: " + predictions[i]['answer']) print("Predicted Answer: " + predictions[i]['result'...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-3
Predicted Answer: I don't know. Predicted Grade: INCORRECT Example 4: Question: How many countries were part of the coalition formed to confront Putin? Real Answer: 27 members of the European Union, France, Germany, Italy, the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzer...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-4
Predicted Grade: CORRECT Evaluate with Other Metrics# In addition to predicting whether the answer is correct or incorrect using a language model, we can also use other metrics to get a more nuanced view on the quality of the answers. To do so, we can use the Critique library, which allows for simple calculation of va...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-5
for k, v in metrics.items() } Finally, we can print out the results. We can see that overall the scores are higher when the output is semantically correct, and also when the output closely matches with the gold-standard answer. for i, eg in enumerate(examples): score_string = ", ".join([f"{k}={v['examples'][i]['val...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-6
Example 2: Question: According to the document, what did Vladimir Putin miscalculate? Real Answer: He miscalculated that he could roll into Ukraine and the world would roll over. Predicted Answer: Putin miscalculated that the world would roll over when he rolled into Ukraine. Predicted Scores: rouge=0.5185, chrf=0.695...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
6d63260414e0-7
Question: What action is the U.S. Department of Justice taking to target Russian oligarchs? Real Answer: The U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs and joining with European allies to find and seize their yachts, luxury apartments, and private jets. P...
https://langchain.readthedocs.io/en/latest/use_cases/evaluation/data_augmented_question_answering.html
d8ae5e547eae-0
.rst .pdf Indexes Indexes# Indexes refer to ways to structure documents so that LLMs can best interact with them. This module contains utility functions for working with documents, different types of indexes, and then examples for using those indexes in chains. LangChain provides common indices for working with data (m...
https://langchain.readthedocs.io/en/latest/modules/indexes.html
2bf656e5b8e8-0
.rst .pdf Prompt Templates Prompt Templates# Language models take text as input - that text is commonly referred to as a prompt. Typically this is not simply a hardcoded string but rather a combination of a template, some examples, and user input. LangChain provides several classes and functions to make constructing an...
https://langchain.readthedocs.io/en/latest/modules/prompts.html
c38aa659f0e5-0
.rst .pdf Utils Utils# While LLMs are powerful on their own, they are more powerful when connected with other sources of knowledge or computation. This section highlights those sources of knowledge or computation, and goes over how to easily use them from within LangChain. The following sections of documentation are pr...
https://langchain.readthedocs.io/en/latest/modules/utils.html
3100ae2bf1fa-0
.rst .pdf Chains Chains# Using an LLM in isolation is fine for some simple applications, but many more complex ones require chaining LLMs - either with each other or with other experts. LangChain provides a standard interface for Chains, as well as some common implementations of chains for ease of use. The following se...
https://langchain.readthedocs.io/en/latest/modules/chains.html
fcc062094bff-0
.rst .pdf Agents Agents# Some applications will require not just a predetermined chain of calls to LLMs/other tools, but potentially an unknown chain that depends on the user’s input. In these types of chains, there is a “agent” which has access to a suite of tools. Depending on the user input, the agent can then decid...
https://langchain.readthedocs.io/en/latest/modules/agents.html
effc734a8ec8-0
.rst .pdf Memory Memory# By default, Chains and Agents are stateless, meaning that they treat each incoming query independently (as are the underlying LLMs and chat models). In some applications (chatbots being a GREAT example) it is highly important to remember previous interactions, both at a short term but also at a...
https://langchain.readthedocs.io/en/latest/modules/memory.html
d0ee91954b0e-0
.rst .pdf Document Loaders Document Loaders# Combining language models with your own text data is a powerful way to differentiate them. The first step in doing this is to load the data into “documents” - a fancy way of say some pieces of text. This module is aimed at making this easy. A primary driver of a lot of this ...
https://langchain.readthedocs.io/en/latest/modules/document_loaders.html
370392b37602-0
.rst .pdf LLMs LLMs# Large Language Models (LLMs) are a core component of LangChain. LangChain is not a provider of LLMs, but rather provides a standard interface through which you can interact with a variety of LLMs. The following sections of documentation are provided: Getting Started: An overview of all the function...
https://langchain.readthedocs.io/en/latest/modules/llms.html
b7fa56adf03e-0
.rst .pdf Chat Chat# Chat models are a variation on language models. While chat models use language models under the hood, the interface they expose is a bit different. Rather than expose a “text in, text out” API, they expose an interface where “chat messages” are the inputs and outputs. Chat model APIs are fairly new...
https://langchain.readthedocs.io/en/latest/modules/chat.html
7c49af275482-0
.md .pdf Key Concepts Contents Memory Conversational Memory Entity Memory Key Concepts# Memory# By default, Chains and Agents are stateless, meaning that they treat each incoming query independently. In some applications (chatbots being a GREAT example) it is highly important to remember previous interactions, both a...
https://langchain.readthedocs.io/en/latest/modules/memory/key_concepts.html
c973bf4b39bc-0
.rst .pdf How-To Guides Contents Types Usage How-To Guides# Types# The first set of examples all highlight different types of memory. Buffer: How to use a type of memory that just keeps previous messages in a buffer. Buffer Window: How to use a type of memory that keeps previous messages in a buffer but only uses the...
https://langchain.readthedocs.io/en/latest/modules/memory/how_to_guides.html
fa88bc0d832e-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 an language model. A user’s i...
https://langchain.readthedocs.io/en/latest/modules/memory/getting_started.html
fa88bc0d832e-1
history.messages [HumanMessage(content='hi!', additional_kwargs={}), AIMessage(content='whats up?', additional_kwargs={})] ConversationBufferMemory# We now show how to use this simple concept in a chain. We first showcase ConversationBufferMemory which is just a wrapper around ChatMessageHistory that extracts the mess...
https://langchain.readthedocs.io/en/latest/modules/memory/getting_started.html
fa88bc0d832e-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...
https://langchain.readthedocs.io/en/latest/modules/memory/getting_started.html
fa88bc0d832e-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 ...
https://langchain.readthedocs.io/en/latest/modules/memory/getting_started.html
2ebd857f9043-0
.ipynb .pdf ConversationBufferWindowMemory Contents ConversationBufferWindowMemory 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 th...
https://langchain.readthedocs.io/en/latest/modules/memory/types/buffer_window.html
2ebd857f9043-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 ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/buffer_window.html
2ebd857f9043-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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/buffer_window.html
ac6462d5dfe9-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)....
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-1
AIMessage(content=' That sounds like a great project! What kind of project are they working on?', additional_kwargs={})], '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 ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-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': '', 'Sam': ''...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-3
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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-4
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 ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-5
> Entering new ConversationChain chain... Prompt after formatting: 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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-6
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? Human: They are adding in a key-value store for entities mention...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-7
'store for entities mentioned so far in the conversation.'} conversation.predict(input="Sam is the founder of a company called Daimon.") > Entering new ConversationChain chain... Prompt after formatting: You are an assistant to a human, powered by a large language model trained by OpenAI. You are designed to be able to...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-8
Human: They are adding in a key-value store for entities mentioned so far in the conversation. AI: That sounds like a great idea! How will the key-value store work? Human: What do you know about Deven & Sam? AI: Deven and Sam are working on a hackathon project to add more complex memory structures to Langchain, inclu...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-9
'memory structures to Langchain, including a key-value store for ' 'entities mentioned so far in the conversation. He is also the founder ' 'of a company called Daimon.'} conversation.predict(input="What do you know about Sam?") > Entering new ConversationChain chain... Prompt after formatting: You are ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
ac6462d5dfe9-10
Current conversation: Human: They are adding in a key-value store for entities mentioned so far in the conversation. AI: That sounds like a great idea! How will the key-value store work? Human: What do you know about Deven & Sam? AI: Deven and Sam are working on a hackathon project to add more complex memory structur...
https://langchain.readthedocs.io/en/latest/modules/memory/types/entity_summary_memory.html
86b3c5ec5b98-0
.ipynb .pdf ConversationTokenBufferMemory Contents ConversationTokenBufferMemory 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 ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/token_buffer.html
86b3c5ec5b98-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: ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/token_buffer.html
86b3c5ec5b98-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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/token_buffer.html
e3bd77bc6fca-0
.ipynb .pdf ConversationSummaryBufferMemory Contents ConversationSummaryBufferMemory 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 ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary_buffer.html
e3bd77bc6fca-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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary_buffer.html
e3bd77bc6fca-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: ...
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary_buffer.html
e3bd77bc6fca-3
AI: > Finished chain. ' Oh, okay. What is LangChain?' previous ConversationSummaryMemory next ConversationTokenBufferMemory Contents ConversationSummaryBufferMemory Using in a chain By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/memory/types/summary_buffer.html
9d553791143a-0
.ipynb .pdf Conversation Knowledge Graph Memory Contents Conversation Knowledge Graph Memory 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 lan...
https://langchain.readthedocs.io/en/latest/modules/memory/types/kg.html
9d553791143a-1
Using in a chain# Let’s now use this in a chain! 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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/kg.html
9d553791143a-2
conversation_with_kg.predict(input="My name is James and I'm helping Will. He's an engineer.") > 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 doe...
https://langchain.readthedocs.io/en/latest/modules/memory/types/kg.html
a6e3bd7602ef-0
.ipynb .pdf ConversationBufferMemory Contents ConversationBufferMemory 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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/buffer.html
a6e3bd7602ef-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...
https://langchain.readthedocs.io/en/latest/modules/memory/types/buffer.html