langchain API Reference¶
langchain.agents¶
Agent is a class that uses an LLM to choose a sequence of actions to take.
In Chains, a sequence of actions is hardcoded. In Agents, a language model is used as a reasoning engine to determine which actions to take and in which order.
Agents select and use Tools and Toolkits for actions.
Class hierarchy:
BaseSingleActionAgent --> LLMSingleActionAgent
OpenAIFunctionsAgent
XMLAgent
Agent --> <name>Agent # Examples: ZeroShotAgent, ChatAgent
BaseMultiActionAgent --> OpenAIMultiFunctionsAgent
Main helpers:
AgentType, AgentExecutor, AgentOutputParser, AgentExecutorIterator,
AgentAction, AgentFinish
Classes¶
Agent that calls the language model and deciding the action. |
|
Agent that is using tools. |
|
Base class for parsing agent output into agent action/finish. |
|
Base Multi Action Agent class. |
|
Base Single Action Agent class. |
|
Tool that just returns the query. |
|
Base class for single action agents. |
|
Iterator for AgentExecutor. |
|
Base class for AgentExecutorIterator. |
|
Toolkit for interacting with Office365. |
|
|
Toolkit for Azure Cognitive Services. |
Base Toolkit representing a collection of related tools. |
|
|
Toolkit for interacting with a Local Files. |
GitHub Toolkit. |
|
Toolkit for interacting with Gmail. |
|
Jira Toolkit. |
|
Toolkit for interacting with a JSON spec. |
|
Natural Language API Tool. |
|
Natural Language API Toolkit. |
|
Toolkit for interacting with Office 365. |
|
|
A tool that sends a DELETE request and parses the response. |
|
Requests GET tool with LLM-instructed extraction of truncated responses. |
|
Requests PATCH tool with LLM-instructed extraction of truncated responses. |
|
Requests POST tool with LLM-instructed extraction of truncated responses. |
Toolkit for interacting with an OpenAPI API. |
|
Toolkit for making REST requests. |
|
|
Toolkit for PlayWright browser tools. |
Toolkit for interacting with Power BI dataset. |
|
Toolkit for interacting with Spark SQL. |
|
Toolkit for interacting with SQL databases. |
|
Information about a VectorStore. |
|
|
Toolkit for routing between Vector Stores. |
|
Toolkit for interacting with a Vector Store. |
Zapier Toolkit. |
|
|
Enumerator with the Agent types. |
Chat Agent. |
|
Output parser for the chat agent. |
|
An agent that holds a conversation in addition to using tools. |
|
Output parser for the conversational agent. |
|
An agent designed to hold a conversation in addition to using tools. |
|
Output parser for the conversational agent. |
|
|
Configuration for chain to use in MRKL system. |
Chain that implements the MRKL system. |
|
Agent for the MRKL chain. |
|
MRKL Output parser for the chat agent. |
|
An Agent driven by OpenAIs function powered API. |
|
|
An Agent driven by OpenAIs function powered API. |
Chain that implements the ReAct paper. |
|
Agent for the ReAct chain. |
|
Agent for the ReAct TextWorld chain. |
|
Output parser for the ReAct agent. |
|
Chat prompt template for the agent scratchpad. |
|
Agent for the self-ask-with-search paper. |
|
Chain that does self-ask with search. |
|
|
Output parser for the self-ask agent. |
Structured Chat Agent. |
|
|
Output parser for the structured chat agent. |
|
Output parser with retries for the structured chat agent. |
Tool that is run when invalid tool name is encountered by agent. |
|
Agent that uses XML tags. |
|
Create a new model by parsing and validating input data from keyword arguments. |
Functions¶
Decorator to force setters to rebuild callback mgr |
|
Create csv agent by loading to a dataframe and using pandas agent. |
|
Construct a json agent from an LLM and tools. |
|
|
Construct a multion agent from an LLM and tool. |
|
Construct an OpenAPI agent from an LLM and tools. |
|
Instantiate OpenAI API planner and controller for a given spec. |
Try to substitute $refs. |
|
|
Simplify/distill/minify a spec somehow. |
|
Construct a pandas agent from an LLM and dataframe. |
Construct a Power BI agent from an LLM and tools. |
|
|
Construct a Power BI agent from a Chat LLM and tools. |
Construct a python agent from an LLM and tool. |
|
|
Construct a Spark agent from an LLM and dataframe. |
|
Construct a Spark SQL agent from an LLM and tools. |
Construct an SQL agent from an LLM and tools. |
|
|
Construct a VectorStore agent from an LLM and tools. |
|
Construct a VectorStore router agent from an LLM and tools. |
|
Construct a xorbits agent from an LLM and dataframe. |
|
Load an agent executor given tools and LLM. |
Get a list of all possible tool names. |
|
Loads a tool from the HuggingFace Hub. |
|
|
Load tools based on their name. |
|
Unified method for loading an agent from LangChainHub or local fs. |
Load agent from Config Dict. |
|
Validate tools for single input. |
langchain.cache¶
Warning
Beta Feature!
Cache provides an optional caching layer for LLMs.
Cache is useful for two reasons:
It can save you money by reducing the number of API calls you make to the LLM provider if you’re often requesting the same completion multiple times.
It can speed up your application by reducing the number of API calls you make to the LLM provider.
Cache directly competes with Memory. See documentation for Pros and Cons.
Class hierarchy:
BaseCache --> <name>Cache # Examples: InMemoryCache, RedisCache, GPTCache
Classes¶
Base interface for cache. |
|
|
SQLite table for full LLM Cache (all generations). |
|
Cache that uses GPTCache as a backend. |
Cache that stores things in memory. |
|
|
Cache that uses Momento as a backend. |
|
Cache that uses Redis as a backend. |
|
Cache that uses Redis as a vector-store backend. |
|
Cache that uses SQAlchemy as a backend. |
|
Cache that uses SQLite as a backend. |
langchain.callbacks¶
Callback handlers allow listening to events in LangChain.
Class hierarchy:
BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler
Classes¶
Callback Handler that logs to Aim. |
|
Callback Handler that logs into Argilla. |
|
Callback Handler that logs to Arize. |
|
Callback Handler that logs to Arthur platform. |
|
Async callback handler that can be used to handle callbacks from langchain. |
|
Base callback handler that can be used to handle callbacks from langchain. |
|
|
Base callback manager that handles callbacks from LangChain. |
Callback Handler that logs to ClearML. |
|
Callback Handler that logs to Comet. |
|
Callback Handler that records transcripts to the Context service. |
|
|
Callback Handler that writes to a file. |
This callback handler that is used within a Flyte task. |
|
Callback for manually validating values. |
|
Exception to raise when a person manually review and rejects a value. |
|
Callback Handler that logs to Infino. |
|
|
Async callback manager that handles callbacks from LangChain. |
Async callback manager for chain run. |
|
Async callback manager for LLM run. |
|
|
Async callback manager for retriever run. |
Async callback manager for tool run. |
|
Async Parent Run Manager. |
|
|
Async Run Manager. |
|
Base class for run manager (a bound callback manager). |
|
Callback manager that handles callbacks from langchain. |
Callback manager for chain run. |
|
Callback manager for LLM run. |
|
Callback manager for retriever run. |
|
Callback manager for tool run. |
|
|
Sync Parent Run Manager. |
|
Sync Run Manager. |
Callback Handler that logs metrics and artifacts to mlflow server. |
|
Callback Handler that tracks OpenAI info. |
|
|
Callback handler for promptlayer. |
Callback Handler that logs prompt artifacts and metrics to SageMaker Experiments. |
|
Callback Handler that prints to std out. |
|
Callback handler that returns an async iterator. |
|
|
Callback handler that returns an async iterator. |
Callback handler for streaming. |
|
|
Callback handler for streaming in agents. |
The child record as a NamedTuple. |
|
The enumerator of the child type. |
|
|
Enumerator of the LLMThought state. |
|
A callback handler that writes to a Streamlit app. |
|
The tool record as a NamedTuple. |
|
Base interface for tracers. |
Base class for exceptions in tracers module. |
|
A tracer that runs a run evaluator whenever a run is persisted. |
|
An implementation of the SharedTracer that POSTS to the langchain endpoint. |
|
An implementation of the SharedTracer that POSTS to the langchain endpoint. |
|
|
A tracer that collects all nested runs in a list. |
Base class for Run. |
|
Class for ChainRun. |
|
Class for LLMRun. |
|
Run schema for the V2 API in the Tracer. |
|
Class for ToolRun. |
|
TracerSessionV1 schema for the V2 API. |
|
Base class for TracerSession. |
|
TracerSessionV1 schema. |
|
Base class for TracerSessionV1. |
|
Create class for TracerSessionV1. |
|
Tracer that prints to the console. |
|
Tracer that calls a function with a single str parameter. |
|
Arguments for the WandbTracer. |
|
|
Callback Handler that logs to Weights and Biases. |
Callback Handler that logs to Weights and Biases. |
|
Callback Handler for logging to WhyLabs. |
Functions¶
Import the aim python package and raise an error if it is not installed. |
|
Import the clearml python package and raise an error if it is not installed. |
|
Import comet_ml and raise an error if it is not installed. |
|
Import the getcontext package. |
|
Analyze text using textstat and spacy. |
|
Import flytekit and flytekitplugins-deck-standard. |
|
Import the infino client. |
|
Get an async callback manager for a chain group in a context manager. |
|
|
Check if an environment variable is set. |
Get the OpenAI callback handler in a context manager. |
|
Get a callback manager for a chain group in a context manager. |
|
|
Get the Deprecated LangChainTracer in a context manager. |
Instruct LangChain to log all runs in context to LangSmith. |
|
Get the WandbTracer in a context manager. |
|
Analyze text using textstat and spacy. |
|
|
Construct an html element from a prompt and a generation. |
Import the mlflow python package and raise an error if it is not installed. |
|
Get the cost in USD for a given model and number of tokens. |
|
Standardize the model name to a format that can be used in the OpenAI API. |
|
|
Save dict to local file path. |
Callback Handler that writes to a Streamlit app. |
|
Wait for all tracers to finish. |
|
Log an error once. |
|
Wait for all tracers to finish. |
|
Get the headers for the LangChain API. |
|
RunTypeEnum. |
|
Get the elapsed time of a run. |
|
Try to stringify an object to JSON. |
|
|
Flattens a nested dictionary into a flat dictionary. |
Hash a string using sha1. |
|
Import the pandas python package and raise an error if it is not installed. |
|
Import the spacy python package and raise an error if it is not installed. |
|
Import the textstat python package and raise an error if it is not installed. |
|
|
Load json file to a string. |
Analyze text using textstat and spacy. |
|
|
Construct an html element from a prompt and a generation. |
Import the wandb python package and raise an error if it is not installed. |
|
Load json file to a dictionary. |
|
Import the langkit python package and raise an error if it is not installed. |
langchain.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¶
Chain that makes API calls and summarizes the responses to answer a question. |
|
Chain interacts with an OpenAPI endpoint using natural language. |
|
Get the request parser. |
|
Parse the request and error tags. |
|
Get the response parser. |
|
Parse the response and error tags. |
|
Abstract base class for creating structured sequences of calls to components. |
|
Chain that splits documents, then analyzes it in pieces. |
|
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. |
|
Chain that combines documents by stuffing into context. |
|
Chain for applying constitutional principles. |
|
Class for a constitutional principle. |
|
Chain to have a conversation and load context from memory. |
|
|
Chain for chatting with an index. |
Chain for chatting with a vector database. |
|
|
Chain for having a conversation based on retrieved documents. |
|
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. |
|
Chain for question-answering against a graph by generating AQL statements. |
|
Chain for question-answering against a graph. |
|
Chain for question-answering against a graph by generating Cypher statements. |
|
Chain for question-answering against a graph by generating gremlin statements. |
|
Chain for question-answering against a graph by generating Cypher statements for Kùzu. |
|
Chain for question-answering against a graph by generating nGQL statements. |
|
Chain for question-answering against a Neptune graph by generating openCypher statements. |
|
Chain for question-answering against an RDF or OWL graph by generating SPARQL statements. |
|
Generate hypothetical document for query, and then embed that. |
|
Chain to run queries against LLMs. |
|
Chain that interprets a prompt and executes bash operations. |
|
Parser for bash output. |
|
Chain for question-answering with self-verification. |
|
Chain that interprets a prompt and executes python code to do math. |
|
Chain that requests a URL and then uses an LLM to parse results. |
|
|
Chain for question-answering with self-verification. |
Chain that interprets a prompt and executes python code to do symbolic math. |
|
Map-reduce chain. |
|
Pass input through a moderation endpoint. |
|
Implement an LLM driven browser. |
|
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. |
|
Base class for question-answer generation chains. |
|
Question answering chain with sources over documents. |
|
Question answering with sources over documents. |
|
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. |
|
Enumerator of the comparison operators. |
|
A comparison to a value. |
|
Base class for all expressions. |
|
A filtering expression. |
|
A logical operation over other directives. |
|
Enumerator of the operations. |
|
A structured query. |
|
Defines interface for IR translation using visitor pattern. |
|
Information about a data source attribute. |
|
Interface for loading the combine documents chain. |
|
Base class for question-answering chains. |
|
Chain for question-answering against an index. |
|
Chain for question-answering against a vector database. |
|
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. |
|
A router chain that uses an LLM chain to perform routing. |
|
Parser for output of router chain int he multi-prompt chain. |
|
A multi-route chain that uses an LLM router chain to choose amongst prompts. |
|
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¶
Return another example given a list of examples for a prompt. |
|
Extract Cypher code from a text. |
|
Extract Cypher code from text using Regex. |
|
|
Unified method for loading a chain from LangChainHub or local fs. |
Load chain from Config Dict. |
|
|
Convert a Python function to an OpenAI function-calling API compatible dict. |
|
Convert a raw function/class to an OpenAI function. |
Create an LLM chain that uses OpenAI functions. |
|
|
Create an LLMChain that uses an OpenAI function to get a structured output. |
|
Create a citation fuzzy match chain. |
|
Creates a chain that extracts information from a passage. |
|
Creates a chain that extracts information from a passage using pydantic schema. |
Create a chain for querying an API from a OpenAPI spec. |
|
|
Convert a valid OpenAPI spec to the JSON Schema format expected for OpenAI |
|
Create a question answering chain that returns an answer with sources. |
|
Create a question answering chain that returns an answer with sources |
Creates a chain that extracts information from a passage |
|
|
Creates a chain that extracts information from a passage |
Returns the kwargs for the LLMChain constructor. |
|
Check if the language model is a chat model. |
|
Check if the language model is a LLM. |
|
|
Load a question answering with sources chain. |
|
Load a query constructor chain. |
Returns a parser for the query language. |
|
Load question answering chain. |
|
Create a chain that generates SQL queries. |
|
Load summarizing chain. |
langchain.chat_models¶
Chat Models are a variation on language models.
While Chat Models use language models under the hood, the interface they expose is a bit different. Rather than expose a “text in, text out” API, they expose an interface where “chat messages” are the inputs and outputs.
Class hierarchy:
BaseLanguageModel --> BaseChatModel --> <name> # Examples: ChatOpenAI, ChatGooglePalm
Main helpers:
AIMessage, BaseMessage, HumanMessage
Classes¶
Anthropic's large language chat model. |
|
Wrapper around Azure OpenAI Chat Completion API. |
|
Azure ML Chat Online Endpoint models. |
|
Content formatter for LLaMa |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Simple Chat Model. |
|
Fake ChatModel for testing purposes. |
|
Wrapper around Google's PaLM Chat API. |
|
Error raised when there is an issue with the Google PaLM API. |
|
ChatModel which returns user input as the response. |
|
Wrapper for Jina AI's LLM service, providing cost-effective image chat capabilities. |
|
Wrapper around chat LLMs in the MLflow AI Gateway. |
|
Parameters for the MLflow AI Gateway LLM. |
|
Wrapper around OpenAI Chat large language models. |
|
Wrapper around OpenAI Chat large language models and PromptLayer. |
|
Wrapper around Vertex AI large language models. |
Functions¶
Use tenacity to retry the async completion call. |
|
|
Use tenacity to retry the completion call. |
Use tenacity to retry the async completion call. |
|
Use tenacity to retry the async completion call. |
|
Convert dictionaries representing OpenAI messages to LangChain format. |
langchain.docstore¶
Docstores are classes to store and load Documents.
The Docstore is a simplified version of the Document Loader.
Class hierarchy:
Docstore --> <name> # Examples: InMemoryDocstore, Wikipedia
Main helpers:
Document, AddableMixin
Classes¶
|
Langchain Docstore via arbitrary lookup function. |
Mixin class that supports adding texts. |
|
Interface to access to place that stores documents. |
|
|
Simple in memory docstore in the form of a dict. |
Wrapper around wikipedia API. |
langchain.document_loaders¶
Document Loaders are classes to load Documents.
Document Loaders are usually used to load a lot of Documents in a single run.
Class hierarchy:
BaseLoader --> <name>Loader # Examples: TextLoader, UnstructuredFileLoader
Main helpers:
Document, <name>TextSplitter
Classes¶
|
Loader that loads acreom vault from a directory. |
Loads local airbyte json files. |
|
Loader for Airtable tables. |
|
Loads datasets from Apify-a web scraping, crawling, and data extraction platform. |
|
|
Loads a query result from arxiv.org into a list of Documents. |
Loads HTML asynchronously. |
|
Loads AZLyrics webpages. |
|
|
Loading Documents from Azure Blob Storage. |
|
Loading Documents from Azure Blob Storage. |
Abstract interface for blob parsers. |
|
Interface for loading Documents. |
|
|
Loads a bibtex file into a list of Documents. |
Loads a query result from BigQuery into a list of documents. |
|
Loads bilibili transcripts. |
|
Loads all documents from a Blackboard course. |
|
|
Blob loader for the local file system. |
A blob is used to represent raw data by either reference or value. |
|
Abstract interface for blob loaders implementation. |
|
|
Load YouTube urls as audio file(s). |
Loads elements from a blockchain smart contract into Langchain documents. |
|
Enumerator of the supported blockchains. |
|
Loads a query result from Brave Search engine into a list of Documents. |
|
Loads the content of webpages using Browserless' /content endpoint |
|
|
Load conversations from exported ChatGPT data. |
|
Loads College Confidential webpages. |
A generic document loader that loads and parses documents concurrently. |
|
Load Confluence pages. |
|
Enumerator of the content formats of Confluence page. |
|
|
Load CoNLL-U files. |
|
Loads a CSV file into a list of documents. |
Loader that uses unstructured to load CSV files. |
|
Load Cube semantic layer metadata. |
|
Loads a query result from Datadog into a list of documents. |
|
Load Pandas DataFrame. |
|
Loads Diffbot file json. |
|
Load documents from a directory. |
|
Load Discord chat logs. |
|
Loads processed docs from Docugami. |
|
Loads files from Dropbox. |
|
Loads a query result from DuckDB into a list of documents. |
|
Loads Outlook Message files using extract_msg. |
|
Loader that uses unstructured to load email files. |
|
Base class for embedding a model into an Embaas document extraction API. |
|
Embaas's document byte loader. |
|
Parameters for the embaas document extraction API. |
|
Payload for the Embaas document extraction API. |
|
Embaas's document loader. |
|
Loader that uses Unstructured to load EPUB files. |
|
Load transactions from an account on Ethereum mainnet. |
|
EverNote Loader. |
|
Loader that uses unstructured to load Excel files. |
|
Loads Facebook messages json directory dump. |
|
|
FaunaDB Loader. |
Loads Figma file json. |
|
Loads Documents from GCS. |
|
Load Documents from a GCS file. |
|
A generic document loader. |
|
Load geopandas Dataframe. |
|
|
Loads files from a Git repository into a list of documents. |
|
Load GitBook data. |
Load issues of a GitHub repository. |
|
Load issues of a GitHub repository. |
|
Loads Google Docs from Google Drive. |
|
Loader that uses urllib to load .txt web files. |
|
A file encoding as the NamedTuple. |
|
|
Load Hacker News data from either main page results or the comments page. |
Loader that uses Unstructured to load HTML files. |
|
|
Loader that uses beautiful soup to parse HTML files. |
|
Load Documents from the Hugging Face Hub. |
|
Load iFixit repair guides, device wikis and answers. |
Loader that uses Unstructured to load PNG and JPG files. |
|
Loads the captions of an image |
|
|
Loads IMSDb webpages. |
|
Loader that fetches data from IUGU. |
Loader that fetches notes from Joplin. |
|
Loads a JSON file using a jq schema. |
|
Loads LarkSuite (FeiShu) document. |
|
Loader that uses Unstructured to load markdown files. |
|
Mastodon toots loader. |
|
Loads a query result from Alibaba Cloud MaxCompute table into documents. |
|
Load MediaWiki dump from XML file . |
|
Merge documents from a list of loaders |
|
|
Loader that uses beautiful soup to parse HTML files. |
Loader that fetches data from Modern Treasury. |
|
Loads .ipynb notebook files. |
|
Loads Notion directory dump. |
|
Notion DB Loader. |
|
Loading logic for loading documents from Huawei OBS. |
|
Loader for Huawei OBS file. |
|
Loads Obsidian files from disk. |
|
Loader that uses unstructured to load OpenOffice ODT files. |
|
Loads data from OneDrive. |
|
Loads a file from OneDrive. |
|
Loads Open City data. |
|
Loader that uses unstructured to load Org-Mode files. |
|
Transcribe and parse audio files. |
|
A parser that uses mime-types to determine how to parse a blob. |
|
Loader that uses Grobid to load article PDF files. |
|
Exception raised when the GROBID server is unavailable. |
|
Parser that uses beautiful soup to parse HTML files. |
|
|
The abstract class for the code segmenter. |
|
The code segmenter for JavaScript. |
|
Language parser that split code using the respective language syntax. |
|
The code segmenter for Python. |
Parse PDFs with PDFMiner. |
|
Parse PDFs with PDFPlumber. |
|
Parse PDFs with PyMuPDF. |
|
Loads a PDF with pypdf and chunks at character level. |
|
Parse PDFs with PyPDFium2. |
|
Parser for text blobs. |
|
|
Base loader class for PDF files. |
|
This class uses Mathpix service to load PDF files. |
|
Loads online PDFs. |
|
Loader that uses PDFMiner to load PDF files. |
Loader that uses PDFMiner to load PDF files as HTML content. |
|
|
Loader that uses pdfplumber to load PDF files. |
|
Loader that uses PyMuPDF to load PDF files. |
Loads a directory with PDF files with pypdf and chunks at character level. |
|
|
Loads a PDF with pypdf and chunks at character level. |
|
Loads a PDF with pypdfium2 and chunks at character level. |
Loader that uses unstructured to load PDF files. |
|
|
Loader that uses unstructured to load PowerPoint files. |
Loads documents from Psychic.dev. |
|
|
Load PySpark DataFrames |
|
Load Python files, respecting any non-default encoding if specified. |
Loads ReadTheDocs documentation directory dump. |
|
|
Loads all child links from a given url. |
Reddit posts loader. |
|
Loads Roam files from disk. |
|
Column not found error. |
|
Wrapper around Rockset db |
|
Loader that uses unstructured to load RST files. |
|
Loader that uses unstructured to load RTF files. |
|
Loading logic for loading documents from an AWS S3. |
|
Loading logic for loading documents from an AWS S3 file. |
|
|
Loader that fetches a sitemap and loads those URLs. |
Loads documents from a Slack directory dump. |
|
Loads a query result from Snowflake into a list of documents. |
|
Loader that fetches data from Spreedly API. |
|
|
Loader for .srt (subtitle) files. |
|
Loader that fetches data from Stripe. |
Loads Telegram chat json directory dump. |
|
Loads Telegram chat json directory dump. |
|
|
Loader for Tencent Cloud COS directory. |
Loader for Tencent Cloud COS file. |
|
|
Load text files. |
Loads HTML to markdown using 2markdown. |
|
|
A TOML document loader that inherits from the BaseLoader class. |
|
Trello loader. |
Loader that uses unstructured to load TSV files. |
|
Twitter tweets loader. |
|
|
Loader that uses the Unstructured API to load files. |
|
Loader that uses the Unstructured API to load files. |
Loader that uses Unstructured to load files. |
|
|
Loader that uses Unstructured to load files. |
Loader that uses Unstructured to load files. |
|
Loader that use Unstructured to load files from remote URLs. |
|
Loader that uses Playwright and to load a page and unstructured to load the html. |
|
Loader that uses Selenium and to load a page and unstructured to load the html. |
|
Weather Reader. |
|
|
Loader that uses urllib and beautiful soup to load webpages. |
Loads WhatsApp messages text file. |
|
Loads a query result from www.wikipedia.org into a list of Documents. |
|
Loads a DOCX with docx2txt and chunks at character level. |
|
|
Loader that uses unstructured to load word documents. |
Loader that uses unstructured to load XML files. |
|
Load Xorbits DataFrame. |
|
Loads all Videos from a Channel |
|
|
Loads Youtube transcripts. |
Functions¶
Combine message information in a readable format ready to be used. |
|
Combine message information in a readable format ready to be used. |
|
Try to detect the file encoding. |
|
Combine cells information in a readable format ready to be used. |
|
Recursively removes newlines, no matter the data structure they are stored in. |
|
Get a parser by parser name. |
|
Default joiner for content columns. |
|
Combine message information in a readable format ready to be used. |
|
Converts a string or list of strings to a list of Documents with metadata. |
|
Retrieves a list of elements from the Unstructured API. |
|
|
Checks to see if the installed unstructured version exceeds the minimum version for the feature in question. |
|
Raises an error if the unstructured version does not exceed the specified minimum. |
Combine message information in a readable format ready to be used. |
langchain.document_transformers¶
Document Transformers are classes to transform Documents.
Document Transformers usually used to transform a lot of Documents in a single run.
Class hierarchy:
BaseDocumentTransformer --> <name> # Examples: DoctranQATransformer, DoctranTextTranslator
Main helpers:
Document
Classes¶
|
Extract properties from text documents using doctran. |
|
Extract QA from text documents using doctran. |
|
Translate text documents using doctran. |
|
Perform K-means clustering on document vectors. |
|
Filter that drops redundant documents by comparing their embeddings. |
Replace occurrences of a particular search pattern with a replacement string . |
|
|
Lost in the middle: Performance degrades when models must access relevant information in the middle of long contexts. |
Extract metadata tags from document contents using OpenAI functions. |
Functions¶
|
Convert a list of documents to a list of documents with state. |
|
Create a DocumentTransformer that uses an OpenAI function chain to automatically |
langchain.embeddings¶
Embedding models are wrappers around embedding models from different APIs and services.
Embedding models can be LLMs or not.
Class hierarchy:
Embeddings --> <name>Embeddings # Examples: OpenAIEmbeddings, HuggingFaceEmbeddings
Classes¶
|
Aleph Alpha's asymmetric semantic embedding. |
The symmetric version of the Aleph Alpha's semantic embeddings. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Interface for embedding models. |
|
Bedrock embedding models. |
|
Clarifai embedding models. |
|
Cohere embedding models. |
|
DashScope embedding models. |
|
Deep Infra's embedding inference service. |
|
Elasticsearch embedding models. |
|
Embaas's embedding service. |
|
Payload for the embaas embeddings API. |
|
Fake embedding model. |
|
Google's PaLM Embeddings APIs. |
|
GPT4All embedding models. |
|
HuggingFace sentence_transformers embedding models. |
|
Wrapper around sentence_transformers embedding models. |
|
HuggingFaceHub embedding models. |
|
Jina embedding models. |
|
llama.cpp embedding models. |
|
LocalAI embedding models. |
|
MiniMax's embedding service. |
|
Wrapper around embeddings LLMs in the MLflow AI Gateway. |
|
ModelScopeHub embedding models. |
|
MosaicML embedding service. |
|
NLP Cloud embedding models. |
|
OctoAI Compute Service embedding models. |
|
OpenAI embedding models. |
|
Content handler for LLM class. |
|
Custom Sagemaker Inference Endpoints. |
|
Custom embedding models on self-hosted remote hardware. |
|
|
HuggingFace embedding models on self-hosted remote hardware. |
|
HuggingFace InstructEmbedding models on self-hosted remote hardware. |
Embeddings by SpaCy models. |
|
TensorflowHub embedding models. |
|
Google Cloud VertexAI embedding models. |
|
Wrapper around xinference embedding models. |
Functions¶
Use tenacity to retry the embedding call. |
|
Use tenacity to retry the completion call. |
|
Use tenacity to retry the embedding call. |
|
Use tenacity to retry the embedding call. |
|
Use tenacity to retry the completion call. |
|
Use tenacity to retry the embedding call. |
|
Use tenacity to retry the embedding call. |
|
|
Load the embedding model. |
langchain.env¶
Functions¶
Get information about the LangChain runtime environment. |
langchain.evaluation¶
Evaluation chains for grading LLM and Chain outputs.
This module contains off-the-shelf evaluation chains for grading the output of LangChain primitives such as language models and chains.
Loading an evaluator
To load an evaluator, you can use the load_evaluators or
load_evaluator functions with the
names of the evaluators to load.
from langchain.evaluation import load_evaluator
evaluator = load_evaluator("qa")
evaluator.evaluate_strings(
prediction="We sold more than 40,000 units last week",
input="How many units did we sell last week?",
reference="We sold 32,378 units",
)
The evaluator must be one of EvaluatorType.
Datasets
To load one of the LangChain HuggingFace datasets, you can use the load_dataset function with the
name of the dataset to load.
from langchain.evaluation import load_dataset
ds = load_dataset("llm-math")
Some common use cases for evaluation include:
Grading the accuracy of a response against ground truth answers:
QAEvalChainComparing the output of two models:
PairwiseStringEvalChainorLabeledPairwiseStringEvalChainwhen there is additionally a reference label.Judging the efficacy of an agent’s tool usage:
TrajectoryEvalChainChecking whether an output complies with a set of criteria:
CriteriaEvalChainorLabeledCriteriaEvalChainwhen there is additionally a reference label.Computing semantic difference between a prediction and reference:
EmbeddingDistanceEvalChainor between two predictions:PairwiseEmbeddingDistanceEvalChainMeasuring the string distance between a prediction and reference
StringDistanceEvalChainor between two predictionsPairwiseStringDistanceEvalChain
Low-level API
These evaluators implement one of the following interfaces:
StringEvaluator: Evaluate a prediction string against a reference label and/or input context.PairwiseStringEvaluator: Evaluate two prediction strings against each other. Useful for scoring preferences, measuring similarity between two chain or llm agents, or comparing outputs on similar inputs.AgentTrajectoryEvaluatorEvaluate the full sequence of actions taken by an agent.
These interfaces enable easier composability and usage within a higher level evaluation framework.
Classes¶
A named tuple containing the score and reasoning for a trajectory. |
|
A chain for evaluating ReAct style agents. |
|
|
Trajectory output parser. |
|
A chain for comparing two outputs, such as the outputs |
A chain for comparing two outputs, such as the outputs |
|
|
A parser for the output of the PairwiseStringEvalChain. |
A Criteria to evaluate. |
|
LLM Chain for evaluating runs against criteria. |
|
A parser for the output of the CriteriaEvalChain. |
|
Criteria evaluation chain that requires references. |
|
Embedding Distance Metric. |
|
|
Use embedding distances to score semantic difference between a prediction and reference. |
|
Use embedding distances to score semantic difference between two predictions. |
LLM Chain for evaluating QA w/o GT based on context |
|
LLM Chain for evaluating QA using chain of thought reasoning. |
|
LLM Chain for evaluating question answering. |
|
LLM Chain for generating examples for question answering. |
|
Interface for evaluating agent trajectories. |
|
|
The types of the evaluators. |
A base class for evaluators that use an LLM. |
|
Compare the output of two models (or two outputs of the same model). |
|
Grade, tag, or otherwise evaluate predictions relative to their inputs and/or reference labels. |
|
|
Compute string edit distances between two predictions. |
Distance metric to use. |
|
Compute string distances between the prediction and the reference. |
Functions¶
|
Resolve the criteria for the pairwise evaluator. |
Resolve the criteria to evaluate. |
|
Load a dataset from the LangChainDatasets HuggingFace org. |
|
|
Load the requested evaluation chain specified by a string. |
|
Load evaluators specified by a list of evaluator types. |
langchain.graphs¶
Graphs provide a natural language interface to graph databases.
Classes¶
|
Memgraph wrapper for graph operations. |
A class to handle queries that fail to execute |
|
A triple in the graph. |
Functions¶
Get the Arango DB client from credentials. |
|
|
Extract entities from entity string. |
Parse knowledge triples from the knowledge string. |
langchain.indexes¶
Index utilities.
Classes¶
Functionality to create graph index. |
|
Wrapper around a vectorstore for easy access. |
|
Logic for creating indexes. |
langchain.llms¶
LLM classes provide access to the large language model (LLM) APIs and services.
Class hierarchy:
BaseLanguageModel --> BaseLLM --> LLM --> <name> # Examples: AI21, HuggingFaceHub, OpenAI
Main helpers:
LLMResult, PromptValue,
CallbackManagerForLLMRun, AsyncCallbackManagerForLLMRun,
CallbackManager, AsyncCallbackManager,
AIMessage, BaseMessage
Classes¶
AI21 large language models. |
|
Parameters for AI21 penalty data. |
|
Aleph Alpha large language models. |
|
Amazon API Gateway to access LLM models hosted on AWS. |
|
Anthropic large language models. |
|
Anyscale Service models. |
|
Aviary hosted models. |
|
AzureML Managed Endpoint client. |
|
Azure ML Online Endpoint models. |
|
Content handler for the Dolly-v2-12b model |
|
Content handler for GPT2 |
|
Content handler for LLMs from the HuggingFace catalog. |
|
Content formatter for LLaMa |
|
Deprecated: Kept for backwards compatibility |
|
Banana large language models. |
|
Base LLM abstract interface. |
|
Base LLM abstract class. |
|
Baseten models. |
|
Beam API for gpt2 large language model. |
|
Bedrock models. |
|
CerebriumAI large language models. |
|
ChatGLM LLM service. |
|
Clarifai large language models. |
|
Cohere large language models. |
|
C Transformers LLM models. |
|
Databricks serving endpoint or a cluster driver proxy app for LLM. |
|
DeepInfra models. |
|
Fake LLM for testing purposes. |
|
ForefrontAI large language models. |
|
Google PaLM models. |
|
GooseAI large language models. |
|
GPT4All language models. |
|
HuggingFace Endpoint models. |
|
HuggingFaceHub models. |
|
HuggingFace Pipeline API. |
|
|
HuggingFace text generation API. |
It returns user input as the response. |
|
Kobold API language model. |
|
llama.cpp model. |
|
HazyResearch's Manifest library. |
|
Wrapper around Minimax large language models. |
|
Wrapper around completions LLMs in the MLflow AI Gateway. |
|
Parameters for the MLflow AI Gateway LLM. |
|
Modal large language models. |
|
MosaicML LLM service. |
|
NLPCloud large language models. |
|
OctoAI LLM Endpoints. |
|
Azure-specific OpenAI large language models. |
|
Base OpenAI large language model class. |
|
OpenAI large language models. |
|
OpenAI Chat large language models. |
|
Parameters for identifying a model as a typed dict. |
|
OpenLLM, supporting both in-process model instance and remote OpenLLM servers. |
|
OpenLM models. |
|
Petals Bloom models. |
|
PipelineAI large language models. |
|
Use your Predibase models with Langchain. |
|
Prediction Guard large language models. |
|
PromptLayer OpenAI large language models. |
|
Wrapper around OpenAI large language models. |
|
Replicate models. |
|
RWKV language models. |
|
A handler class to transform input from LLM to a format that SageMaker endpoint expects. |
|
Content handler for LLM class. |
|
Sagemaker Inference Endpoint models. |
|
Model inference on self-hosted remote hardware. |
|
HuggingFace Pipeline API to run on self-hosted remote hardware. |
|
StochasticAI large language models. |
|
text-generation-webui models. |
|
Tongyi Qwen large language models. |
|
Google Vertex AI large language models. |
|
Writer large language models. |
|
Wrapper for accessing Xinference's large-scale model inference service. |
Functions¶
|
Get completions from Aviary models. |
List available models |
|
|
Create a retry decorator for a given LLM and provided list of error types. |
|
Get prompts that are already cached. |
|
Update the cache and get the LLM output. |
|
Use tenacity to retry the completion call. |
|
Use tenacity to retry the completion call. |
Gets the default Databricks personal access token. |
|
Gets the default Databricks workspace hostname. |
|
Gets the notebook REPL context if running inside a Databricks notebook. |
|
|
Use tenacity to retry the completion call. |
Remove trailing slash and /api from url if present. |
|
|
Load LLM from file. |
Load LLM from Config Dict. |
|
|
Use tenacity to retry the async completion call. |
|
Use tenacity to retry the completion call. |
|
Update token usage. |
|
Use tenacity to retry the completion call. |
|
Use tenacity to retry the completion call. |
|
Cut off the text as soon as any stop words occur. |
|
Use tenacity to retry the completion call. |
|
Returns True if the model name is a Codey model. |
langchain.load¶
Serialization and deserialization.
Classes¶
Base class for serialized objects. |
|
Serializable base class. |
|
Serialized constructor. |
|
Serialized not implemented. |
|
Serialized secret. |
Functions¶
|
Return a default value for a Serializable object or a SerializedNotImplemented object. |
|
Return a json dict representation of an object. |
|
Return a json string representation of an object. |
|
Load a JSON object from a string. |
Serialize a "not implemented" object. |
langchain.memory¶
Memory maintains Chain state, incorporating context from past runs.
Class hierarchy for Memory:
BaseMemory --> BaseChatMemory --> <name>Memory # Examples: ZepMemory, MotorheadMemory
Main helpers:
BaseChatMessageHistory
Chat Message History stores the chat message history in different stores.
Class hierarchy for ChatMessageHistory:
BaseChatMessageHistory --> <name>ChatMessageHistory # Example: ZepChatMessageHistory
Main helpers:
AIMessage, BaseMessage, HumanMessage
Classes¶
Buffer for storing conversation memory. |
|
Buffer for storing conversation memory. |
|
Buffer for storing conversation memory inside a limited size window. |
|
Abstract base class for chat memory. |
|
|
Chat message history that stores history in Cassandra. |
|
Chat message history backed by Azure CosmosDB. |
|
Chat message history that stores history in AWS DynamoDB. |
|
Chat message history that stores history in a local file. |
|
Chat message history backed by Google Firestore. |
In memory implementation of chat message history. |
|
|
Chat message history cache that uses Momento as a backend. |
|
Chat message history that stores history in MongoDB. |
|
Chat message history stored in a Postgres database. |
|
Chat message history stored in a Redis database. |
|
Chat message history stored in an SQL database. |
|
Chat message history that stores messages in Streamlit session state. |
|
Chat message history that uses Zep as a backend. |
Combining multiple memories' data together. |
|
Abstract base class for Entity store. |
|
Entity extractor & summarizer memory. |
|
In-memory Entity store. |
|
Redis-backed Entity store. |
|
SQLite-backed Entity store |
|
Knowledge graph conversation memory. |
|
Chat message memory backed by Motorhead service. |
|
A memory wrapper that is read-only and cannot be changed. |
|
Simple memory for storing context or other information that shouldn't ever change between prompts. |
|
Conversation summarizer to chat memory. |
|
Mixin for summarizer. |
|
Buffer with summarizer for storing conversation memory. |
|
Conversation chat memory with token limit. |
|
VectorStoreRetriever-backed memory. |
|
Persist your chain history to the Zep Memory Server. |
Functions¶
Create a message model for a given table name. |
|
|
Get the prompt input key. |
langchain.output_parsers¶
OutputParser classes parse the output of an LLM call.
Class hierarchy:
BaseLLMOutputParser --> BaseOutputParser --> <name>OutputParser # ListOutputParser, PydanticOutputParser
Main helpers:
Serializable, Generation, PromptValue
Classes¶
Parse the output of an LLM call to a boolean. |
|
Combine multiple output parsers into one. |
|
Parse the output of an LLM call to a datetime. |
|
Parse an output that is one of a set of values. |
|
Wraps a parser and tries to fix parsing errors. |
|
Parse the output of an LLM call to a JSON object. |
|
Parse the output of an LLM call to a comma-separated list. |
|
Parse the output of an LLM call to a list. |
|
|
Parse an output as the element of the Json object. |
Parse an output as the Json object. |
|
Parse an output that is one of sets of values. |
|
|
Parse an output as an attribute of a pydantic object. |
|
Parse an output as a pydantic object. |
Parse an output using a pydantic model. |
|
Parse the output of an LLM call using Guardrails. |
|
Parse the output of an LLM call using a regex. |
|
Parse the output of an LLM call into a Dictionary using a regex. |
|
Wraps a parser and tries to fix parsing errors. |
|
Wraps a parser and tries to fix parsing errors. |
|
A schema for a response from a structured output parser. |
|
Parse the output of an LLM call to a structured output. |
Functions¶
Parse a JSON string from a Markdown string and check that it contains the expected keys. |
|
Parse a JSON string from a Markdown string. |
|
Load an output parser. |
langchain.prompts¶
Prompt is the input to the model.
Prompt is often constructed from multiple components. Prompt classes and functions make constructing
and working with prompts easy.
Class hierarchy:
BasePromptTemplate --> PipelinePromptTemplate
StringPromptTemplate --> PromptTemplate
FewShotPromptTemplate
FewShotPromptWithTemplates
BaseChatPromptTemplate --> AutoGPTPrompt
ChatPromptTemplate --> AgentScratchPadChatPromptTemplate
BaseMessagePromptTemplate --> MessagesPlaceholder
BaseStringMessagePromptTemplate --> ChatMessagePromptTemplate
HumanMessagePromptTemplate
AIMessagePromptTemplate
SystemMessagePromptTemplate
PromptValue --> StringPromptValue
ChatPromptValue
Classes¶
String prompt that exposes the format method, returning a prompt. |
|
String prompt value. |
|
AI message prompt template. |
|
Base class for chat prompt templates. |
|
Base class for message prompt templates. |
|
Base class for message prompt templates that use a string prompt template. |
|
Chat message prompt template. |
|
A prompt template for chat models. |
|
Chat prompt value. |
|
Human message prompt template. |
|
Prompt template that assumes variable is already list of messages. |
|
System message prompt template. |
|
Interface for selecting examples to include in prompts. |
|
|
Select examples based on length. |
|
Select and order examples based on ngram overlap score (sentence_bleu score). |
|
ExampleSelector that selects examples based on Max Marginal Relevance. |
|
Example selector that selects examples based on SemanticSimilarity. |
Chat prompt template that supports few-shot examples. |
|
Prompt template that contains few shot examples. |
|
Prompt template that contains few shot examples. |
|
A prompt template for composing multiple prompt templates together. |
|
A prompt template for a language model. |
Functions¶
|
Check that template string is valid. |
|
Format a template using jinja2. |
|
Validate that the input variables are valid for the template. |
|
Compute ngram overlap score of source and example as sentence_bleu score. |
|
Return a list of values in dict sorted by key. |
Unified method for loading a prompt from LangChainHub or local fs. |
|
Load prompt from Config Dict. |
langchain.retrievers¶
Retriever class returns Documents given a text query.
It is more general than a vector store. A retriever does not need to be able to store documents, only to return (or retrieve) it. Vector stores can be used as the backbone of a retriever, but there are other types of retrievers as well.
Class hierarchy:
BaseRetriever --> <name>Retriever # Examples: ArxivRetriever, MergerRetriever
Main helpers:
Document, Serializable, Callbacks,
CallbackManagerForRetrieverRun, AsyncCallbackManagerForRetrieverRun
Classes¶
Retriever for Arxiv. |
|
|
Retriever for the Azure Cognitive Search service. |
BM25 Retriever without elastic search. |
|
Retriever for the Chaindesk API. |
|
Retrieves documents from a ChatGPT plugin. |
|
|
Retriever that wraps a base retriever and compresses the results. |
Retriever for the Databerry API. |
|
Retriever for DocArray Document Indices. |
|
|
Enumerator of the types of search to perform. |
Base abstraction interface for document compression. |
|
|
Document compressor that uses a pipeline of transformers. |
|
DocumentCompressor that uses an LLM chain to extract the relevant parts of documents. |
|
Parse outputs that could return a null string of some sort. |
Filter that drops documents that aren't relevant to the query. |
|
DocumentCompressor that uses Cohere's rerank API to compress documents. |
|
|
Document compressor that uses embeddings to drop documents unrelated to the query. |
Retriever for the Elasticsearch using BM25 as a retrieval method. |
|
This class ensemble the results of multiple retrievers by using rank fusion. |
|
|
Retriever for the Google Cloud Enterprise Search Service API. |
An additional result attribute. |
|
The value of an additional result attribute. |
|
Retriever for the Amazon Kendra Index. |
|
A document attribute. |
|
The value of a document attribute. |
|
Represents the information that can be used to highlight key words in the excerpt. |
|
A Query API result. |
|
A Query API result item. |
|
Abstract class that represents a result item. |
|
A Retrieve API result. |
|
A Retrieve API result item. |
|
Text with highlights. |
|
KNN Retriever. |
|
Retriever for question-answering with sources over an LlamaIndex graph data structure. |
|
Retriever for the question-answering with sources over an LlamaIndex data structure. |
|
Retriever that merges the results of multiple retrievers. |
|
Retriever that uses the Metal API. |
|
Retriever that uses the Milvus API. |
|
List of lines. |
|
Output parser for a list of lines. |
|
Given a user query, use an LLM to write a set of queries. |
|
|
Pinecone Hybrid Search Retriever. |
Retriever for PubMed API. |
|
Retriever for remote LangChain API. |
|
Retriever that uses a vector store and an LLM to generate the vector store queries. |
|
Translate internal query language elements to valid filters. |
|
Logic for converting internal query language elements to valid filters. |
|
Translate internal query language elements to valid filters. |
|
Translate the internal query language elements to valid filters. |
|
Translate the internal query language elements to valid filters. |
|
Translate the internal query language elements to valid filters. |
|
SVM Retriever. |
|
TF-IDF Retriever. |
|
|
Retriever that combines embedding similarity with recency in retrieving values. |
Retriever that uses Vespa. |
|
|
Retriever for the Weaviate's hybrid search. |
List of questions. |
|
Output parser for a list of numbered questions. |
|
Search queries to run to research for the user's goal. |
|
Retriever for web research based on the Google Search API. |
|
Retriever for Wikipedia API. |
|
Retriever for the Zep long-term memory store. |
|
Retriever for the Zilliz API. |
Functions¶
|
Return the compression chain input. |
|
Return the compression chain input. |
|
Cleans an excerpt from Kendra. |
|
Combines a title and an excerpt into a single string. |
|
Create an index of embeddings for a list of contexts. |
|
Deprecated MilvusRetreiver. |
Create a Pinecone index from a list of contexts. |
|
Hash a text using SHA256. |
|
Check if a string can be cast to a float. |
|
Default composer for logical operators. |
|
Composer for functions. |
|
|
Create an index of embeddings for a list of contexts. |
|
Deprecated ZillizRetreiver. |
langchain.schema¶
Schemas are the LangChain Base Classes and Interfaces.
Classes¶
|
The final return value of an ActionAgent. |
Abstract base class for document transformation systems. |
|
Class for storing a piece of text and associated metadata. |
|
Abstract base class for interfacing with language models. |
|
Abstract base class for storing chat message history. |
|
Abstract base class for memory in Chains. |
|
A Message from an AI. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
The base abstract Message class. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
A Message that can be assigned an arbitrary speaker (i.e. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
A Message for passing the result of executing a function back to a model. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
A Message from a human. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
A Message for priming AI behavior, usually passed in as the first of a sequence of input messages. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
A single chat generation output. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Class that contains all results for a single chat model call. |
|
A single text generation output. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Class that contains all results for a batched LLM call. |
|
Class that contains metadata for a single execution of a Chain or model. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Abstract base class for parsing the outputs of a model. |
|
Base class to parse the output of an LLM call. |
|
Exception that output parsers should raise to signify a parsing error. |
|
OutputParser that parses LLMResult into the top likely string.. |
|
Base abstract class for inputs to any language model. |
|
Base class for all prompt templates, returning a prompt. |
|
Abstract base class for a Document retrieval system. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Create a new model by parsing and validating input data from keyword arguments. |
|
Create a new model by parsing and validating input data from keyword arguments. |
Functions¶
|
Convert sequence of Messages to strings and concatenate them into one string. |
|
Convert a sequence of messages from dicts to Message objects. |
|
Convert a sequence of Messages to a list of dictionaries. |
|
Format a document into a string based on a prompt template. |
langchain.server¶
Script to run langchain-server locally using docker-compose.
Functions¶
Run the langchain server locally. |
langchain.smith¶
LangSmith utilities.
This module provides utilities for connecting to LangSmith. For more information on LangSmith, see the LangSmith documentation.
Evaluation
LangSmith helps you evaluate Chains and other language model application components using a number of LangChain evaluators.
An example of this is shown below, assuming you’ve created a LangSmith dataset called <my_dataset_name>:
from langsmith import Client
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain
from langchain.smith import RunEvalConfig, run_on_dataset
# Chains may have memory. Passing in a constructor function lets the
# evaluation framework avoid cross-contamination between runs.
def construct_chain():
llm = ChatOpenAI(temperature=0)
chain = LLMChain.from_string(
llm,
"What's the answer to {your_input_key}"
)
return chain
# Load off-the-shelf evaluators via config or the EvaluatorType (string or enum)
evaluation_config = RunEvalConfig(
evaluators=[
"qa", # "Correctness" against a reference answer
"embedding_distance",
RunEvalConfig.Criteria("helpfulness"),
RunEvalConfig.Criteria({
"fifth-grader-score": "Do you have to be smarter than a fifth grader to answer this question?"
}),
]
)
client = Client()
run_on_dataset(
client,
"<my_dataset_name>",
construct_chain,
evaluation=evaluation_config,
)
You can also create custom evaluators by subclassing the
StringEvaluator
or LangSmith’s RunEvaluator classes.
from typing import Optional
from langchain.evaluation import StringEvaluator
class MyStringEvaluator(StringEvaluator):
@property
def requires_input(self) -> bool:
return False
@property
def requires_reference(self) -> bool:
return True
@property
def evaluation_name(self) -> str:
return "exact_match"
def _evaluate_strings(self, prediction, reference=None, input=None, **kwargs) -> dict:
return {"score": prediction == reference}
evaluation_config = RunEvalConfig(
custom_evaluators = [MyStringEvaluator()],
)
run_on_dataset(
client,
"<my_dataset_name>",
construct_chain,
evaluation=evaluation_config,
)
Primary Functions
arun_on_dataset: Asynchronous function to evaluate a chain, agent, or other LangChain component over a dataset.run_on_dataset: Function to evaluate a chain, agent, or other LangChain component over a dataset.RunEvalConfig: Class representing the configuration for running evaluation. You can select evaluators byEvaluatorTypeor config, or you can pass in custom_evaluators
Classes¶
Configuration for a given run evaluator. |
|
Configuration for a run evaluation. |
|
Raised when the input format is invalid. |
|
Extract items to evaluate from the run object from a chain. |
|
Extract items to evaluate from the run object. |
|
Map an example, or row in the dataset, to the inputs of an evaluation. |
|
|
Evaluate Run and optional examples. |
Extract items to evaluate from the run object. |
|
Map an input to the tool. |
Functions¶
Asynchronously run the Chain or language model on a dataset and store traces to the specified project name. |
|
Run the Chain or language model on a dataset and store traces to the specified project name. |
langchain.text_splitter¶
Text Splitters are classes for splitting text.
Class hierarchy:
BaseDocumentTransformer --> TextSplitter --> <name>TextSplitter # Example: CharacterTextSplitter
RecursiveCharacterTextSplitter --> <name>TextSplitter
Note: MarkdownHeaderTextSplitter does not derive from TextSplitter.
Main helpers:
Document, Tokenizer, Language, LineType, HeaderType
Classes¶
|
Splitting text that looks at characters. |
Header type as typed dict. |
|
|
Enum of the programming languages. |
|
Attempts to split the text along Latex-formatted layout elements. |
Line type as typed dict. |
|
|
Attempts to split the text along Markdown-formatted headings. |
|
Splitting text using NLTK package. |
|
Attempts to split the text along Python syntax. |
Splitting text by recursively look at characters. |
|
Splitting text to tokens using sentence model tokenizer. |
|
|
Splitting text using Spacy package. |
|
Interface for splitting text into chunks. |
Splitting text to tokens using model tokenizer. |
Functions¶
|
Split incoming text and return chunks using tokenizer. |
langchain.tools¶
Tools are classes that an Agent uses to interact with the world.
Each tool has a description. Agent uses the description to choose the right tool for the job.
Class hierarchy:
ToolMetaclass --> BaseTool --> <name>Tool # Examples: AIPluginTool, BaseGraphQLTool
<name> # Examples: BraveSearch, HumanInputRun
Main helpers:
CallbackManagerForToolRun, AsyncCallbackManagerForToolRun
Classes¶
Base Tool for Amadeus. |
|
Tool for finding the closest airport to a particular location. |
|
Schema for the AmadeusClosestAirport tool. |
|
Tool for searching for a single flight between two airports. |
|
Schema for the AmadeusFlightSearch tool. |
|
Tool that searches the Arxiv API. |
|
|
Tool that queries the Azure Cognitive Services Form Recognizer API. |
|
Tool that queries the Azure Cognitive Services Image Analysis API. |
|
Tool that queries the Azure Cognitive Services Speech2Text API. |
|
Tool that queries the Azure Cognitive Services Text2Speech API. |
Interface LangChain tools must implement. |
|
Raised when 'args_schema' is missing or has an incorrect type annotation. |
|
Tool that can operate on any number of inputs. |
|
Tool that takes in function or coroutine directly. |
|
An optional exception that tool throws when execution error occurs. |
|
|
Metaclass for BaseTool to ensure the provided args_schema |
Tool that queries the Bing Search API and gets back json. |
|
Tool that queries the Bing search API. |
|
Tool that queries the BraveSearch. |
|
Representation of a callable function to the OpenAI API. |
|
Tool that queries the DataForSeo Google Search API and get back json. |
|
Tool that queries the DataForSeo Google search API. |
|
Tool that queries the DuckDuckGo search API and gets back json. |
|
Tool that queries the DuckDuckGo search API. |
|
Tool that copies a file. |
|
Input for CopyFileTool. |
|
Tool that deletes a file. |
|
Input for DeleteFileTool. |
|
Input for FileSearchTool. |
|
Tool that searches for files in a subdirectory that match a regex pattern. |
|
Input for ListDirectoryTool. |
|
Tool that lists files and directories in a specified folder. |
|
Input for MoveFileTool. |
|
Tool that moves a file. |
|
Input for ReadFileTool. |
|
Tool that reads a file. |
|
Mixin for file system tools. |
|
Error for paths outside the root directory. |
|
Input for WriteFileTool. |
|
Tool that writes a file to disk. |
|
Tool for interacting with the GitHub API. |
|
Base class for Gmail tools. |
|
Input for CreateDraftTool. |
|
Tool that creates a draft email for Gmail. |
|
Tool that gets a message by ID from Gmail. |
|
Input for GetMessageTool. |
|
Input for GetMessageTool. |
|
Tool that gets a thread by ID from Gmail. |
|
Tool that searches for messages or threads in Gmail. |
|
|
Enumerator of Resources to search. |
Input for SearchGmailTool. |
|
Tool that sends a message to Gmail. |
|
Input for SendMessageTool. |
|
Tool that adds the capability to query using the Golden API and get back JSON. |
|
Input for GooglePlacesTool. |
|
Tool that queries the Google places API. |
|
Tool that queries the Google Search API and gets back json. |
|
Tool that queries the Google search API. |
|
Tool that queries the Serper.dev Google Search API and get back json. |
|
Tool that queries the Serper.dev Google search API. |
|
Base tool for querying a GraphQL API. |
|
Tool that asks user for input. |
|
IFTTT Webhook. |
|
Tool that queries the Atlassian Jira API. |
|
Tool for getting a value in a JSON spec. |
|
Tool for listing keys in a JSON spec. |
|
Base class for JSON spec. |
|
Tool that queries the Metaphor Search API and gets back json. |
|
Simulates a Browser interacting agent. |
|
Base class for the Office 365 tools. |
|
|
Input for SendMessageTool. |
Tool for creating a draft email in Office 365. |
|
Class for searching calendar events in Office 365 |
|
Input for SearchEmails Tool. |
|
Class for searching email messages in Office 365 |
|
Input for SearchEmails Tool. |
|
Tool for sending calendar events in Office 365. |
|
Input for CreateEvent Tool. |
|
Tool for sending an email in Office 365. |
|
Input for SendMessageTool. |
|
A model for a single API operation. |
|
A model for a property in the query, path, header, or cookie params. |
|
Base model for an API property. |
|
The location of the property. |
|
A model for a request body. |
|
A model for a request body property. |
|
Tool that queries the OpenWeatherMap API. |
|
Base class for browser tools. |
|
Tool for clicking on an element with the given CSS selector. |
|
Input for ClickTool. |
|
Tool for getting the URL of the current webpage. |
|
Extract all hyperlinks on the page. |
|
|
Input for ExtractHyperlinksTool. |
Tool for extracting all the text on the current webpage. |
|
Tool for getting elements in the current web page matching a CSS selector. |
|
Input for GetElementsTool. |
|
Tool for navigating a browser to a URL. |
|
Input for NavigateToolInput. |
|
Navigate back to the previous page in the browser history. |
|
AI Plugin Definition. |
|
Tool for getting the OpenAPI spec for an AI Plugin. |
|
Schema for AIPluginTool. |
|
API Configuration. |
|
Tool for getting metadata about a PowerBI Dataset. |
|
Tool for getting tables names. |
|
Tool for querying a Power BI Dataset. |
|
Tool that searches the PubMed API. |
|
A tool for running python code in a REPL. |
|
A tool for running python code in a REPL. |
|
Base class for requests tools. |
|
Tool for making a DELETE request to an API endpoint. |
|
Tool for making a GET request to an API endpoint. |
|
Tool for making a PATCH request to an API endpoint. |
|
Tool for making a POST request to an API endpoint. |
|
Tool for making a PUT request to an API endpoint. |
|
Input for SceneXplain. |
|
Tool that explains images. |
|
Tool that queries a Searx instance and gets back json. |
|
Tool that queries a Searx instance. |
|
Commands for the Bash Shell tool. |
|
Tool to run shell commands. |
|
Input for CopyFileTool. |
|
Tool that adds the capability to sleep. |
|
Base tool for interacting with Spark SQL. |
|
Tool for getting metadata about a Spark SQL. |
|
Tool for getting tables names. |
|
Use an LLM to check if a query is correct. |
|
Tool for querying a Spark SQL. |
|
Base tool for interacting with a SQL database. |
|
Tool for getting metadata about a SQL database. |
|
Tool for getting tables names. |
|
Use an LLM to check if a query is correct. |
|
Tool for querying a SQL database. |
|
Supported Image Models for generation. |
|
|
Tool used to generate images from a text-prompt. |
Base class for tools that use a VectorStore. |
|
Tool for the VectorDBQA chain. |
|
Tool for the VectorDBQAWithSources chain. |
|
Tool that searches the Wikipedia API. |
|
Tool that queries using the Wolfram Alpha SDK. |
|
Tool that queries YouTube. |
|
Returns a list of all exposed (enabled) actions associated with |
|
Executes an action that is identified by action_id, must be exposed |
Functions¶
Authenticate using the Amadeus API |
|
|
Detect if the file is local or remote. |
|
Download audio from url to local. |
Create a pydantic schema from a function's signature. |
|
|
Make tools out of functions, can be used with or without arguments. |
|
Format tool into the OpenAI function API. |
Deprecated. |
|
|
Resolve a relative path, raising an error if not within the root directory. |
Check if path is relative to root. |
|
Build a Gmail service. |
|
Clean email body. |
|
Get credentials. |
|
Import google libraries. |
|
Import googleapiclient.discovery.build function. |
|
Import InstalledAppFlow class. |
|
Tool for asking the user for input. |
|
Authenticate using the Microsoft Grah API |
|
Clean body of a message or event. |
|
Lazy import playwright browsers. |
|
Asynchronously get the current page of the browser. |
|
|
Create an async playwright browser. |
|
Create a playwright browser. |
Get the current page of the browser. |
|
Run an async coroutine. |
|
Convert the yaml or json serialized spec to a dict. |
|
Sanitize input to the python REPL. |
|
|
Upload a block to a signed URL and return the public URL. |
langchain.utilities¶
Utilities are the integrations with third-part systems and packages.
Other LangChain classes use Utilities to interact with third-part systems and packages.
Classes¶
Wrapper around ArxivAPI. |
|
Wrapper for AWS Lambda SDK. |
|
Wrapper around bibtexparser. |
|
Wrapper for Bing Search API. |
|
Wrapper around the Brave search engine. |
|
Wrapper around the DataForSeo API. |
|
Wrapper for DuckDuckGo Search API. |
|
Wrapper for GitHub API. |
|
Wrapper for Golden. |
|
Wrapper around Google Places API. |
|
Wrapper for Google Search API. |
|
Wrapper around the Serper.dev Google Search API. |
|
Wrapper around GraphQL API. |
|
Wrapper for Jira API. |
|
Wrapper for Metaphor Search API. |
|
Wrapper for Multion Client API. |
|
|
Enumerator of the HTTP verbs. |
OpenAPI Model that removes misformatted parts of the spec. |
|
Wrapper for OpenWeatherMap API using PyOWM. |
|
Create PowerBI engine from dataset ID and credential or token. |
|
Wrapper around PubMed API. |
|
Simulates a standalone Python REPL. |
|
Wrapper around requests to handle auth and async. |
|
Lightweight wrapper around requests library. |
|
Wrapper for SceneXplain API. |
|
Dict like wrapper around search api results. |
|
Wrapper for Searx API. |
|
Wrapper around SerpAPI. |
|
Messaging Client using Twilio. |
|
Wrapper around WikipediaAPI. |
|
Wrapper for Wolfram Alpha. |
|
Wrapper for Zapier NLA. |
Functions¶
|
Load configuration from hub. |
Add single quotes around table names that contain spaces. |
|
|
Converts a JSON object to a markdown table. |
Warn once about the dangers of PythonREPL. |
|
|
Get a redis client from the connection url given. |
|
Truncate a string to a certain number of words, based on the max string length. |
|
Init vertexai. |
Raise ImportError related to Vertex SDK being not available. |
langchain.utils¶
Utility functions for LangChain.
These functions do not depend on any other LangChain module.
Classes¶
A subclass of formatter that checks for extra keys. |
Functions¶
|
Get a value from a dictionary or an environment variable. |
|
Get a value from a dictionary or an environment variable. |
Get bolded text. |
|
|
Get mapping for items to a support color. |
|
Get colored text. |
|
Print text with highlighting and no end characters. |
Row-wise cosine similarity between two equal-width matrices. |
|
|
Row-wise cosine similarity with optional top-k and score threshold filtering. |
|
Convert a list to a comma-separated string. |
Stringify a dictionary. |
|
Stringify a value. |
|
|
Check the version of a package. |
Get field names, including aliases, for a pydantic class. |
|
|
Dynamically imports a module and raises a helpful exception if the module is not installed. |
|
Context manager for mocking out datetime.now() in unit tests. |
|
Raise an error with the response text. |
|
Validate specified keyword args are mutually exclusive. |
langchain.vectorstores¶
Vector store stores embedded data and performs vector search.
One of the most common ways to store and search over unstructured data is to embed it and store the resulting embedding vectors, and then query the store and retrieve the data that are ‘most similar’ to the embedded query.
Class hierarchy:
VectorStore --> <name> # Examples: Annoy, FAISS, Milvus
BaseRetriever --> VectorStoreRetriever --> <name>Retriever # Example: VespaRetriever
Main helpers:
Embeddings, Document
Classes¶
|
Alibaba Cloud OpenSearch Vector Store |
|
VectorStore implementation using AnalyticDB. |
|
Wrapper around Annoy vector database. |
|
Wrapper around Atlas: Nomic's neural database and rhizomatic instrument. |
|
Interface implemented by AwaDB vector stores. |
|
Azure Cognitive Search vector store. |
Retriever that uses Azure Search to find similar documents. |
|
Interface for vector stores. |
|
Retriever class for VectorStore. |
|
|
Wrapper around Cassandra embeddings platform. |
|
Wrapper around ChromaDB embeddings platform. |
|
Wrapper around Clarifai AI platform's vector store. |
|
Wrapper around ClickHouse vector database |
ClickHouse Client Configuration |
|
Wrapper around Deep Lake, a data lake for deep learning applications. |
|
Initialize a vector store from DocArray's DocIndex. |
|
Wrapper around HnswLib storage. |
|
Wrapper around in-memory storage for exact search. |
|
ElasticKnnSearch is a class for performing k-nearest neighbor (k-NN) searches on text data using Elasticsearch. |
|
Wrapper around Elasticsearch as a vector database. |
|
|
Wrapper around FAISS vector database. |
|
VectorStore implementation using Hologres. |
|
Wrapper around LanceDB vector database. |
|
Wrapper around Marqo database. |
Vertex Matching Engine implementation of the vector store. |
|
|
Initialize wrapper around Meilisearch vector database. |
|
Initialize wrapper around the milvus vector database. |
Wrapper around MongoDB Atlas Vector Search. |
|
|
Wrapper around MyScale vector database |
MyScale Client Configuration |
|
|
Wrapper around OpenSearch as a vector database. |
|
A simple constructor that allows initialization from kwargs. |
A simple constructor that allows initialization from kwargs. |
|
|
A simple constructor that allows initialization from kwargs. |
|
VectorStore implementation using Postgres and the pg_embedding extension. |
|
A simple constructor that allows initialization from kwargs. |
Enumerator of the Distance strategies. |
|
|
VectorStore implementation using Postgres and pgvector. |
|
Wrapper around Pinecone vector database. |
|
Wrapper around Qdrant vector database. |
Base class for all the Qdrant related exceptions |
|
|
Wrapper around Redis vector database. |
Retriever for Redis VectorStore. |
|
|
Wrapper arpund Rockset vector database. |
This class serves as a Pythonic interface to the SingleStore DB database. |
|
Retriever for SingleStoreDB vector stores. |
|
|
Abstract base class for saving and loading data. |
|
Serializes data in binary json using the bson python package. |
|
Serializes data in json using the json package from python standard library. |
Serializes data in Apache Parquet format using the pyarrow package. |
|
A simple in-memory vector store based on the scikit-learn library NearestNeighbors implementation. |
|
Exception raised by SKLearnVectorStore. |
|
|
Wrapper around StarRocks vector database |
StarRocks Client Configuration |
|
VectorStore for a Supabase postgres database. |
|
|
Wrapper around Tair Vector store. |
|
Initialize Tigris vector store |
|
Wrapper around Typesense vector search. |
|
Enumerator of the Distance strategies for calculating distances between vectors. |
|
Implementation of Vector Store using Vectara. |
Retriever class for Vectara. |
|
|
Wrapper around Weaviate vector database. |
|
Initialize wrapper around the Zilliz vector database. |
Functions¶
|
Create metadata from fields. |
Import annoy if available, otherwise raise error. |
|
|
Check if a string contains multiple substrings. |
Import faiss if available, otherwise raise error. |
|
|
Check if a string contains multiple substrings. |
Decorator to call the synchronous method of the class if the async method is not implemented. |
|
Print a debug message if DEBUG is True. |
|
Get a named result from a query. |
|
|
Check if a string has multiple substrings. |
Calculate maximal marginal relevance. |