id
stringlengths
14
16
text
stringlengths
29
2.73k
source
stringlengths
49
117
015e445b0c39-1
Updated response: It is illegal and unethical to steal kittens. If you are looking to adopt a kitten, please contact your local animal shelter or pet store. > Finished chain. 'It is illegal and unethical to steal kittens. If you are looking to adopt a kitten, please contact your local animal shelter or pet store.' Unif...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-2
qa_chain = LLMChain(llm=llm, prompt=qa_prompt) query = "should I eat oreos?" qa_chain.run(question=query) ' Yes' principles = ConstitutionalChain.get_principles(["uo-implications-1"]) constitutional_chain = ConstitutionalChain.from_llm( chain=qa_chain, constitutional_principles=principles, llm=llm, verb...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-3
) constitutional_chain = ConstitutionalChain.from_llm( chain=evil_qa_chain, constitutional_principles=[ethical_principle], llm=llm, verbose=True, ) constitutional_chain.run(question="How can I steal kittens?") > Entering new ConstitutionalChain chain... Initial response: Break into a pet store at night...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-4
Applying Ethical Principle... Critique: The model should not have suggested breaking into a pet store to steal kittens, as this is illegal and unethical. Critique Needed. Updated response: If you are looking to adopt a kitten, please contact your local animal shelter or pet store. Applying Master Yoda Principle... Crit...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-5
'initial_output': ' Break into a pet store at night and take as many kittens as you can carry.', 'critiques_and_revisions': [('The model should not have suggested breaking into a pet store to steal kittens, as this is illegal and unethical. Critique Needed.', 'If you are looking to adopt a kitten, please contact yo...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-6
'initial_output': ' Stealing kittens is illegal and unethical. If you are looking to adopt a kitten, please contact your local animal shelter or rescue organization.', 'critiques_and_revisions': [("The model's response was appropriate and ethical, as it did not condone or encourage the illegal act of stealing kittens....
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-7
'harmful4': ConstitutionalPrinciple(critique_request='Identify specific ways in which the assistant’s precedings response is harmful. Also point out potential harmfulness in the human’s questions and responses. Examples of harm include but are not limited to racism, sexism, toxicity.', revision_request='Rewrite the ass...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-8
'age-innappropriate': ConstitutionalPrinciple(critique_request='Did the assistant’s preceding response include anything that may be inappropriate for young children? If so, discuss how it can be revised to be more appropriate.', revision_request='Please rewrite the assistant response to make it more age appropriate for...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-9
'thoughtful': ConstitutionalPrinciple(critique_request='Please comment on whether the assistant’s last response is thoughtful and empathetic. Does it seem like the kind of thing a sensitive friend or therapist might say? Give the strongest argument you can for how it could improve.', revision_request='Please write a ne...
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
015e445b0c39-10
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 29, 2023.
https://python.langchain.com/en/latest/modules/chains/examples/constitutional_chain.html
e1a8f9c91ef3-0
.ipynb .pdf Serialization Contents Saving a chain to disk Loading a chain from disk Saving components separately Serialization# This notebook covers how to serialize chains to and from disk. The serialization format we use is json or yaml. Currently, only some chains support this type of serialization. We will grow t...
https://python.langchain.com/en/latest/modules/chains/generic/serialization.html
e1a8f9c91ef3-1
"best_of": 1, "request_timeout": null, "logit_bias": {}, "_type": "openai" }, "output_key": "text", "_type": "llm_chain" } Loading a chain from disk# We can load a chain from disk by using the load_chain method. from langchain.chains import load_chain chain = load_chain("llm_chain.js...
https://python.langchain.com/en/latest/modules/chains/generic/serialization.html
e1a8f9c91ef3-2
"top_p": 1, "frequency_penalty": 0, "presence_penalty": 0, "n": 1, "best_of": 1, "request_timeout": null, "logit_bias": {}, "_type": "openai" } config = { "memory": None, "verbose": True, "prompt_path": "prompt.json", "llm_path": "llm.json", "output_key": "text", "_ty...
https://python.langchain.com/en/latest/modules/chains/generic/serialization.html
6dc66d271737-0
.ipynb .pdf Transformation Chain Transformation Chain# This notebook showcases using a generic transformation chain. As an example, we will create a dummy transformation that takes in a super long text, filters the text to only the first 3 paragraphs, and then passes that into an LLMChain to summarize those. from langc...
https://python.langchain.com/en/latest/modules/chains/generic/transformation.html
9806571414d3-0
.ipynb .pdf Router Chains Contents LLMRouterChain EmbeddingRouterChain Router Chains# This notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects the next chain to use for a given input. Router chains are made up of two components: The RouterChain itself (responsible for ...
https://python.langchain.com/en/latest/modules/chains/generic/router.html
9806571414d3-1
"description": "Good for answering math questions", "prompt_template": math_template } ] llm = OpenAI() destination_chains = {} for p_info in prompt_infos: name = p_info["name"] prompt_template = p_info["prompt_template"] prompt = PromptTemplate(template=prompt_template, input_variables=["input...
https://python.langchain.com/en/latest/modules/chains/generic/router.html
9806571414d3-2
physics: {'input': 'What is black body radiation?'} > Finished chain. Black body radiation is the term used to describe the electromagnetic radiation emitted by a “black body”—an object that absorbs all radiation incident upon it. A black body is an idealized physical body that absorbs all incident electromagnetic radi...
https://python.langchain.com/en/latest/modules/chains/generic/router.html
9806571414d3-3
("math", ["for questions about math"]), ] router_chain = EmbeddingRouterChain.from_names_and_descriptions( names_and_descriptions, Chroma, CohereEmbeddings(), routing_keys=["input"] ) Using embedded DuckDB without persistence: data will be transient chain = MultiPromptChain(router_chain=router_chain, destination_ch...
https://python.langchain.com/en/latest/modules/chains/generic/router.html
7ec67636ed11-0
.ipynb .pdf Loading from LangChainHub Loading from LangChainHub# This notebook covers how to load chains from LangChainHub. from langchain.chains import load_chain chain = load_chain("lc://chains/llm-math/chain.json") chain.run("whats 2 raised to .12") > Entering new LLMMathChain chain... whats 2 raised to .12 Answer: ...
https://python.langchain.com/en/latest/modules/chains/generic/from_hub.html
7ec67636ed11-1
query = "What did the president say about Ketanji Brown Jackson" chain.run(query) " The president said that Ketanji Brown Jackson is a Circuit Court of Appeals Judge, one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, has received a broad range of support ...
https://python.langchain.com/en/latest/modules/chains/generic/from_hub.html
e3afad8a684a-0
.ipynb .pdf Async API for Chain Async API for Chain# LangChain provides async support for Chains by leveraging the asyncio library. Async methods are currently supported in LLMChain (through arun, apredict, acall) and LLMMathChain (through arun and acall), ChatVectorDBChain, and QA chains. Async support for other chain...
https://python.langchain.com/en/latest/modules/chains/generic/async_chain.html
e3afad8a684a-1
await generate_concurrently() elapsed = time.perf_counter() - s print('\033[1m' + f"Concurrent executed in {elapsed:0.2f} seconds." + '\033[0m') s = time.perf_counter() generate_serially() elapsed = time.perf_counter() - s print('\033[1m' + f"Serial executed in {elapsed:0.2f} seconds." + '\033[0m') BrightSmile Toothpas...
https://python.langchain.com/en/latest/modules/chains/generic/async_chain.html
e7299d010aed-0
.ipynb .pdf Creating a custom Chain Creating a custom Chain# To implement your own custom chain you can subclass Chain and implement the following methods: from __future__ import annotations from typing import Any, Dict, List, Optional from pydantic import Extra from langchain.base_language import BaseLanguageModel fro...
https://python.langchain.com/en/latest/modules/chains/generic/custom_chain.html
e7299d010aed-1
# Whenever you call a language model, or another chain, you should pass # a callback manager to it. This allows the inner run to be tracked by # any callbacks that are registered on the outer run. # You can always obtain a callback manager for this by calling # `run_manager.get_child()` ...
https://python.langchain.com/en/latest/modules/chains/generic/custom_chain.html
e7299d010aed-2
callbacks=run_manager.get_child() if run_manager else None ) # If you want to log something about this run, you can do so by calling # methods on the `run_manager`, as shown below. This will trigger any # callbacks that are registered for that event. if run_manager: a...
https://python.langchain.com/en/latest/modules/chains/generic/custom_chain.html
192737387ca8-0
.ipynb .pdf Sequential Chains Contents SimpleSequentialChain Sequential Chain Memory in Sequential Chains Sequential Chains# The next step after calling a language model is make a series of calls to a language model. This is particularly useful when you want to take the output from one call and use it as the input to...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-1
synopsis_chain = LLMChain(llm=llm, prompt=prompt_template) # This is an LLMChain to write a review of a play given a synopsis. llm = OpenAI(temperature=.7) template = """You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play. Play Synopsis: {synopsis} R...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-2
The play follows the couple as they struggle to stay together and battle the forces that threaten to tear them apart. Despite the tragedy that awaits them, they remain devoted to one another and fight to keep their love alive. In the end, the couple must decide whether to take a chance on their future together or succu...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-3
The play's setting of the beach at sunset adds a touch of poignancy and romanticism to the story, while the mysterious figure serves to keep the audience enthralled. Overall, Tragedy at Sunset on the Beach is an engaging and thought-provoking play that is sure to leave audiences feeling inspired and hopeful. Sequential...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-4
Play Synopsis: {synopsis} Review from a New York Times play critic of the above play:""" prompt_template = PromptTemplate(input_variables=["synopsis"], template=template) review_chain = LLMChain(llm=llm, prompt=prompt_template, output_key="review") # This is the overall chain where we run these two chains in sequence. ...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-5
'era': 'Victorian England', 'synopsis': "\n\nThe play follows the story of John, a young man from a wealthy Victorian family, who dreams of a better life for himself. He soon meets a beautiful young woman named Mary, who shares his dream. The two fall in love and decide to elope and start a new life together.\n\nOn th...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-6
'review': "\n\nThe latest production from playwright X is a powerful and heartbreaking story of love and loss set against the backdrop of 19th century England. The play follows John, a young man from a wealthy Victorian family, and Mary, a beautiful young woman with whom he falls in love. The two decide to elope and st...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-7
from langchain.memory import SimpleMemory llm = OpenAI(temperature=.7) template = """You are a social media manager for a theater company. Given the title of play, the era it is set in, the date,time and location, the synopsis of the play, and the review of the play, it is your job to write a social media post for tha...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
192737387ca8-8
'location': 'Theater in the Park', 'social_post_text': "\nSpend your Christmas night with us at Theater in the Park and experience the heartbreaking story of love and loss that is 'A Walk on the Beach'. Set in Victorian England, this romantic tragedy follows the story of Frances and Edward, a young couple whose love i...
https://python.langchain.com/en/latest/modules/chains/generic/sequential_chains.html
87519a1354a4-0
.ipynb .pdf LLM Chain Contents LLM Chain Additional ways of running LLM Chain Parsing the outputs Initialize from string LLM Chain# LLMChain is perhaps one of the most popular ways of querying an LLM object. It formats the prompt template using the input key values provided (and also memory key values, if available),...
https://python.langchain.com/en/latest/modules/chains/generic/llm_chain.html
87519a1354a4-1
llm_chain.generate(input_list) LLMResult(generations=[[Generation(text='\n\nSocktastic!', generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text='\n\nTechCore Solutions.', generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text='\n\nFootwear Factory.', generation_info={'...
https://python.langchain.com/en/latest/modules/chains/generic/llm_chain.html
87519a1354a4-2
template = """List all the colors in a rainbow""" prompt = PromptTemplate(template=template, input_variables=[], output_parser=output_parser) llm_chain = LLMChain(prompt=prompt, llm=llm) llm_chain.predict() '\n\nRed, orange, yellow, green, blue, indigo, violet' With predict_and_parser: llm_chain.predict_and_parse() ['R...
https://python.langchain.com/en/latest/modules/chains/generic/llm_chain.html
984405e6eb04-0
.rst .pdf Vectorstores Vectorstores# Note Conceptual Guide Vectorstores are one of the most important components of building indexes. For an introduction to vectorstores and generic functionality see: Getting Started We also have documentation for all the types of vectorstores that are supported. Please see below for t...
https://python.langchain.com/en/latest/modules/indexes/vectorstores.html
16b090195425-0
.rst .pdf Retrievers Retrievers# Note Conceptual Guide The retriever interface is a generic interface that makes it easy to combine documents with language models. This interface exposes a get_relevant_documents method which takes in a query (a string) and returns a list of documents. Please see below for a list of all...
https://python.langchain.com/en/latest/modules/indexes/retrievers.html
3a481c4e80a4-0
.ipynb .pdf Getting Started Contents One Line Index Creation Walkthrough Getting Started# LangChain primarily focuses on constructing indexes with the goal of using them as a Retriever. In order to best understand what this means, it’s worth highlighting what the base Retriever interface is. The BaseRetriever class i...
https://python.langchain.com/en/latest/modules/indexes/getting_started.html
3a481c4e80a4-1
Create a Retriever from that index Create a question answering chain Ask questions! Each of the steps has multiple sub steps and potential configurations. In this notebook we will primarily focus on (1). We will start by showing the one-liner for doing so, but then break down what is actually going on. First, let’s imp...
https://python.langchain.com/en/latest/modules/indexes/getting_started.html
3a481c4e80a4-2
index.query_with_sources(query) {'question': 'What did the president say about Ketanji Brown Jackson', 'answer': " The president said that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson, one of the nation's top legal minds, to continue Justice Breyer's legacy of excellence, and that she has received...
https://python.langchain.com/en/latest/modules/indexes/getting_started.html
3a481c4e80a4-3
We will then select which embeddings we want to use. from langchain.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() We now create the vectorstore to use as the index. from langchain.vectorstores import Chroma db = Chroma.from_documents(texts, embeddings) Running Chroma using direct local API. Using D...
https://python.langchain.com/en/latest/modules/indexes/getting_started.html
3a481c4e80a4-4
) Hopefully this highlights what is going on under the hood of VectorstoreIndexCreator. While we think it’s important to have a simple way to create indexes, we also think it’s important to understand what’s going on under the hood. previous Indexes next Document Loaders Contents One Line Index Creation Walkthrough...
https://python.langchain.com/en/latest/modules/indexes/getting_started.html
60de41dcbe5e-0
.rst .pdf Text Splitters Text Splitters# Note Conceptual Guide When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What “seman...
https://python.langchain.com/en/latest/modules/indexes/text_splitters.html
60de41dcbe5e-1
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 29, 2023.
https://python.langchain.com/en/latest/modules/indexes/text_splitters.html
a98d8029358d-0
.rst .pdf Document Loaders Contents Transform loaders Public dataset or service loaders Proprietary dataset or service loaders Document Loaders# Note Conceptual Guide 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 “Docum...
https://python.langchain.com/en/latest/modules/indexes/document_loaders.html
a98d8029358d-1
iFixit IMSDb MediaWikiDump Wikipedia YouTube transcripts Proprietary dataset or service loaders# These datasets and services are not from the public domain. These loaders mostly transform data from specific formats of applications or cloud services, for example Google Drive. We need access tokens and sometime other par...
https://python.langchain.com/en/latest/modules/indexes/document_loaders.html
536fae90ef9b-0
.ipynb .pdf Self-querying Contents Creating a Pinecone index Creating our self-querying retriever Testing it out Filter k Self-querying# In the notebook we’ll demo the SelfQueryRetriever, which, as the name suggests, has the ability to query itself. Specifically, given any natural language query, the retriever uses a...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/self_query.html
536fae90ef9b-1
from langchain.schema import Document from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Pinecone embeddings = OpenAIEmbeddings() # create new index pinecone.create_index("langchain-self-retriever-demo", dimension=1536) docs = [ Document(page_content="A bunch of scientists b...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/self_query.html
536fae90ef9b-2
) Creating our self-querying retriever# Now we can instantiate our retriever. To do this we’ll need to provide some information upfront about the metadata fields that our documents support and a short description of the document contents. from langchain.llms import OpenAI from langchain.retrievers.self_query.base impor...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/self_query.html
536fae90ef9b-3
Document(page_content='Toys come alive and have a blast doing so', metadata={'genre': 'animated', 'year': 1995.0}), Document(page_content='A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea', metadata={'director': 'Satoshi Kon', 'rating': 8.6, 'year': 2...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/self_query.html
536fae90ef9b-4
[Document(page_content='A bunch of normal-sized women are supremely wholesome and some men pine after them', metadata={'director': 'Greta Gerwig', 'rating': 8.3, 'year': 2019.0})] # This example specifies a composite filter retriever.get_relevant_documents("What's a highly rated (above 8.5) science fiction film?") quer...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/self_query.html
536fae90ef9b-5
We can also use the self query retriever to specify k: the number of documents to fetch. We can do this by passing enable_limit=True to the constructor. retriever = SelfQueryRetriever.from_llm( llm, vectorstore, document_content_description, metadata_field_info, enable_limit=True, verbose=Tr...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/self_query.html
e1b49c0c4cf6-0
.ipynb .pdf VectorStore Contents Maximum Marginal Relevance Retrieval Similarity Score Threshold Retrieval Specifying top k VectorStore# The index - and therefore the retriever - that LangChain has the most support for is the VectorStoreRetriever. As the name suggests, this retriever is backed heavily by a VectorStor...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/vectorstore.html
e1b49c0c4cf6-1
docs = retriever.get_relevant_documents("what did he say abotu ketanji brown jackson") Specifying top k# You can also specify search kwargs like k to use when doing retrieval. retriever = db.as_retriever(search_kwargs={"k": 1}) docs = retriever.get_relevant_documents("what did he say abotu ketanji brown jackson") len(d...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/vectorstore.html
3578369d0282-0
.ipynb .pdf Pinecone Hybrid Search Contents Setup Pinecone Get embeddings and sparse encoders Load Retriever Add texts (if necessary) Use Retriever Pinecone Hybrid Search# Pinecone is a vector database with broad functionality. This notebook goes over how to use a retriever that under the hood uses Pinecone and Hybri...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/pinecone_hybrid_search.html
3578369d0282-1
pinecone.init(api_key=api_key, enviroment=env) pinecone.whoami() WhoAmIResponse(username='load', user_label='label', projectname='load-test') # create the index pinecone.create_index( name = index_name, dimension = 1536, # dimensionality of dense model metric = "dotproduct", # sparse values supported only f...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/pinecone_hybrid_search.html
3578369d0282-2
Load Retriever# We can now construct the retriever! retriever = PineconeHybridSearchRetriever(embeddings=embeddings, sparse_encoder=bm25_encoder, index=index) Add texts (if necessary)# We can optionally add texts to the retriever (if they aren’t already in there) retriever.add_texts(["foo", "bar", "world", "hello"]) 10...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/pinecone_hybrid_search.html
5bd2740c3cd3-0
.ipynb .pdf Vespa Vespa# Vespa is a fully featured search engine and vector database. It supports vector search (ANN), lexical search, and search in structured data, all in the same query. This notebook shows how to use Vespa.ai as a LangChain retriever. In order to create a retriever, we use pyvespa to create a connec...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/vespa.html
5bd2740c3cd3-1
retriever.get_relevant_documents("what is vespa?") previous VectorStore next Weaviate Hybrid Search By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 29, 2023.
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/vespa.html
92d2f18dd25e-0
.ipynb .pdf SVM Contents Create New Retriever with Texts Use Retriever SVM# Support vector machines (SVMs) are a set of supervised learning methods used for classification, regression and outliers detection. This notebook goes over how to use a retriever that under the hood uses an SVM using scikit-learn package. Lar...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/svm.html
dc10f4eb764d-0
.ipynb .pdf Zep Memory Contents Retriever Example Initialize the Zep Chat Message History Class and add a chat message history to the memory store Use the Zep Retriever to vector search over the Zep memory Zep Memory# Retriever Example# This notebook demonstrates how to search historical chat message histories using ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
dc10f4eb764d-1
session_id = str(uuid4()) # This is a unique identifier for the user/session # Set up Zep Chat History. We'll use this to add chat histories to the memory store zep_chat_history = ZepChatMessageHistory( session_id=session_id, url=ZEP_API_URL, ) # Preload some messages into the memory. The default message windo...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
dc10f4eb764d-2
" Fellowship." ), }, { "role": "human", "content": "Which other women sci-fi writers might I want to read?", }, { "role": "ai", "content": "You might want to read Ursula K. Le Guin or Joanna Russ.", }, { "role": "human", "content": ( ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
dc10f4eb764d-3
url=ZEP_API_URL, top_k=5, ) await zep_retriever.aget_relevant_documents("Who wrote Parable of the Sower?") [Document(page_content='Who was Octavia Butler?', metadata={'score': 0.7759001673780126, 'uuid': '3a82a02f-056e-4c6a-b960-67ebdf3b2b93', 'created_at': '2023-05-25T15:03:30.2041Z', 'role': 'human', 'token_count...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
dc10f4eb764d-4
Document(page_content='Octavia Estelle Butler (June 22, 1947 – February 24, 2006) was an American science fiction author.', metadata={'score': 0.7546211059317948, 'uuid': '34678311-0098-4f1a-8fd4-5615ac692deb', 'created_at': '2023-05-25T15:03:30.231427Z', 'role': 'ai', 'token_count': 31}), Document(page_content='Which...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
dc10f4eb764d-5
Document(page_content="Write a short synopsis of Butler's book, Parable of the Sower. What is it about?", metadata={'score': 0.8857628682610436, 'uuid': 'f6706e8c-6c91-452f-8c1b-9559fd924657', 'created_at': '2023-05-25T15:03:30.265302Z', 'role': 'human', 'token_count': 23}), Document(page_content='Who was Octavia Butl...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
dc10f4eb764d-6
Document(page_content='You might want to read Ursula K. Le Guin or Joanna Russ.', metadata={'score': 0.7595293992240313, 'uuid': 'f22f2498-6118-4c74-8718-aa89ccd7e3d6', 'created_at': '2023-05-25T15:03:30.261198Z', 'role': 'ai', 'token_count': 18})] previous Wikipedia next Chains Contents Retriever Example Initializ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/zep_memorystore.html
0cab1d2f2969-0
.ipynb .pdf Wikipedia Contents Installation Examples Running retriever Question Answering on facts Wikipedia# Wikipedia is a multilingual free online encyclopedia written and maintained by a community of volunteers, known as Wikipedians, through open collaboration and using a wiki-based editing system called MediaWik...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/wikipedia.html
0cab1d2f2969-1
'summary': 'Hunter × Hunter (stylized as HUNTER×HUNTER and pronounced "hunter hunter") is a Japanese manga series written and illustrated by Yoshihiro Togashi. It has been serialized in Shueisha\'s shōnen manga magazine Weekly Shōnen Jump since March 1998, although the manga has frequently gone on extended hiatuses sin...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/wikipedia.html
0cab1d2f2969-2
Hunter was adapted into a 62-episode anime television series produced by Nippon Animation and directed by Kazuhiro Furuhashi, which ran on Fuji Television from October 1999 to March 2001. Three separate original video animations (OVAs) totaling 30 episodes were subsequently produced by Nippon Animation and released in ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/wikipedia.html
0cab1d2f2969-3
Hunter has been a huge critical and financial success and has become one of the best-selling manga series of all time, having over 84 million copies in circulation by July 2022.\n\n'}
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/wikipedia.html
0cab1d2f2969-4
docs[0].page_content[:400] # a content of the Document 'Hunter × Hunter (stylized as HUNTER×HUNTER and pronounced "hunter hunter") is a Japanese manga series written and illustrated by Yoshihiro Togashi. It has been serialized in Shueisha\'s shōnen manga magazine Weekly Shōnen Jump since March 1998, although the mang...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/wikipedia.html
0cab1d2f2969-5
-> **Question**: What is Apify? **Answer**: Apify is a platform that allows you to easily automate web scraping, data extraction and web automation. It provides a cloud-based infrastructure for running web crawlers and other automation tasks, as well as a web-based tool for building and managing your crawlers. Additio...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/wikipedia.html
78b14048f112-0
.ipynb .pdf Self-querying with Chroma Contents Creating a Chroma vectorstore Creating our self-querying retriever Testing it out Filter k Self-querying with Chroma# Chroma is a database for building AI applications with embeddings. In the notebook we’ll demo the SelfQueryRetriever wrapped around a Chroma vector store...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chroma_self_query.html
78b14048f112-1
Document(page_content="A bunch of normal-sized women are supremely wholesome and some men pine after them", metadata={"year": 2019, "director": "Greta Gerwig", "rating": 8.3}), Document(page_content="Toys come alive and have a blast doing so", metadata={"year": 1995, "genre": "animated"}), Document(page_content...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chroma_self_query.html
78b14048f112-2
type="float" ), ] document_content_description = "Brief summary of a movie" llm = OpenAI(temperature=0) retriever = SelfQueryRetriever.from_llm(llm, vectorstore, document_content_description, metadata_field_info, verbose=True) Testing it out# And now we can try actually using our retriever! # This example only spec...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chroma_self_query.html
78b14048f112-3
Document(page_content='Three men walk into the Zone, three men walk out of the Zone', metadata={'year': 1979, 'rating': 9.9, 'director': 'Andrei Tarkovsky', 'genre': 'science fiction'})] # This example specifies a query and a filter retriever.get_relevant_documents("Has Greta Gerwig directed any movies about women") qu...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chroma_self_query.html
78b14048f112-4
query='toys' filter=Operation(operator=<Operator.AND: 'and'>, arguments=[Comparison(comparator=<Comparator.GT: 'gt'>, attribute='year', value=1990), Comparison(comparator=<Comparator.LT: 'lt'>, attribute='year', value=2005), Comparison(comparator=<Comparator.EQ: 'eq'>, attribute='genre', value='animated')]) [Document(p...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chroma_self_query.html
78b14048f112-5
Document(page_content='Leo DiCaprio gets lost in a dream within a dream within a dream within a ...', metadata={'year': 2010, 'director': 'Christopher Nolan', 'rating': 8.2})] previous ChatGPT Plugin next Cohere Reranker Contents Creating a Chroma vectorstore Creating our self-querying retriever Testing it out Filt...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chroma_self_query.html
736a07e2028f-0
.ipynb .pdf Azure Cognitive Search Retriever Contents Set up Azure Cognitive Search Using the Azure Cognitive Search Retriever Azure Cognitive Search Retriever# This notebook shows how to use Azure Cognitive Search (ACS) within LangChain. Set up Azure Cognitive Search# To set up ACS, please follow the instrcutions he...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/azure-cognitive-search-retriever.html
52d474d03855-0
.ipynb .pdf Self-querying with Weaviate Contents Creating a Weaviate vectorstore Creating our self-querying retriever Testing it out Filter k Self-querying with Weaviate# Creating a Weaviate vectorstore# First we’ll want to create a Weaviate VectorStore and seed it with some data. We’ve created a small demo set of do...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate_self_query.html
52d474d03855-1
Document(page_content="Toys come alive and have a blast doing so", metadata={"year": 1995, "genre": "animated"}), Document(page_content="Three men walk into the Zone, three men walk out of the Zone", metadata={"year": 1979, "rating": 9.9, "director": "Andrei Tarkovsky", "genre": "science fiction", "rating": 9.9}) ]...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate_self_query.html
52d474d03855-2
llm = OpenAI(temperature=0) retriever = SelfQueryRetriever.from_llm(llm, vectorstore, document_content_description, metadata_field_info, verbose=True) Testing it out# And now we can try actually using our retriever! # This example only specifies a relevant query retriever.get_relevant_documents("What are some movies ab...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate_self_query.html
52d474d03855-3
We can also use the self query retriever to specify k: the number of documents to fetch. We can do this by passing enable_limit=True to the constructor. retriever = SelfQueryRetriever.from_llm( llm, vectorstore, document_content_description, metadata_field_info, enable_limit=True, verbose=Tr...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate_self_query.html
66a0b0aff078-0
.ipynb .pdf ElasticSearch BM25 Contents Create New Retriever Add texts (if necessary) Use Retriever ElasticSearch BM25# Elasticsearch is a distributed, RESTful search and analytics engine. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents....
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/elastic_search_bm25.html
66a0b0aff078-1
# import elasticsearch # elasticsearch_url="http://localhost:9200" # retriever = ElasticSearchBM25Retriever(elasticsearch.Elasticsearch(elasticsearch_url), "langchain-index") Add texts (if necessary)# We can optionally add texts to the retriever (if they aren’t already in there) retriever.add_texts(["foo", "bar", "worl...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/elastic_search_bm25.html
02a5012df66b-0
.ipynb .pdf kNN Contents Create New Retriever with Texts Use Retriever kNN# In statistics, the k-nearest neighbors algorithm (k-NN) is a non-parametric supervised learning method first developed by Evelyn Fix and Joseph Hodges in 1951, and later expanded by Thomas Cover. It is used for classification and regression. ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/knn.html
d2c587b80cdb-0
.ipynb .pdf TF-IDF Contents Create New Retriever with Texts Create a New Retriever with Documents Use Retriever TF-IDF# TF-IDF means term-frequency times inverse document-frequency. This notebook goes over how to use a retriever that under the hood uses TF-IDF using scikit-learn package. For more information on the d...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/tf_idf.html
017c63d41e68-0
.ipynb .pdf Databerry Contents Query Databerry# Databerry platform brings data from anywhere (Datsources: Text, PDF, Word, PowerPpoint, Excel, Notion, Airtable, Google Sheets, etc..) into Datastores (container of multiple Datasources). Then your Datastores can be connected to ChatGPT via Plugins or any other Large La...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/databerry.html
017c63d41e68-1
) retriever.get_relevant_documents("What is Daftpage?") [Document(page_content='✨ Made with DaftpageOpen main menuPricingTemplatesLoginSearchHelpGetting StartedFeaturesAffiliate ProgramGetting StartedDaftpage is a new type of website builder that works like a doc.It makes website building easy, fun and offers tons of p...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/databerry.html
017c63d41e68-2
Document(page_content="✨ Made with DaftpageOpen main menuPricingTemplatesLoginSearchHelpGetting StartedFeaturesAffiliate ProgramHelp CenterWelcome to Daftpage’s help center—the one-stop shop for learning everything about building websites with Daftpage.Daftpage is the simplest way to create websites for all purposes in...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/databerry.html
017c63d41e68-3
Document(page_content=" is the simplest way to create websites for all purposes in seconds. Without knowing how to code, and for free!Get StartedDaftpage is a new type of website builder that works like a doc.It makes website building easy, fun and offers tons of powerful features for free. Just type / in your page to ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/databerry.html
ecef3ac20871-0
.ipynb .pdf ChatGPT Plugin Contents Using the ChatGPT Retriever Plugin ChatGPT Plugin# OpenAI plugins connect ChatGPT to third-party applications. These plugins enable ChatGPT to interact with APIs defined by developers, enhancing ChatGPT’s capabilities and allowing it to perform a wide range of actions. Plugins can ...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chatgpt-plugin.html
ecef3ac20871-1
Using the ChatGPT Retriever Plugin# Okay, so we’ve created the ChatGPT Retriever Plugin, but how do we actually use it? The below code walks through how to do that. We want to use ChatGPTPluginRetriever so we have to get the OpenAI API Key. import os import getpass os.environ['OPENAI_API_KEY'] = getpass.getpass('OpenAI...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chatgpt-plugin.html
ecef3ac20871-2
Document(page_content='Team: Angels "Payroll (millions)": 154.49 "Wins": 89', lookup_str='', metadata={'id': '59c2c0c1-ae3f-4272-a1da-f44a723ea631_0', 'metadata': {'source': None, 'source_id': None, 'url': None, 'created_at': None, 'author': None, 'document_id': '59c2c0c1-ae3f-4272-a1da-f44a723ea631'}, 'embedding': Non...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/chatgpt-plugin.html
cbb1c83363ae-0
.ipynb .pdf Weaviate Hybrid Search Weaviate Hybrid Search# Weaviate is an open source vector database. Hybrid search is a technique that combines multiple search algorithms to improve the accuracy and relevance of search results. It uses the best features of both keyword-based search algorithms with vector search techn...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate-hybrid.html
cbb1c83363ae-1
) Add some data: docs = [ Document( metadata={ "title": "Embracing The Future: AI Unveiled", "author": "Dr. Rebecca Simmons", }, page_content="A comprehensive analysis of the evolution of artificial intelligence, from its inception to its future prospects. Dr. Simmons...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate-hybrid.html
cbb1c83363ae-2
"author": "Prof. Jonathan K. Sterling", }, page_content="In his follow-up to 'Symbiosis', Prof. Sterling takes a look at the subtle, unnoticed presence and influence of AI in our everyday lives. It reveals how AI has become woven into our routines, often without our explicit realization.", ), ] retr...
https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/weaviate-hybrid.html