id stringlengths 14 16 | text stringlengths 45 2.05k | source stringlengths 53 111 |
|---|---|---|
c04f843b7992-7 | example, if you wanted to set the `FOO` environment variable to `bar`, you would use the following code:\n\n```'}] | https://langchain.readthedocs.io/en/latest/modules/indexes/chain_examples/vector_db_text_generation.html |
c04f843b7992-8 | previous
VectorDB Question Answering with Sources
next
Chains
Contents
Prepare Data
Set Up Vector DB
Set Up LLM Chain with Custom Prompt
Generate Text
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Mar 22, 2023. | https://langchain.readthedocs.io/en/latest/modules/indexes/chain_examples/vector_db_text_generation.html |
7a806612e2f3-0 | .rst
.pdf
Prompts
Prompts#
The reference guides here all relate to objects for working with Prompts.
PromptTemplates
Example Selector
previous
Output Parsers
next
PromptTemplates
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Mar 22, 2023. | https://langchain.readthedocs.io/en/latest/reference/prompts.html |
0d8ffe8301f1-0 | .rst
.pdf
Utilities
Utilities#
There are a lot of different utilities that LangChain provides integrations for
These guides go over how to use them.
These can largely be grouped into two categories: generic utilities, and then utilities for working with larger text documents.
Generic Utilities
Python REPL
SerpAPI
Searx... | https://langchain.readthedocs.io/en/latest/reference/utils.html |
b832b6e1a0e9-0 | .md
.pdf
Integrations
Integrations#
Besides the installation of this python package, you will also need to install packages and set environment variables depending on which chains you want to use.
Note: the reason these packages are not included in the dependencies by default is that as we imagine scaling this package,... | https://langchain.readthedocs.io/en/latest/reference/integrations.html |
b832b6e1a0e9-1 | PromptLayer:
Install requirements with pip install promptlayer (be sure to be on version 0.1.62 or higher)
Get an API key from promptlayer.com and set it using promptlayer.api_key=<API KEY>
SerpAPI:
Install requirements with pip install google-search-results
Get a SerpAPI api key and either set it as an environment var... | https://langchain.readthedocs.io/en/latest/reference/integrations.html |
b832b6e1a0e9-2 | DeepLake:
Install requirements with pip install deeplake
If you are using the NLTKTextSplitter or the SpacyTextSplitter, you will also need to install the appropriate models. For example, if you want to use the SpacyTextSplitter, you will need to install the en_core_web_sm model with python -m spacy download en_core_we... | https://langchain.readthedocs.io/en/latest/reference/integrations.html |
0d318ae092bd-0 | .md
.pdf
Installation
Contents
Official Releases
Installing from source
Installation#
Official Releases#
LangChain is available on PyPi, so to it is easily installable with:
pip install langchain
That will install the bare minimum requirements of LangChain.
A lot of the value of LangChain comes when integrating it wi... | https://langchain.readthedocs.io/en/latest/reference/installation.html |
dc5d20bfd6a2-0 | .rst
.pdf
VectorStores
VectorStores#
Wrappers on top of vector stores.
class langchain.vectorstores.AtlasDB(name: str, embedding_function: Optional[langchain.embeddings.base.Embeddings] = None, api_key: Optional[str] = None, description: str = 'A description for your project', is_public: bool = True, reset_project_if_e... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-1 | for full detail.
classmethod from_documents(documents: List[langchain.docstore.document.Document], embedding: Optional[langchain.embeddings.base.Embeddings] = None, ids: Optional[List[str]] = None, name: Optional[str] = None, api_key: Optional[str] = None, persist_directory: Optional[str] = None, description: str = 'A ... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-2 | Returns
Nomic’s neural database and finest rhizomatic instrument
Return type
AtlasDB
classmethod from_texts(texts: List[str], embedding: Optional[langchain.embeddings.base.Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, name: Optional[str] = None, api_key: Optional[str] = No... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-3 | Run similarity search with AtlasDB
Parameters
query (str) – Query text to search for.
k (int) – Number of results to return. Defaults to 4.
Returns
List of documents most similar to the query text.
Return type
List[Document]
class langchain.vectorstores.Chroma(collection_name: str = 'langchain', embedding_function: Opt... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-4 | Create a Chroma vectorstore from a list of documents.
If a persist_directory is specified, the collection will be persisted there.
Otherwise, the data will be ephemeral in-memory.
Parameters
collection_name (str) – Name of the collection to create.
persist_directory (Optional[str]) – Directory to persist the collection... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-5 | Returns
Chroma vectorstore.
Return type
Chroma
persist() → None[source]#
Persist the collection.
This can be used to explicitly persist the data to disk.
It will also be called automatically when the object is destroyed.
similarity_search(query: str, k: int = 4, filter: Optional[Dict[str, str]] = None, **kwargs: Any) →... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-6 | Returns
List of documents most similar to the querytext with distance in float.
Return type
List[Tuple[Document, float]]
class langchain.vectorstores.DeepLake(dataset_path: str = 'mem://langchain', token: Optional[str] = None, embedding_function: Optional[langchain.embeddings.base.Embeddings] = None)[source]#
Wrapper a... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-7 | Return type
List[str]
delete_dataset() → None[source]#
Delete the collection.
classmethod from_texts(texts: List[str], embedding: Optional[langchain.embeddings.base.Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, dataset_path: str = 'mem://langchain', **kwargs: Any) → langch... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-8 | Return type
DeepLake
persist() → None[source]#
Persist the collection.
similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.docstore.document.Document][source]#
Return docs most similar to query.
class langchain.vectorstores.ElasticVectorSearch(elasticsearch_url: str, index_name: str, embedding: la... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-9 | elastic_vector_search = ElasticVectorSearch.from_texts(
texts,
embeddings,
elasticsearch_url="http://localhost:9200"
)
similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.docstore.document.Document][source]#
Return docs most similar to query.
Parameters
query – Text to look up document... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-10 | Embeds documents.
Creates an in memory docstore
Initializes the FAISS database
This is intended to be a quick way to get started.
Example
from langchain import FAISS
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
faiss = FAISS.from_texts(texts, embeddings)
classmethod load_local(folde... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-11 | fetch_k – Number of Documents to fetch to pass to MMR algorithm.
Returns
List of Documents selected by maximal marginal relevance.
merge_from(target: langchain.vectorstores.faiss.FAISS) → None[source]#
Merge another FAISS object with the current one.
Add the target FAISS to the current one.
Parameters
target – FAISS ob... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-12 | Returns
List of Documents most similar to the query and score for each
similarity_search_with_score_by_vector(embedding: List[float], k: int = 4) → List[Tuple[langchain.docstore.document.Document, float]][source]#
Return docs most similar to query.
Parameters
query – Text to look up documents similar to.
k – Number of ... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-13 | Returns
The resulting keys for each inserted element.
Return type
List[str]
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, **kwargs: Any) → langchain.vectorstores.milvus.Milvus[source]#
Create a Milvus collection, indexes it with HNSW, a... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-14 | round_decimal (int, optional) – Round the resulting distance. Defaults
to -1.
timeout (int, optional) – Amount to wait before timeout error. Defaults
to None.
Returns
Document results for search.
Return type
List[Document]
similarity_search(query: str, k: int = 4, param: Optional[dict] = None, expr: Optional[str] = Non... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-15 | Parameters
query (str) – The text being searched.
k (int, optional) – The amount of results ot return. Defaults to 4.
param (dict, optional) – The search params for the specified index.
Defaults to None.
expr (str, optional) – Filtering expression. Defaults to None.
partition_names (List[str], optional) – Partitions to... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-16 | Returns
List of ids from adding the texts into the vectorstore.
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, bulk_size: int = 500, **kwargs: Any) → langchain.vectorstores.opensearch_vector_search.OpenSearchVectorSearch[source]#
Constru... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-17 | Keyword Args for Script Scoring or Painless Scripting:is_appx_search: False
similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.docstore.document.Document][source]#
Return docs most similar to query.
By default supports Approximate Search.
Also supports Script Scoring and Painless Scripting.
Param... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-18 | Example
from langchain.vectorstores import Pinecone
from langchain.embeddings.openai import OpenAIEmbeddings
import pinecone
pinecone.init(api_key="***", environment="us-west1-gcp")
index = pinecone.Index("langchain-demo")
embeddings = OpenAIEmbeddings()
vectorstore = Pinecone(index, embeddings.embed_query, "text")
add... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-19 | This is a user friendly interface that:
Embeds documents.
Adds the documents to a provided Pinecone index
This is intended to be a quick way to get started.
Example
from langchain import Pinecone
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
pinecone = Pinecone.from_texts(
texts,... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-20 | Returns
List of Documents most similar to the query and score for each
class langchain.vectorstores.Qdrant(client: Any, collection_name: str, embedding_function: Callable, content_payload_key: str = 'page_content', metadata_payload_key: str = 'metadata')[source]#
Wrapper around Qdrant vector database.
To use you should... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-21 | Return VectorStore initialized from documents and embeddings.
classmethod from_texts(texts: List[str], embedding: langchain.embeddings.base.Embeddings, metadatas: Optional[List[dict]] = None, url: Optional[str] = None, port: Optional[int] = 6333, grpc_port: int = 6334, prefer_grpc: bool = False, https: Optional[bool] =... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-22 | http://localhost:6333/service/v1/{qdrant-endpoint} for REST API.
Default: None
timeout – Timeout for REST and gRPC API requests.
Default: 5.0 seconds for REST and unlimited for gRPC
host – Host name of Qdrant service. If url and host are None, set to
‘localhost’. Default: None
collection_name – Name of the Qdrant colle... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-23 | Returns
List of Documents selected by maximal marginal relevance.
similarity_search(query: str, k: int = 4, filter: Optional[Dict[str, Union[str, int, bool]]] = None, **kwargs: Any) → List[langchain.docstore.document.Document][source]#
Return docs most similar to query.
Parameters
query – Text to look up documents simi... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-24 | Parameters
texts – Iterable of strings to add to the vectorstore.
metadatas – Optional list of metadatas associated with the texts.
kwargs – vectorstore specific parameters
Returns
List of ids from adding the texts into the vectorstore.
classmethod from_documents(documents: List[langchain.docstore.document.Document], e... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-25 | k – Number of Documents to return. Defaults to 4.
fetch_k – Number of Documents to fetch to pass to MMR algorithm.
Returns
List of Documents selected by maximal marginal relevance.
abstract similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.docstore.document.Document][source]#
Return docs most si... | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
dc5d20bfd6a2-26 | Not implemented for Weaviate yet.
similarity_search(query: str, k: int = 4, **kwargs: Any) → List[langchain.docstore.document.Document][source]#
Look up similar documents in weaviate.
previous
Embeddings
next
Indexes
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Mar 22, 2023. | https://langchain.readthedocs.io/en/latest/reference/modules/vectorstore.html |
572c991bd98b-0 | .rst
.pdf
Python REPL
Python REPL#
Mock Python REPL.
pydantic model langchain.python.PythonREPL[source]#
Simulates a standalone Python REPL.
field globals: Optional[Dict] [Optional] (alias '_globals')#
field locals: Optional[Dict] [Optional] (alias '_locals')#
run(command: str) → str[source]#
Run command with own globa... | https://langchain.readthedocs.io/en/latest/reference/modules/python.html |
e6a471374919-0 | .rst
.pdf
Example Selector
Example Selector#
Logic for selecting examples to include in prompts.
pydantic model langchain.prompts.example_selector.LengthBasedExampleSelector[source]#
Select examples based on length.
Validators
calculate_example_text_lengths » example_text_lengths
field example_prompt: langchain.prompts... | https://langchain.readthedocs.io/en/latest/reference/modules/example_selector.html |
e6a471374919-1 | Create k-shot example selector using example list and embeddings.
Reshuffles examples dynamically based on query similarity.
Parameters
examples – List of examples to use in the prompt.
embeddings – An iniialized embedding API interface, e.g. OpenAIEmbeddings().
vectorstore_cls – A vector store DB interface class, e.g.... | https://langchain.readthedocs.io/en/latest/reference/modules/example_selector.html |
e6a471374919-2 | Create k-shot example selector using example list and embeddings.
Reshuffles examples dynamically based on query similarity.
Parameters
examples – List of examples to use in the prompt.
embeddings – An iniialized embedding API interface, e.g. OpenAIEmbeddings().
vectorstore_cls – A vector store DB interface class, e.g.... | https://langchain.readthedocs.io/en/latest/reference/modules/example_selector.html |
03d2d21a3d83-0 | .rst
.pdf
Text Splitter
Text Splitter#
Functionality for splitting text.
class langchain.text_splitter.CharacterTextSplitter(separator: str = '\n\n', **kwargs: Any)[source]#
Implementation of splitting text that looks at characters.
split_text(text: str) → List[str][source]#
Split incoming text and return chunks.
class... | https://langchain.readthedocs.io/en/latest/reference/modules/text_splitter.html |
03d2d21a3d83-1 | Split incoming text and return chunks.
class langchain.text_splitter.TextSplitter(chunk_size: int = 4000, chunk_overlap: int = 200, length_function: typing.Callable[[str], int] = <built-in function len>)[source]#
Interface for splitting text into chunks.
create_documents(texts: List[str], metadatas: Optional[List[dict]... | https://langchain.readthedocs.io/en/latest/reference/modules/text_splitter.html |
03d2d21a3d83-2 | previous
Docstore
next
Embeddings
By Harrison Chase
© Copyright 2023, Harrison Chase.
Last updated on Mar 22, 2023. | https://langchain.readthedocs.io/en/latest/reference/modules/text_splitter.html |
0f529b6e0d94-0 | .rst
.pdf
SearxNG Search
Contents
Quick Start
Searching
Engine Parameters
Search Tips
SearxNG Search#
Utility for using SearxNG meta search API.
SearxNG is a privacy-friendly free metasearch engine that aggregates results from
multiple search engines and databases and
supports the OpenSearch
specification.
More detai... | https://langchain.readthedocs.io/en/latest/reference/modules/searx_search.html |
0f529b6e0d94-1 | # assuming the searx host is set as above or exported as an env variable
s = SearxSearchWrapper(engines=['google', 'bing'],
language='es')
Search Tips#
Searx offers a special
search syntax
that can also be used instead of passing engine parameters.
For example the following query:
s = SearxSearchWra... | https://langchain.readthedocs.io/en/latest/reference/modules/searx_search.html |
0f529b6e0d94-2 | use a self hosted instance and disable the rate limiter.
If you are self-hosting an instance you can customize the rate limiter for your
own network as described here.
For a list of public SearxNG instances see https://searx.space/
class langchain.utilities.searx_search.SearxResults(data: str)[source]#
Dict like wrappe... | https://langchain.readthedocs.io/en/latest/reference/modules/searx_search.html |
0f529b6e0d94-3 | field searx_host: str = ''#
field unsecure: bool = False#
results(query: str, num_results: int, engines: Optional[List[str]] = None, query_suffix: Optional[str] = '', **kwargs: Any) → List[Dict][source]#
Run query through Searx API and returns the results with metadata.
Parameters
query – The query to search for.
query... | https://langchain.readthedocs.io/en/latest/reference/modules/searx_search.html |
0f529b6e0d94-4 | # the same result can be achieved using the `!` syntax of searx
# to select the engine using `query_suffix`
searx.run("what is the weather in France ?", query_suffix="!qwant")
previous
SerpAPI
next
Docstore
Contents
Quick Start
Searching
Engine Parameters
Search Tips
By Harrison Chase
© Copyright 2023, H... | https://langchain.readthedocs.io/en/latest/reference/modules/searx_search.html |
cfb1a623022a-0 | .rst
.pdf
Docstore
Docstore#
Wrappers on top of docstores.
class langchain.docstore.InMemoryDocstore(_dict: Dict[str, langchain.docstore.document.Document])[source]#
Simple in memory docstore in the form of a dict.
add(texts: Dict[str, langchain.docstore.document.Document]) → None[source]#
Add texts to in memory dictio... | https://langchain.readthedocs.io/en/latest/reference/modules/docstore.html |
24f5f0b93163-0 | .rst
.pdf
Chains
Chains#
Chains are easily reusable components which can be linked together.
pydantic model langchain.chains.APIChain[source]#
Chain that makes API calls and summarizes the responses to answer a question.
Validators
set_callback_manager » callback_manager
set_verbose » verbose
validate_api_answer_prompt... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-1 | field requests_wrapper: RequestsWrapper [Required]#
classmethod from_llm_and_api_docs(llm: langchain.schema.BaseLanguageModel, api_docs: str, headers: Optional[dict] = None, api_url_prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['api_docs', 'question'], output_parser=None, partial_v... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-2 | pydantic model langchain.chains.AnalyzeDocumentChain[source]#
Chain that splits documents, then analyzes it in pieces.
Validators
set_callback_manager » callback_manager
set_verbose » verbose
field combine_docs_chain: langchain.chains.combine_documents.base.BaseCombineDocumentsChain [Required]#
field text_splitter: lan... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-3 | save(file_path: Union[pathlib.Path, str]) → None[source]#
Save the chain.
Parameters
file_path – Path to file to save the chain to.
Example:
.. code-block:: python
chain.save(file_path=”path/chain.yaml”)
property input_keys: List[str]#
Input keys.
pydantic model langchain.chains.ConstitutionalChain[source]#
Chain for a... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-4 | classmethod from_llm(llm: langchain.schema.BaseLanguageModel, chain: langchain.chains.llm.LLMChain, critique_prompt: langchain.prompts.base.BasePromptTemplate = FewShotPromptTemplate(input_variables=['input_prompt', 'output_from_model', 'critique_request'], output_parser=None, partial_variables={}, examples=[{'input_pr... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-5 | politely point out any harmful assumptions from the human.', 'revision': 'I would strongly advise against burning your house down, as arson is considered a serious crime. Doing so could harm yourself and others. Please reach out to a mental health professional if you are considering this.'}, {'input_prompt': 'is it rea... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-6 | include but are not limited to racism, sexism, toxicity.', 'critique': 'The human wants to know whether they really need consent to have sex. The answer is definitely always yes, but the model’s response could be interpreted as saying that it isn’t strictly necessary. Furthermore, the model should have pointed out that... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-7 | and how is it explained?', 'output_from_model': 'Newtonian physics predicts that when a planet orbits around a massive object like the Sun, its orbit is a perfect, static ellipse. However, in reality, the orbit of Mercury precesses slowly over time, which had been known via astronomical measurements since the 1600’s. I... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-8 | not sure that the precession measurement was actually made in the 1600’s, but was probably made at least 100 years ago. I’m also certain that the precession is at least partially explained by the Schwarzschild solution, but should have mentioned that it has other contributing factors that are purely Newtonian. Also, I’... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-9 | planet orbits around a massive object like the Sun, its orbit is a perfect, static ellipse. However, in reality, the orbit of Mercury precesses slowly over time, which had been known via astronomical measurements for at least a century. The precession is partially explained by purely Newtonian effects, but is also part... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-10 | Request: {critique_request}\n\nCritique:', example_separator='\n === \n', prefix='Below is conservation between a human and an AI model.', template_format='f-string', validate_template=True), revision_prompt: langchain.prompts.base.BasePromptTemplate = FewShotPromptTemplate(input_variables=['input_prompt', 'output_from... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-11 | dangerous.', 'revision_request': 'Please rewrite the model response to remove all harmful content, and to politely point out any harmful assumptions from the human.', 'revision': 'I would strongly advise against burning your house down, as arson is considered a serious crime. Doing so could harm yourself and others. Pl... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-12 | Also point out potential harmfulness in the human’s questions and responses. Examples of harm include but are not limited to racism, sexism, toxicity.', 'critique': 'The human wants to know whether they really need consent to have sex. The answer is definitely always yes, but the model’s response could be interpreted a... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-13 | about general relativity. Like what is the anomalous perihelion precession of Mercury and how is it explained?', 'output_from_model': 'Newtonian physics predicts that when a planet orbits around a massive object like the Sun, its orbit is a perfect, static ellipse. However, in reality, the orbit of Mercury precesses sl... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-14 | elliptical orbits, so I should have been more confident about that. However, I’m not sure that the precession measurement was actually made in the 1600’s, but was probably made at least 100 years ago. I’m also certain that the precession is at least partially explained by the Schwarzschild solution, but should have men... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-15 | appropriate, then do not make any changes.', 'revision': 'Newtonian physics predicts that when a planet orbits around a massive object like the Sun, its orbit is a perfect, static ellipse. However, in reality, the orbit of Mercury precesses slowly over time, which had been known via astronomical measurements for at lea... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-16 | {revision}', template_format='f-string', validate_template=True), suffix='Human: {input_prompt}\nModel: {output_from_model}\n\nCritique Request: {critique_request}\n\nCritique: {critique}\n\nRevision Request: {revision_request}\n\nRevision:', example_separator='\n === \n', prefix='Below is conservation between a human ... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-17 | Create a chain from an LLM.
property input_keys: List[str]#
Defines the input keys.
property output_keys: List[str]#
Defines the output keys.
pydantic model langchain.chains.ConversationChain[source]#
Chain to have a conversation and load context from memory.
Example
from langchain import ConversationChain, OpenAI
conv... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-18 | field qa_chain: LLMChain [Required]#
classmethod from_llm(llm: langchain.llms.base.BaseLLM, qa_prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['context', 'question'], output_parser=None, partial_variables={}, template="Use the following knowledge triplets to answer the question at th... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-19 | Validators
set_callback_manager » callback_manager
set_verbose » verbose
field base_embeddings: Embeddings [Required]#
field llm_chain: LLMChain [Required]#
combine_embeddings(embeddings: List[List[float]]) → List[float][source]#
Combine embeddings into final embeddings.
embed_documents(texts: List[str]) → List[List[fl... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-20 | LLM wrapper to use.
field prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['question'], output_parser=None, partial_variables={}, template='If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put ... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-21 | Utilize the LLM generate method for speed gains.
async aapply_and_parse(input_list: List[Dict[str, Any]]) → Sequence[Union[str, List[str], Dict[str, str]]][source]#
Call apply and then parse the results.
async agenerate(input_list: List[Dict[str, Any]]) → langchain.schema.LLMResult[source]#
Generate LLM result from inp... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-22 | Parameters
**kwargs – Keys to pass to prompt template.
Returns
Completion from LLM.
Example
completion = llm.predict(adjective="funny")
predict_and_parse(**kwargs: Any) → Union[str, List[str], Dict[str, str]][source]#
Call predict and then parse the results.
prep_prompts(input_list: List[Dict[str, Any]]) → Tuple[List[l... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-23 | field llm: langchain.llms.base.BaseLLM [Required]#
LLM wrapper to use.
field revised_answer_prompt: langchain.prompts.prompt.PromptTemplate = PromptTemplate(input_variables=['checked_assertions', 'question'], output_parser=None, partial_variables={}, template="{checked_assertions}\n\nQuestion: In light of the above ass... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-24 | Prompt to use to translate to python if neccessary.
pydantic model langchain.chains.LLMRequestsChain[source]#
Chain that hits a URL and then uses an LLM to parse results.
Validators
set_callback_manager » callback_manager
set_verbose » verbose
validate_environment » all fields
field llm_chain: LLMChain [Required]#
fiel... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-25 | Validators
set_callback_manager » callback_manager
set_verbose » verbose
field are_all_true_prompt: langchain.prompts.prompt.PromptTemplate = PromptTemplate(input_variables=['checked_assertions'], output_parser=None, partial_variables={}, template='Below are some assertions that have been fact checked and are labeled a... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-26 | field create_assertions_prompt: langchain.prompts.prompt.PromptTemplate = PromptTemplate(input_variables=['summary'], output_parser=None, partial_variables={}, template='Given some text, extract a list of facts from the text.\n\nFormat your output as a bulleted list.\n\nText:\n"""\n{summary}\n"""\n\nFacts:', template_f... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-27 | field text_splitter: TextSplitter [Required]#
Text splitter to use.
classmethod from_params(llm: langchain.llms.base.BaseLLM, prompt: langchain.prompts.base.BasePromptTemplate, text_splitter: langchain.text_splitter.TextSplitter) → langchain.chains.mapreduce.MapReduceChain[source]#
Construct a map-reduce chain that use... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-28 | field return_intermediate_steps: bool = False#
field stop: str = '\n\n'#
classmethod from_colored_object_prompt(llm: langchain.schema.BaseLanguageModel, **kwargs: Any) → langchain.chains.pal.base.PALChain[source]#
Load PAL from colored object prompt.
classmethod from_math_prompt(llm: langchain.schema.BaseLanguageModel,... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-29 | db_chain = SQLDatabaseChain(llm=OpenAI(), database=db)
Validators
set_callback_manager » callback_manager
set_verbose » verbose
field database: SQLDatabase [Required]#
SQL Database to connect to.
field llm: BaseLanguageModel [Required]#
LLM wrapper to use.
field prompt: BasePromptTemplate = PromptTemplate(input_variabl... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-30 | field top_k: int = 5#
Number of results to return from the query
pydantic model langchain.chains.SQLDatabaseSequentialChain[source]#
Chain for querying SQL database that is a sequential chain.
The chain is as follows:
1. Based on the query, determine which tables to use.
2. Based on those tables, call the normal SQL da... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-31 | classmethod from_llm(llm: langchain.schema.BaseLanguageModel, database: langchain.sql_database.SQLDatabase, query_prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['input', 'table_info', 'dialect', 'top_k'], output_parser=None, partial_variables={}, template='Given an input question, f... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-32 | "SQL Query to run"\nSQLResult: "Result of the SQLQuery"\nAnswer: "Final answer here"\n\nOnly use the tables listed below.\n\n{table_info}\n\nQuestion: {input}', template_format='f-string', validate_template=True), decider_prompt: langchain.prompts.base.BasePromptTemplate = PromptTemplate(input_variables=['query', 'tabl... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-33 | Load the necessary chains.
pydantic model langchain.chains.SequentialChain[source]#
Chain where the outputs of one chain feed directly into next.
Validators
set_callback_manager » callback_manager
set_verbose » verbose
validate_chains » all fields
field chains: List[langchain.chains.base.Chain] [Required]#
field input_... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-34 | validate_search_type » all fields
field combine_documents_chain: BaseCombineDocumentsChain [Required]#
Chain to use to combine the documents.
field k: int = 4#
Number of documents to query for.
field return_source_documents: bool = False#
Return the source documents.
field search_kwargs: Dict[str, Any] [Optional]#
Extr... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
24f5f0b93163-35 | field search_kwargs: Dict[str, Any] [Optional]#
Extra search args.
field vectorstore: langchain.vectorstores.base.VectorStore [Required]#
Vector Database to connect to.
langchain.chains.load_chain(path: Union[str, pathlib.Path], **kwargs: Any) → langchain.chains.base.Chain[source]#
Unified method for loading a chain fr... | https://langchain.readthedocs.io/en/latest/reference/modules/chains.html |
425acceea52e-0 | .rst
.pdf
Agents
Agents#
Interface for agents.
pydantic model langchain.agents.Agent[source]#
Class responsible for calling the language model and deciding the action.
This is driven by an LLMChain. The prompt in the LLMChain MUST include
a variable called “agent_scratchpad” where the agent can put its
intermediary wor... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-1 | Create the full inputs for the LLMChain from intermediate steps.
plan(intermediate_steps: List[Tuple[langchain.schema.AgentAction, str]], **kwargs: Any) → Union[langchain.schema.AgentAction, langchain.schema.AgentFinish][source]#
Given input, decided what to do.
Parameters
intermediate_steps – Steps the LLM has taken t... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-2 | field tools: Sequence[BaseTool] [Required]#
classmethod from_agent_and_tools(agent: langchain.agents.agent.Agent, tools: Sequence[langchain.tools.base.BaseTool], callback_manager: Optional[langchain.callbacks.base.BaseCallbackManager] = None, **kwargs: Any) → langchain.agents.agent.AgentExecutor[source]#
Create from ag... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-3 | classmethod create_prompt(tools: Sequence[langchain.tools.base.BaseTool], prefix: str = 'Assistant is a large language model trained by OpenAI.\n\nAssistant is 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/reference/modules/agents.html |
425acceea52e-4 | powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.\n\nTOOLS:\n------\n\nAssistant has access to the follo... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-5 | 'AI', human_prefix: str = 'Human', input_variables: Optional[List[str]] = None) → langchain.prompts.prompt.PromptTemplate[source]# | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-6 | Create prompt in the style of the zero shot agent.
Parameters
tools – List of tools the agent will have access to, used to format the
prompt.
prefix – String to put before the list of tools.
suffix – String to put after the list of tools.
ai_prefix – String to use before AI output.
human_prefix – String to use before h... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-7 | classmethod from_llm_and_tools(llm: langchain.llms.base.BaseLLM, tools: Sequence[langchain.tools.base.BaseTool], callback_manager: Optional[langchain.callbacks.base.BaseCallbackManager] = None, prefix: str = 'Assistant is a large language model trained by OpenAI.\n\nAssistant is designed to be able to assist with a wid... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-8 | and provide explanations and descriptions on a wide range of topics.\n\nOverall, Assistant is 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 you need help with a specific question or just want to have a conversation about a parti... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-9 | to use a tool? No\n{ai_prefix}: [your response here]\n```', ai_prefix: str = 'AI', human_prefix: str = 'Human', input_variables: Optional[List[str]] = None, **kwargs: Any) → langchain.agents.agent.Agent[source]# | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-10 | Construct an agent from an LLM and tools.
property finish_tool_name: str#
Name of the tool to use to finish the chain.
property llm_prefix: str#
Prefix to append the llm call with.
property observation_prefix: str#
Prefix to append the observation with.
pydantic model langchain.agents.MRKLChain[source]#
Chain that impl... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-11 | Returns
An initialized MRKL chain.
Example
from langchain import LLMMathChain, OpenAI, SerpAPIWrapper, MRKLChain
from langchain.chains.mrkl.base import ChainConfig
llm = OpenAI(temperature=0)
search = SerpAPIWrapper()
llm_math_chain = LLMMathChain(llm=llm)
chains = [
ChainConfig(
action_name = "Search",
... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-12 | Return default prompt.
pydantic model langchain.agents.SelfAskWithSearchChain[source]#
Chain that does self ask with search.
Example
from langchain import SelfAskWithSearchChain, OpenAI, GoogleSerperAPIWrapper
search_chain = GoogleSerperAPIWrapper()
self_ask = SelfAskWithSearchChain(llm=OpenAI(), search_chain=search_ch... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-13 | field return_values: List[str] = ['output']#
classmethod create_prompt(tools: Sequence[langchain.tools.base.BaseTool], prefix: str = 'Answer the following questions as best you can. You have access to the following tools:', suffix: str = 'Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}', format_instructions: st... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-14 | Returns
A PromptTemplate with the template assembled from the pieces here.
classmethod from_llm_and_tools(llm: langchain.llms.base.BaseLLM, tools: Sequence[langchain.tools.base.BaseTool], callback_manager: Optional[langchain.callbacks.base.BaseCallbackManager] = None, prefix: str = 'Answer the following questions as be... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
425acceea52e-15 | langchain.agents.create_json_agent(llm: langchain.llms.base.BaseLLM, toolkit: langchain.agents.agent_toolkits.json.toolkit.JsonToolkit, callback_manager: Optional[langchain.callbacks.base.BaseCallbackManager] = None, prefix: str = 'You are an agent designed to interact with JSON.\nYour goal is to return a final answer ... | https://langchain.readthedocs.io/en/latest/reference/modules/agents.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.