How-to guides
Here you'll find answers to βHow do Iβ¦.?β types of questions. These guides are goal-oriented and concrete; they're meant to help you complete a specific task. For conceptual explanations see Conceptual Guides. For end-to-end walkthroughs see Tutorials. For comprehensive descriptions of every class and function see API Reference.
Installationβ
Key featuresβ
This highlights functionality that is core to using LangChain.
- How to: return structured data from an LLM
- How to: use a chat model to call tools
- How to: stream runnables
- How to: debug your LLM apps
LangChain Expression Language (LCEL)β
LangChain Expression Language is a way to create arbitrary custom chains. It is built on the Runnable protocol.
- How to: chain runnables
- How to: stream runnables
- How to: invoke runnables in parallel
- How to: attach runtime arguments to a runnable
- How to: run custom functions
- How to: pass through arguments from one step to the next
- How to: add values to a chain's state
- How to: add message history
- How to: route execution within a chain
- How to: inspect runnables
- How to: add fallbacks
Componentsβ
These are the core building blocks you can use when building applications.
Prompt templatesβ
Prompt Templates are responsible for formatting user input into a format that can be passed to a language model.
- How to: use few shot examples
- How to: use few shot examples in chat models
- How to: partially format prompt templates
- How to: compose prompts together
Example selectorsβ
Example Selectors are responsible for selecting the correct few shot examples to pass to the prompt.
- How to: use example selectors
- How to: select examples by length
- How to: select examples by semantic similarity
Chat modelsβ
Chat Models are newer forms of language models that take messages in and output a message.
- How to: do function/tool calling
- How to: get models to return structured output
- How to: cache model responses
- How to: get log probabilities
- How to: create a custom chat model class
- How to: stream a response back
- How to: track token usage
LLMsβ
What LangChain calls LLMs are older forms of language models that take a string in and output a string.
- How to: cache model responses
- How to: create a custom LLM class
- How to: stream a response back
- How to: track token usage
Output parsersβ
Output Parsers are responsible for taking the output of an LLM and parsing into more structured format.
- How to use output parsers to parse an LLM response into structured format
- How to parse JSON output
- How to parse XML output
- How to try to fix errors in output parsing
- How to write a custom output parser class
Document loadersβ
Document Loaders are responsible for loading documents from a variety of sources.
- How to: load CSV data
- How to: load data from a directory
- How to: load HTML data
- How to: load JSON data
- How to: load Markdown data
- How to: load Microsoft Office data
- How to: load PDF files
- How to: write a custom document loader
Text splittersβ
Text Splitters take a document and split into chunks that can be used for retrieval.
- How to: recursively split text
- How to: split by HTML headers
- How to: split by HTML sections
- How to: split by character
- How to: split code
- How to: split Markdown by headers
- How to: recursively split JSON
- How to: split text into semantic chunks
- How to: split by tokens
Embedding modelsβ
Embedding Models take a piece of text and create a numerical representation of it.
Vector storesβ
Vector stores are databases that can efficiently store and retrieve embeddings.
Retrieversβ
Retrievers are responsible for taking a query and returning relevant documents.
- How to: use a vector store to retrieve data
- How to: generate multiple queries to retrieve data for
- How to: use contextual compression to compress the data retrieved
- How to: write a custom retriever class
- How to: add similarity scores to retriever results
- How to: combine the results from multiple retrievers
- How to: reorder retrieved results to put most relevant documents not in the middle
- How to: generate multiple embeddings per document
- How to: retrieve the whole document for a chunk
- How to: generate metadata filters
- How to: create a time-weighted retriever
- How to: use a Matryoshka retriever
Indexingβ
Indexing is the process of keeping your vectorstore in-sync with the underlying data source.
Toolsβ
LangChain Tools contain a description of the tool (to pass to the language model) as well as the implementation of the function to call).
- How to: use LangChain tools
- How to: use a chat model to call tools
- How to: use LangChain toolkits
- How to: define a custom tool
- How to: convert LangChain tools to OpenAI functions
- How to: use tools without function calling
- How to: let the LLM choose between multiple tools
- How to: add a human in the loop to tool usage
- How to: do parallel tool use
- How to: handle errors when calling tools
- How to: call tools using multi-modal data
Agentsβ
For in depth how-to guides for agents, please check out LangGraph documentation.
- How to: use legacy LangChain Agents (AgentExecutor)
- How to: migrate from legacy LangChain agents to LangGraph
Customβ
All of LangChain components can easily be extended to support your own versions.
- How to: create a custom chat model class
- How to: create a custom LLM class
- How to: write a custom retriever class
- How to: write a custom document loader
- How to: write a custom output parser class
- How to: define a custom tool
Use casesβ
These guides cover use-case specific details.
Q&A with RAGβ
Retrieval Augmented Generation (RAG) is a way to connect LLMs to external sources of data.
- How to: add chat history
- How to: stream
- How to: return sources
- How to: return citations
- How to: do per-user retrieval
Extractionβ
Extraction is when you use LLMs to extract structured information from unstructured text.
- How to: use reference examples
- How to: handle long text
- How to: do extraction without using function calling
Chatbotsβ
Chatbots involve using an LLM to have a conversation.
Query analysisβ
Query Analysis is the task of using an LLM to generate a query to send to a retriever.
- How to: add examples to the prompt
- How to: handle cases where no queries are generated
- How to: handle multiple queries
- How to: handle multiple retrievers
- How to: construct filters
- How to: deal with high cardinality categorical variables
Q&A over SQL + CSVβ
You can use LLMs to do question answering over tabular data.
- How to: use prompting to improve results
- How to: do query validation
- How to: deal with large databases
- How to: deal with CSV files
Q&A over graph databasesβ
You can use an LLM to do question answering over graph databases.