LangChain Introduction, Architecture and Installation
What LangChain is, how its packages fit together, and how to install and verify it.
LangChain is an open-source framework for building applications with language models. It provides standard interfaces for chat models, embeddings, vector stores, retrievers and tools from hundreds of providers, plus agents built on its sister project LangGraph. This module teaches LangChain for RAG from the ground up. This first lesson explains how LangChain is organised in its current (v1) form and gets it installed.
What you will learn
- What LangChain provides and when it is worth using
- How the LangChain packages fit together in version 1
- How to install LangChain with the integrations used in this module
- How to make your first model call with
init_chat_model
Prerequisites
- Python 3.10 or later (Python Environment Setup)
- Build a Minimal RAG System from Scratch (so you know what LangChain automates)
Architecture: the package layout
LangChain 1.0 (released in late 2025) reorganised the project into focused packages:
| Package | Contains |
|---|---|
langchain-core | Base abstractions: messages, prompts, documents, the Runnable interface (LCEL), vector store and retriever interfaces, output parsers |
langchain | The main package: agents (create_agent), tools, init_chat_model, embeddings helpers |
| Provider packages | langchain-anthropic, langchain-openai, langchain-ollama, langchain-google-genai, langchain-chroma, langchain-postgres, langchain-pinecone and many more |
langchain-text-splitters | Text splitters such as RecursiveCharacterTextSplitter |
langchain-community | Community-maintained integrations, including many document loaders |
langchain-classic | Legacy APIs moved out of the main package in v1: older chains (such as the RetrievalQA family), retrievers, the indexing API and the hub |
langgraph | The graph runtime that powers agents and stateful workflows |
Older tutorials import chains such as RetrievalQA from langchain.chains. In LangChain 1.x those legacy chains live in langchain-classic; new code should use LCEL chains or agents instead, as this module shows.
The building blocks for RAG
- Document loaders read files into
Documentobjects. - Text splitters chunk them.
- Embeddings and vector stores index the chunks.
- Retrievers return relevant chunks for a query.
- Prompt templates and chat models generate the answer.
- LCEL (the
|operator on Runnables) or an agent connects the steps.
Installation
pip install -U langchain langchain-core langchain-anthropic langchain-text-splitters
pip install -U langchain-community langchain-chroma langchain-huggingface # used later in this module
Check the installed versions:
import langchain, langchain_core
print(langchain.__version__, langchain_core.__version__)
1.x.y 1.x.y
The lessons in this module are written for LangChain 1.x. Pin versions in requirements.txt once your project works; LangChain releases frequently.
Your first call
init_chat_model creates a chat model from a "provider:model" string, so switching providers is a one-line change:
from dotenv import load_dotenv
from langchain.chat_models import init_chat_model
load_dotenv() # ANTHROPIC_API_KEY from .env
model = init_chat_model("anthropic:claude-opus-5-5")
reply = model.invoke("In one sentence, what does LangChain do?")
print(reply.text) # the reply's text content
LangChain provides standard building blocks and integrations for creating applications
powered by language models, such as chatbots, RAG systems and agents.
Every LangChain model, retriever and chain is a Runnable with the same methods: invoke (one input), batch (many inputs) and stream (incremental output). You will use them throughout the module.
When to use LangChain
- Good fit: you want many integrations, to switch providers easily, or to build agents and stateful workflows with LangGraph.
- Less needed: a small, fixed pipeline you fully understand; plain SDK code is shorter and easier to debug (Build from Scratch or Use a Framework?).
Common errors and troubleshooting
ImportError: cannot import name 'RetrievalQA' from 'langchain.chains': old tutorial code; use the patterns in this module, or installlangchain-classicfor legacy code.- Provider not found in
init_chat_model: install the provider package (langchain-anthropic,langchain-openai). - Errors about
temperaturewith current Claude models: these models do not accept sampling parameters; do not pass them.
Key takeaways
- LangChain 1.x splits into
langchain-core,langchain, provider packages, text splitters, community and classic. - Legacy chains live in
langchain-classic; new RAG code uses LCEL or agents. init_chat_model("provider:model")creates a chat model; every component is a Runnable.
Frequently asked questions
What is the difference between LangChain and LangGraph?
LangChain provides components and agents; LangGraph is the lower-level runtime for stateful, multi-step graphs that LangChain agents are built on (LangGraph Architecture and State).
Is the earlier "RAG with LangChain and LangGraph" lesson still valid?
That overview lesson uses LCEL from langchain-core, which is current. This module goes deeper into each component.
Practice exercises
- Use
model.batch([...])to ask three questions at once. - Stream a reply with
for chunk in model.stream("..."): print(chunk.text, end="").