Conceptual Guide
Overviewβ
In this guide, you'll find explanations of the key concepts, providing a deeper understanding of core principles.
We recommend that you go through at least one of the Tutorials before diving into the conceptual guide. This will help you understand the context and practical applications of the concepts discussed here.
The conceptual guide will not cover step-by-step instructions or specific implementation details β those are found in the How-To Guides and Tutorials sections. For detailed reference material, please visit the API Reference.
High Levelβ
- Why LangChain?: Why LangChain is the best choice for building AI applications.
- Architecture: Overview of how packages are organized in the LangChain ecosystem.
Conceptsβ
- Chat Models: Modern LLMs exposed via a chat interface which process sequences of messages as input and output a message.
- Messages: Messages are the unit of communication in modern LLMs, used to represent input and output of a chat model, as well as any additional context or metadata that may be associated with the conversation.
- Chat History: Chat history is a record of the conversation between the user and the chat model, used to maintain context and state throughout the conversation.
- Tools: The tool abstraction in LangChain associates a Python function with a schema defining the function's name, description, and input.
- Tool Calling: Tool calling is the process of invoking a tool from a chat model.
- Structured Output: A technique to make the chat model respond in a structured format, such as JSON and matching a specific schema.
- Memory: Explanation of short-term memory and long-term memory and how to implement them using LangGraph.
- Multimodality: The ability to work with data that comes in different forms, such as text, audio, images, and video.
- Tokens: Modern large language models (LLMs) are typically based on a transformer architecture that processes a sequence of units known as tokens.
- Runnable Interface: Description of the standard Runnable interface which is implemented by many components in LangChain.
- LangChain Expression Language (LCEL): A declarative approach to building new Runnables from existing Runnables.
- Document Loaders: Abstraction for loading documents.
- Retrieval: Information retrieval systems can retrieve structured or unstructured data from a datasource in response to a query.
- Text Splitters: Use to split long content into smaller more manageable chunks.
- Embedding Models: Embedding models are models that can represent data in a vector space.
- VectorStores: A datastore that can store embeddings and associated data and supports efficient vector search.
- Retriever: A retriever is a component that retrieves relevant documents from a knowledge base in response to a query.
- Retrieval Augmented Generation (RAG): A powerful technique that enhances language models by combining them with external knowledge bases.
- Agents: Use a language model to choose a sequence of actions to take. Agents can interact with external resources via tool calling.
- Prompt Templates: Use to define prompt templates that can be lazily evaluated to generate prompts for language models. Primarily used with LCEL or prompts need to be serialized and stored for later use (e.g., in a database).
- Async Programming with LangChain: This guide covers some basic things that one should know to work with LangChain in an asynchronous context.
- Callbacks: Learn about the callback system in LangChain. It is composed of CallbackManagers (which dispatch events to the registered handlers) and CallbackHandlers (which handle the events). Callbacks are used to stream outputs from LLMs in LangChain, observe the progress of an LLM application, and more.
- Output Parsers: Output parsers are responsible for taking the output of a model and transforming it into a more suitable format for downstream tasks. Output parsers were primarily useful prior to the general availability of chat models that natively support tool calling and structured outputs.
Glossaryβ
- AIMessageChunk: A partial response from an AI message. Used when streaming responses from a chat model.
- AIMessage: Represents a complete response from an AI model.
- astream_events: Stream granular information from LCEL chains.
- BaseTool: The base class for all tools in LangChain.
- batch: Use to execute a runnable with batch inputs a Runnable.
- bind_tools: Allows models to interact with tools.
- Caching: Storing results to avoid redundant calls to a chat model.
- Chat Models: Chat models that handle multiple data modalities.
- Configurable Runnables: Creating configurable Runnables.
- Context window: The maximum size of input a chat model can process.
- Conversation patterns: Common patterns in chat interactions.
- Embedding models: Models that generate vector embeddings for various data types.
- HumanMessage: Represents a message from a human user.
- InjectedState: A state injected into a tool function.
- InjectedStore: A store that can be injected into a tool for data persistence.
- InjectedToolArg: Mechanism to inject arguments into tool functions.
- input and output types: Types used for input and output in Runnables.
- invoke: A standard method to invoke a Runnable.
- JSON mode: Returning responses in JSON format.
- langchain-community: Community-driven components for LangChain.
- langchain-core: Core langchain package. Includes base interfaces and in-memory implementations.
- langchain: A package for higher level components (e.g., some pre-built chains).
- langgraph: Powerful orchestration layer for LangChain. Use to build complex pipelines and workflows.
- langserve: Use to deploy LangChain Runnables as REST endpoints. Uses FastAPI. Works primarily for LangChain Runnables, does not currently integrate with LangGraph.
- Managing chat history: Techniques to maintain and manage the chat history.
- Multimodality: Capability to process different types of data like text, audio, and images.
- OpenAI format: OpenAI's message format for chat models.
- Partner packages: Third-party packages that integrate with LangChain.
- Propagation of RunnableConfig: Propagating configuration through Runnables. Read if working with python 3.9, 3.10 and async.
- rate-limiting: Client side rate limiting for chat models.
- RemoveMessage: An abstraction used to remove a message from chat history, used primarily in LangGraph.
- role: Represents the role (e.g., user, assistant) of a chat message.
- RunnableConfig: Use to pass run time information to Runnables (e.g.,
run_name
,run_id
,tags
,metadata
,max_concurrency
,recursion_limit
,configurable
). - Standard parameters for chat models: Parameters such as API key,
temperature
, andmax_tokens
, - stream: Use to stream output from a Runnable or a graph.
- Tokenization: The process of converting data into tokens and vice versa.
- Tokens: The basic unit that a language model reads, processes, and generates.
- Tool artifacts: Add artifacts to the output of a tool that will not be sent to the model, but will be available for downstream processing.
- Tool binding: Binding tools to models.
- @tool: Decorator for creating tools in LangChain.
- ToolMessage: Represents a message that contains the results of a tool execution.
- Vectorstores: Datastores specialized for storing and efficiently searching vector embeddings.
- with_structured_output: A helper method for chat models that natively support tool calling to get structured output matching a given schema specified via Pydantic, JSON schema or a function.
- with_types: Method to overwrite the input and output types of a runnable. Useful when working with complex LCEL chains and deploying with LangServe.