chains
#
Chains are easily reusable components linked together.
Chains encode a sequence of calls to components like models, document retrievers, other Chains, etc., and provide a simple interface to this sequence.
The Chain interface makes it easy to create apps that are:
Stateful: add Memory to any Chain to give it state,
Observable: pass Callbacks to a Chain to execute additional functionality, like logging, outside the main sequence of component calls,
Composable: combine Chains with other components, including other Chains.
Class hierarchy:
Chain --> <name>Chain # Examples: LLMChain, MapReduceChain, RouterChain
Classes
Abstract base class for creating structured sequences of calls to components. |
|
Base interface for chains combining documents. |
|
Combining documents by mapping a chain over them, then combining results. |
|
Combining documents by mapping a chain over them, then reranking results. |
|
|
Interface for the combine_docs method. |
Interface for the combine_docs method. |
|
Combine documents by recursively reducing them. |
|
Combine documents by doing a first pass and then refining on more documents. |
|
Class for a constitutional principle. |
|
|
Chain for chatting with an index. |
Chain for chatting with a vector database. |
|
Input type for ConversationalRetrievalChain. |
|
|
Chain for interacting with Elasticsearch Database. |
Chain that combines a retriever, a question generator, and a response generator. |
|
Chain that generates questions from uncertain spans. |
|
Output parser that checks if the output is finished. |
|
Generate hypothetical document for query, and then embed that. |
|
Pass input through a moderation endpoint. |
|
A crawler for web pages. |
|
A typed dictionary containing information about elements in the viewport. |
|
|
Class representing a single statement. |
A question and its answer as a list of facts each one should have a source. |
|
Chain for making a simple request to an API endpoint. |
|
An answer to the question, with sources. |
|
Base class for prompt selectors. |
|
Prompt collection that goes through conditionals. |
|
Interface for loading the combine documents chain. |
|
|
Question-answering with sources over an index. |
Question-answering with sources over a vector database. |
|
Output parser that parses a structured query. |
|
A date in ISO 8601 format (YYYY-MM-DD). |
|
A datetime in ISO 8601 format (YYYY-MM-DDTHH:MM:SS). |
|
Information about a data source attribute. |
|
Interface for loading the combine documents chain. |
|
Use a single chain to route an input to one of multiple candidate chains. |
|
|
Create new instance of Route(destination, next_inputs) |
Chain that outputs the name of a destination chain and the inputs to it. |
|
Chain that uses embeddings to route between options. |
|
Parser for output of router chain in the multi-prompt chain. |
|
A multi-route chain that uses an LLM router chain to choose amongst retrieval qa chains. |
|
Chain where the outputs of one chain feed directly into next. |
|
Simple chain where the outputs of one step feed directly into next. |
|
Input for a SQL Chain. |
|
Input for a SQL Chain. |
|
Interface for loading the combine documents chain. |
|
Chain that transforms the chain output. |
Functions
Execute a collapse function on a set of documents and merge their metadatas. |
|
Execute a collapse function on a set of documents and merge their metadatas. |
|
Split Documents into subsets that each meet a cumulative length constraint. |
|
|
Create a chain for passing a list of Documents to a model. |
Return another example given a list of examples for a prompt. |
|
|
Create a chain that takes conversation history and returns documents. |
|
Create a citation fuzzy match Runnable. |
|
Convert a valid OpenAPI spec to the JSON Schema format expected for OpenAI |
Return the kwargs for the LLMChain constructor. |
|
Check if the language model is a chat model. |
|
Check if the language model is a LLM. |
|
Construct examples from input-output pairs. |
|
Fix invalid filter directive. |
|
|
Create query construction prompt. |
|
Load a query constructor runnable chain. |
Return a parser for the query language. |
|
Dummy decorator for when lark is not installed. |
|
Create retrieval chain that retrieves documents and then passes them on. |
|
Create a chain that generates SQL queries. |
|
Get the appropriate function output parser given the user functions. |
|
Load summarizing chain. |
Deprecated classes
Deprecated since version 0.2.13: This class is deprecated and will be removed in langchain 1.0. See API reference for replacement: https://api.python.langchain.com/en/latest/chains/langchain.chains.api.base.APIChain.html |
|
Deprecated since version 0.2.7: Use |
|
Deprecated since version 0.2.13: This class is deprecated. Use the create_stuff_documents_chain constructor instead. See migration guide here: https://python.langchain.com/v0.2/docs/versions/migrating_chains/stuff_docs_chain/ |
|
Deprecated since version 0.2.13: This class is deprecated and will be removed in langchain 1.0. See API reference for replacement: https://api.python.langchain.com/en/latest/chains/langchain.chains.constitutional_ai.base.ConstitutionalChain.html |
|
Deprecated since version 0.2.7: Use |
|
|
Deprecated since version 0.1.17: Use |
Deprecated since version 0.1.17: Use |
|
Deprecated since version 0.2.13: See LangGraph guides for a variety of self-reflection and corrective strategies for question-answering and other tasks: https://langchain-ai.github.io/langgraph/tutorials/rag/langgraph_self_rag/ |
|
Deprecated since version 0.2.13: This class is deprecated and will be removed in langchain 1.0. See API reference for replacement: https://api.python.langchain.com/en/latest/chains/langchain.chains.llm_math.base.LLMMathChain.html |
|
|
Deprecated since version 0.2.13: See LangGraph guides for a variety of self-reflection and corrective strategies for question-answering and other tasks: https://langchain-ai.github.io/langgraph/tutorials/rag/langgraph_self_rag/ |
Deprecated since version 0.2.13: Refer here for a recommended map-reduce implementation using langgraph: https://langchain-ai.github.io/langgraph/how-tos/map-reduce/. See also migration guide: https://python.langchain.com/v0.2/docs/versions/migrating_chains/map_reduce_chain/ |
|
Deprecated since version 0.2.13: Importing NatBotChain from langchain is deprecated and will be removed in langchain 1.0. Please import from langchain_community instead: from langchain_community.chains.natbot import NatBotChain. You may need to pip install -U langchain-community. |
|
Deprecated since version 0.2.7: Use |
|
Deprecated since version 0.2.13: This class is deprecated. Refer to this guide on retrieval and question answering with sources: https://python.langchain.com/v0.2/docs/how_to/qa_sources/ |
|
Deprecated since version 0.2.13: This class is deprecated. Refer to this guide on retrieval and question answering with sources: https://python.langchain.com/v0.2/docs/how_to/qa_sources/ |
|
Deprecated since version 0.2.13: This class is deprecated. Use the create_retrieval_chain constructor instead. See migration guide here: https://python.langchain.com/v0.2/docs/versions/migrating_chains/retrieval_qa/ |
|
Deprecated since version 0.1.17: This class is deprecated. Use the create_retrieval_chain constructor instead. See migration guide here: https://python.langchain.com/v0.2/docs/versions/migrating_chains/retrieval_qa/ |
|
Deprecated since version 0.2.13: This class is deprecated. Use the create_retrieval_chain constructor instead. See migration guide here: https://python.langchain.com/v0.2/docs/versions/migrating_chains/retrieval_qa/ |
|
Deprecated since version 0.2.12: Use RunnableLambda to select from multiple prompt templates. See example in API reference: https://api.python.langchain.com/en/latest/chains/langchain.chains.router.llm_router.LLMRouterChain.html |
|
Deprecated since version 0.2.12: Use RunnableLambda to select from multiple prompt templates. See example in API reference: https://api.python.langchain.com/en/latest/chains/langchain.chains.router.multi_prompt.MultiPromptChain.html |
Deprecated functions
|
Deprecated since version 0.2.13: This function is deprecated and will be removed in langchain 1.0. At that point chains must be imported from their respective modules. |
Deprecated since version 0.2.13: This function is deprecated and will be removed in langchain 1.0. At that point chains must be imported from their respective modules. |
|
Deprecated since version 0.1.1: Use |
|
|
Deprecated since version 0.1.1: Use |
|
Deprecated since version 0.2.13: Use |
|
Deprecated since version 0.1.14: LangChain has introduced a method called with_structured_output thatis available on ChatModels capable of tool calling.You can read more about the method here: <https://python.langchain.com/docs/modules/model_io/chat/structured_output/>. Please follow our extraction use case documentation for more guidelineson how to do information extraction with LLMs.<https://python.langchain.com/docs/use_cases/extraction/>. If you notice other issues, please provide feedback here:<langchain-ai/langchain#18154> Use `` |
|
Deprecated since version 0.1.14: LangChain has introduced a method called with_structured_output thatis available on ChatModels capable of tool calling.You can read more about the method here: <https://python.langchain.com/docs/modules/model_io/chat/structured_output/>. Please follow our extraction use case documentation for more guidelineson how to do information extraction with LLMs.<https://python.langchain.com/docs/use_cases/extraction/>. If you notice other issues, please provide feedback here:<langchain-ai/langchain#18154> Use `` |
Deprecated since version 0.2.13: This function is deprecated and will be removed in langchain 1.0. See API reference for replacement: https://api.python.langchain.com/en/latest/chains/langchain.chains.openai_functions.openapi.get_openapi_chain.html |
|
|
Deprecated since version 0.2.13: This function is deprecated. Refer to this guide on retrieval and question answering with sources: https://python.langchain.com/v0.2/docs/how_to/qa_sources/#structure-sources-in-model-response |
|
Deprecated since version 0.2.13: This function is deprecated. Refer to this guide on retrieval and question answering with structured responses: https://python.langchain.com/v0.2/docs/how_to/qa_sources/#structure-sources-in-model-response |
Deprecated since version 0.2.13: LangChain has introduced a method called with_structured_output that is available on ChatModels capable of tool calling. See API reference for this function for replacement: <https://api.python.langchain.com/en/latest/chains/langchain.chains.openai_functions.tagging.create_tagging_chain.html> You can read more about with_structured_output here: <https://python.langchain.com/v0.2/docs/how_to/structured_output/>. If you notice other issues, please provide feedback here: <langchain-ai/langchain#18154> |
|
|
Deprecated since version 0.2.13: LangChain has introduced a method called with_structured_output that is available on ChatModels capable of tool calling. See API reference for this function for replacement: <https://api.python.langchain.com/en/latest/chains/langchain.chains.openai_functions.tagging.create_tagging_chain_pydantic.html> You can read more about with_structured_output here: <https://python.langchain.com/v0.2/docs/how_to/structured_output/>. If you notice other issues, please provide feedback here: <langchain-ai/langchain#18154> |
|
Deprecated since version 0.1.14: LangChain has introduced a method called with_structured_output thatis available on ChatModels capable of tool calling.You can read more about the method here: <https://python.langchain.com/docs/modules/model_io/chat/structured_output/>. Please follow our extraction use case documentation for more guidelineson how to do information extraction with LLMs.<https://python.langchain.com/docs/use_cases/extraction/>. with_structured_output does not currently support a list of pydantic schemas. If this is a blocker or if you notice other issues, please provide feedback here:<langchain-ai/langchain#18154> Use `` |
|
Deprecated since version 0.2.13: This function is deprecated. Refer to this guide on retrieval and question answering with sources: https://python.langchain.com/v0.2/docs/how_to/qa_sources/ |
|
Deprecated since version 0.2.13: Use |
Deprecated since version 0.2.13: This class is deprecated. See the following migration guides for replacements based on chain_type: |
|
|
Deprecated since version 0.1.14: LangChain has introduced a method called with_structured_output that is available on ChatModels capable of tool calling. You can read more about the method here: <https://python.langchain.com/docs/modules/model_io/chat/structured_output/>. Please follow our extraction use case documentation for more guidelines on how to do information extraction with LLMs. <https://python.langchain.com/docs/use_cases/extraction/>. If you notice other issues, please provide feedback here: <langchain-ai/langchain#18154> Use `` |
|
Deprecated since version 0.1.17: LangChain has introduced a method called with_structured_output that is available on ChatModels capable of tool calling. You can read more about the method here: <https://python.langchain.com/docs/modules/model_io/chat/structured_output/>.Please follow our extraction use case documentation for more guidelines on how to do information extraction with LLMs. <https://python.langchain.com/docs/use_cases/extraction/>. If you notice other issues, please provide feedback here: <langchain-ai/langchain#18154> Use `` |