id stringlengths 14 16 | text stringlengths 36 2.73k | source stringlengths 49 117 |
|---|---|---|
41208ea6f041-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 |
41208ea6f041-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 |
41208ea6f041-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 |
41208ea6f041-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 |
41208ea6f041-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 |
991b94529578-0 | .ipynb
.pdf
Time Weighted VectorStore
Contents
Low Decay Rate
High Decay Rate
Virtual Time
Time Weighted VectorStore#
This retriever uses a combination of semantic similarity and a time decay.
The algorithm for scoring them is:
semantic_similarity + (1.0 - decay_rate) ** hours_passed
Notably, hours_passed refers to t... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/time_weighted_vectorstore.html |
991b94529578-1 | retriever.add_documents([Document(page_content="hello foo")])
['d7f85756-2371-4bdf-9140-052780a0f9b3']
# "Hello World" is returned first because it is most salient, and the decay rate is close to 0., meaning it's still recent enough
retriever.get_relevant_documents("hello world")
[Document(page_content='hello world', m... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/time_weighted_vectorstore.html |
991b94529578-2 | # "Hello Foo" is returned first because "hello world" is mostly forgotten
retriever.get_relevant_documents("hello world")
[Document(page_content='hello foo', metadata={'last_accessed_at': datetime.datetime(2023, 4, 16, 22, 9, 2, 494798), 'created_at': datetime.datetime(2023, 4, 16, 22, 9, 2, 178722), 'buffer_idx': 1})]... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/time_weighted_vectorstore.html |
35e50852258d-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 |
35e50852258d-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 |
35e50852258d-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 |
35e50852258d-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 |
35e50852258d-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 |
35e50852258d-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 |
9eb2812a02d8-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 |
9eb2812a02d8-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 |
9eb2812a02d8-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 |
9eb2812a02d8-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 |
a572de124994-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 |
a572de124994-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 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/vespa.html |
216cbd63ff3f-0 | .ipynb
.pdf
Contextual Compression
Contents
Contextual Compression
Using a vanilla vector store retriever
Adding contextual compression with an LLMChainExtractor
More built-in compressors: filters
LLMChainFilter
EmbeddingsFilter
Stringing compressors and document transformers together
Contextual Compression#
This not... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-1 | texts = text_splitter.split_documents(documents)
retriever = FAISS.from_documents(texts, OpenAIEmbeddings()).as_retriever()
docs = retriever.get_relevant_documents("What did the president say about Ketanji Brown Jackson")
pretty_print_docs(docs)
Document 1:
Tonight. I call on the Senate to: Pass the Freedom to Vote Act... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-2 | We’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.
----------------------------------------------------------------------------------------------------
Document 3:
And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-3 | Let’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.
Adding contextual compression with an LLMChainExtractor#
Now let’s wrap our base retriever with a ContextualCompressionRetriever. We’l... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-4 | More built-in compressors: filters#
LLMChainFilter#
The LLMChainFilter is slightly simpler but more robust compressor that uses an LLM chain to decide which of the initially retrieved documents to filter out and which ones to return, without manipulating the document contents.
from langchain.retrievers.document_compres... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-5 | from langchain.retrievers.document_compressors import EmbeddingsFilter
embeddings = OpenAIEmbeddings()
embeddings_filter = EmbeddingsFilter(embeddings=embeddings, similarity_threshold=0.76)
compression_retriever = ContextualCompressionRetriever(base_compressor=embeddings_filter, base_retriever=retriever)
compressed_doc... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-6 | We can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling.
We’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers.
We’re putting in place dedicated immigration judges so families fleeing persecution and violence can have th... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-7 | Below we create a compressor pipeline by first splitting our docs into smaller chunks, then removing redundant documents, and then filtering based on relevance to the query.
from langchain.document_transformers import EmbeddingsRedundantFilter
from langchain.retrievers.document_compressors import DocumentCompressorPipe... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
216cbd63ff3f-8 | previous
Cohere Reranker
next
Databerry
Contents
Contextual Compression
Using a vanilla vector store retriever
Adding contextual compression with an LLMChainExtractor
More built-in compressors: filters
LLMChainFilter
EmbeddingsFilter
Stringing compressors and document transformers together
By Harrison Chase
... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/contextual-compression.html |
2ebef52cee85-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 |
2ebef52cee85-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 |
2ebef52cee85-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 |
2ebef52cee85-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 |
2ebef52cee85-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 |
2ebef52cee85-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 |
9cb451a8408b-0 | .ipynb
.pdf
Arxiv
Contents
Installation
Examples
Running retriever
Question Answering on facts
Arxiv#
arXiv is an open-access archive for 2 million scholarly articles in the fields of physics, mathematics, computer science, quantitative biology, quantitative finance, statistics, electrical engineering and systems sci... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/arxiv.html |
9cb451a8408b-1 | 'Authors': 'Caprice Stanley, Tobias Windisch',
'Summary': 'Graphs on lattice points are studied whose edges come from a finite set of\nallowed moves of arbitrary length. We show that the diameter of these graphs on\nfibers of a fixed integer matrix can be bounded from above by a constant. We\nthen study the mixing beh... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/arxiv.html |
9cb451a8408b-2 | questions = [
"What are Heat-bath random walks with Markov base?",
"What is the ImageBind model?",
"How does Compositional Reasoning with Large Language Models works?",
]
chat_history = []
for question in questions:
result = qa({"question": question, "chat_history": chat_history})
chat_history... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/arxiv.html |
9cb451a8408b-3 | -> **Question**: How does Compositional Reasoning with Large Language Models works?
**Answer**: Compositional reasoning with large language models refers to the ability of these models to correctly identify and represent complex concepts by breaking them down into smaller, more basic parts and combining them in a stru... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/arxiv.html |
9cb451a8408b-4 | **Answer**: Heat-bath random walks with Markov base (HB-MB) is a class of stochastic processes that have been studied in the field of statistical mechanics and condensed matter physics. In these processes, a particle moves in a lattice by making a transition to a neighboring site, which is chosen according to a probabi... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/arxiv.html |
8291307a963d-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 |
e57d3928073d-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 |
e57d3928073d-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 |
e57d3928073d-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 |
e57d3928073d-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 |
113f3f787744-0 | .ipynb
.pdf
Cohere Reranker
Contents
Set up the base vector store retriever
Doing reranking with CohereRerank
Cohere Reranker#
Cohere is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.
This notebook shows how to use Cohere’s rerank endpoint i... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-1 | texts = text_splitter.split_documents(documents)
retriever = FAISS.from_documents(texts, OpenAIEmbeddings()).as_retriever(search_kwargs={"k": 20})
query = "What did the president say about Ketanji Brown Jackson"
docs = retriever.get_relevant_documents(query)
pretty_print_docs(docs)
Document 1:
One of the most serious c... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-2 | Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland.
In this struggle as President Zelenskyy said in his speech to the European Parliament “Light will win over darkness.” The Ukrainian Ambassador to the United States is here tonight.... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-3 | It’s exploitation—and it drives up prices.
----------------------------------------------------------------------------------------------------
Document 8:
For the past 40 years we were told that if we gave tax breaks to those at the very top, the benefits would trickle down to everyone else.
But that trickle-down the... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-4 | The pandemic has been punishing.
And so many families are living paycheck to paycheck, struggling to keep up with the rising cost of food, gas, housing, and so much more.
I understand.
----------------------------------------------------------------------------------------------------
Document 12:
Madam Speaker, Mada... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-5 | Third, support our veterans.
Veterans are the best of us.
I’ve always believed that we have a sacred obligation to equip all those we send to war and care for them and their families when they come home.
My administration is providing assistance with job training and housing, and now helping lower-income veterans ge... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-6 | ----------------------------------------------------------------------------------------------------
Document 19:
I understand.
I remember when my Dad had to leave our home in Scranton, Pennsylvania to find work. I grew up in a family where if the price of food went up, you felt it.
That’s why one of the first things... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-7 | And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
----------------------------------------------------------------------------------------------------
Document 2:
I spoke with th... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
113f3f787744-8 | previous
Self-querying with Chroma
next
Contextual Compression
Contents
Set up the base vector store retriever
Doing reranking with CohereRerank
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/cohere-reranker.html |
a61873a608d2-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 |
a61873a608d2-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 |
a61873a608d2-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 |
4b635c2ddc1d-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 |
7b2fbabf0811-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 |
7b2fbabf0811-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 |
7b2fbabf0811-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 |
7b2fbabf0811-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 |
7b2fbabf0811-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 |
7b2fbabf0811-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 |
5c1d7c5e58b5-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 |
e9e1cfbabcae-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 |
e9e1cfbabcae-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 |
e9e1cfbabcae-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 |
355dd3fa5db7-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 |
c10307b3f122-0 | .ipynb
.pdf
Metal
Contents
Ingest Documents
Query
Metal#
Metal is a managed service for ML Embeddings.
This notebook shows how to use Metal’s retriever.
First, you will need to sign up for Metal and get an API key. You can do so here
# !pip install metal_sdk
from metal_sdk.metal import Metal
API_KEY = ""
CLIENT_ID = ... | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/metal.html |
c10307b3f122-1 | previous
kNN
next
Pinecone Hybrid Search
Contents
Ingest Documents
Query
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/retrievers/examples/metal.html |
7917fac10fa8-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 |
7917fac10fa8-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 |
9b1522f50f8e-0 | .ipynb
.pdf
Getting Started
Getting Started#
The default recommended text splitter is the RecursiveCharacterTextSplitter. This text splitter takes a list of characters. It tries to create chunks based on splitting on the first character, but if any chunks are too large it then moves onto the next character, and so fort... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/getting_started.html |
9b1522f50f8e-1 | previous
Text Splitters
next
Character
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/text_splitters/getting_started.html |
57fe010309ed-0 | .ipynb
.pdf
spaCy
spaCy#
spaCy is an open-source software library for advanced natural language processing, written in the programming languages Python and Cython.
Another alternative to NLTK is to use Spacy tokenizer.
How the text is split: by spaCy tokenizer
How the chunk size is measured: by number of characters
#!p... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/spacy.html |
57fe010309ed-1 | previous
Recursive Character
next
Tiktoken
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/spacy.html |
c67ee34b305e-0 | .ipynb
.pdf
Hugging Face tokenizer
Hugging Face tokenizer#
Hugging Face has many tokenizers.
We use Hugging Face tokenizer, the GPT2TokenizerFast to count the text length in tokens.
How the text is split: by character passed in
How the chunk size is measured: by number of tokens calculated by the Hugging Face tokenizer... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/huggingface_length_function.html |
52a603d1f714-0 | .ipynb
.pdf
NLTK
NLTK#
The Natural Language Toolkit, or more commonly NLTK, is a suite of libraries and programs for symbolic and statistical natural language processing (NLP) for English written in the Python programming language.
Rather than just splitting on “\n\n”, we can use NLTK to split based on NLTK tokenizers.... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/nltk.html |
52a603d1f714-1 | Groups of citizens blocking tanks with their bodies.
previous
Markdown
next
Python Code
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/nltk.html |
c55e76773487-0 | .ipynb
.pdf
Character
Character#
This is the simplest method. This splits based on characters (by default “\n\n”) and measure chunk length by number of characters.
How the text is split: by single character
How the chunk size is measured: by number of characters
# This is a long document we can split up.
with open('../... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/character_text_splitter.html |
c55e76773487-1 | texts = text_splitter.create_documents([state_of_the_union])
print(texts[0])
page_content='Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n\nLast year COVID-19 kept us apart. This year we are finally to... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/character_text_splitter.html |
c55e76773487-2 | print(documents[0])
page_content='Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n\nLast year COVID-19 kept us apart. This year we are finally together again. \n\nTonight, we meet as Democrats Republica... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/character_text_splitter.html |
c55e76773487-3 | text_splitter.split_text(state_of_the_union)[0]
'Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n\nLast year COVID-19 kept us apart. This year we are finally together again. \n\nTonight, we meet as Demo... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/character_text_splitter.html |
486c2cfa24d4-0 | .ipynb
.pdf
Recursive Character
Recursive Character#
This text splitter is the recommended one for generic text. It is parameterized by a list of characters. It tries to split on them in order until the chunks are small enough. The default list is ["\n\n", "\n", " ", ""]. This has the effect of trying to keep all parag... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/recursive_text_splitter.html |
486c2cfa24d4-1 | previous
Python Code
next
spaCy
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/recursive_text_splitter.html |
c97a05d81d4a-0 | .ipynb
.pdf
Python Code
Python Code#
PythonCodeTextSplitter splits text along python class and method definitions. It’s implemented as a simple subclass of RecursiveCharacterSplitter with Python-specific separators. See the source code to see the Python syntax expected by default.
How the text is split: by list of pyth... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/python.html |
adebfb44a4ce-0 | .ipynb
.pdf
Tiktoken
Tiktoken#
tiktoken is a fast BPE tokeniser created by OpenAI.
How the text is split: by tiktoken tokens
How the chunk size is measured: by tiktoken tokens
#!pip install tiktoken
# This is a long document we can split up.
with open('../../../state_of_the_union.txt') as f:
state_of_the_union = f.... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/tiktoken_splitter.html |
34d4bcdb3106-0 | .ipynb
.pdf
Markdown
Markdown#
Markdown is a lightweight markup language for creating formatted text using a plain-text editor.
MarkdownTextSplitter splits text along Markdown headings, code blocks, or horizontal rules. It’s implemented as a simple subclass of RecursiveCharacterSplitter with Markdown-specific separator... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/markdown.html |
34d4bcdb3106-1 | previous
LaTeX
next
NLTK
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on May 28, 2023. | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/markdown.html |
c3b1090d6ede-0 | .ipynb
.pdf
LaTeX
LaTeX#
LaTeX is widely used in academia for the communication and publication of scientific documents in many fields, including mathematics, computer science, engineering, physics, chemistry, economics, linguistics, quantitative psychology, philosophy, and political science.
LatexTextSplitter splits t... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/latex.html |
c3b1090d6ede-1 | latex_splitter = LatexTextSplitter(chunk_size=400, chunk_overlap=0)
docs = latex_splitter.create_documents([latex_text])
docs
[Document(page_content='\\documentclass{article}\n\n\x08egin{document}\n\n\\maketitle', lookup_str='', metadata={}, lookup_index=0),
Document(page_content='Introduction}\nLarge language models ... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/latex.html |
c3b1090d6ede-2 | 'Introduction}\nLarge language models (LLMs) are a type of machine learning model that can be trained on vast amounts of text data to generate human-like language. In recent years, LLMs have made significant advances in a variety of natural language processing tasks, including language translation, text generation, and... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/latex.html |
c081459f732a-0 | .ipynb
.pdf
tiktoken (OpenAI) tokenizer
tiktoken (OpenAI) tokenizer#
tiktoken is a fast BPE tokenizer created by OpenAI.
We can use it to estimate tokens used. It will probably be more accurate for the OpenAI models.
How the text is split: by character passed in
How the chunk size is measured: by tiktoken tokenizer
#!p... | https://python.langchain.com/en/latest/modules/indexes/text_splitters/examples/tiktoken.html |
9070a6f2448d-0 | .ipynb
.pdf
Getting Started
Contents
Why do we need chains?
Quick start: Using LLMChain
Different ways of calling chains
Add memory to chains
Debug Chain
Combine chains with the SequentialChain
Create a custom chain with the Chain class
Getting Started#
In this tutorial, we will learn about creating simple chains in ... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
9070a6f2448d-1 | print(chain.run("colorful socks"))
Colorful Toes Co.
If there are multiple variables, you can input them all at once using a dictionary.
prompt = PromptTemplate(
input_variables=["company", "product"],
template="What is a good name for {company} that makes {product}?",
)
chain = LLMChain(llm=llm, prompt=prompt)... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
9070a6f2448d-2 | llm_chain(inputs={"adjective":"corny"})
{'adjective': 'corny',
'text': 'Why did the tomato turn red? Because it saw the salad dressing!'}
By default, __call__ returns both the input and output key values. You can configure it to only return output key values by setting return_only_outputs to True.
llm_chain("corny", r... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
9070a6f2448d-3 | from langchain.memory import ConversationBufferMemory
conversation = ConversationChain(
llm=chat,
memory=ConversationBufferMemory()
)
conversation.run("Answer briefly. What are the first 3 colors of a rainbow?")
# -> The first three colors of a rainbow are red, orange, and yellow.
conversation.run("And the next... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
9070a6f2448d-4 | Current conversation:
Human: What is ChatGPT?
AI:
> Finished chain.
'ChatGPT is an AI language model developed by OpenAI. It is based on the GPT-3 architecture and is capable of generating human-like responses to text prompts. ChatGPT has been trained on a massive amount of text data and can understand and respond to a... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
9070a6f2448d-5 | catchphrase = overall_chain.run("colorful socks")
print(catchphrase)
> Entering new SimpleSequentialChain chain...
Rainbow Socks Co.
"Put a little rainbow in your step!"
> Finished chain.
"Put a little rainbow in your step!"
Create a custom chain with the Chain class#
LangChain provides many chains out of the box, but ... | https://python.langchain.com/en/latest/modules/chains/getting_started.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.