LangChain Fundamentals
Master LangChain Fundamentals — what is LangChain, Models API, LLMs vs Chat Models, Embeddings, LCEL, installation and setup with code examples.
This module introduces LangChain — the open-source framework that serves as the foundation for building LLM-powered applications. You'll understand what LangChain is, why it exists, its core components, and write your first LangChain code. By the end, you'll be able to connect to any LLM, run inference, and understand the pipe-based LCEL architecture.
What is LangChain & Why Learn It First
Why this matters
LangChain standardizes LLM app plumbing — models, prompts, chains — so you ship faster than raw API calls.
LangChain is a framework for composing LLM applications: models, prompts, parsers, retrievers, and agents share a common Runnable interface.
- Modular components swap providers (OpenAI, Anthropic, local models).
- LCEL (
|pipe) chains steps with streaming and async support. - Ecosystem: LangSmith (observability), LangGraph (stateful agents).
Common mistakes
- Hard-coding API keys in source instead of environment variables.
- Passing raw strings where ChatPromptTemplate expects message tuples.
- Skipping text splitting before embedding large PDFs (context overflow).
Interview checkpoints
- Q: Explain langchain intro in LangChain. A: One-sentence definition + one API name.
- Q: Common bug? A: Keys, message format, or missing split/embed step.
Practice
- Basic: Sketch a minimal langchain intro snippet.
- Intermediate: Run a notebook cell demonstrating LangChain Intro.
- Advanced: Break LangChain Intro intentionally and interpret the error.
Recap
- You can explain langchain intro clearly.
- You know one mistake to avoid.
- You see how this connects to the next lesson.
Next: Models & LCEL
Models API, Embeddings & LCEL Setup
Why this matters
Chat models, embeddings, and LCEL are the core building blocks every LangChain app composes.
Use Chat models for message-based APIs; legacy LLMs accept plain strings. Embeddings convert text to vectors for search.
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
emb = OpenAIEmbeddings(model="text-embedding-3-small")Install: pip install langchain langchain-openai langchain-community python-dotenv. Load keys via OPENAI_API_KEY in .env.
Common mistakes
- Hard-coding API keys in source instead of environment variables.
- Passing raw strings where ChatPromptTemplate expects message tuples.
- Skipping text splitting before embedding large PDFs (context overflow).
Interview checkpoints
- Q: Explain models & lcel in LangChain. A: One-sentence definition + one API name.
- Q: Common bug? A: Keys, message format, or missing split/embed step.
Practice
- Basic: Sketch a minimal models & lcel snippet.
- Intermediate: Run a notebook cell demonstrating Models & LCEL.
- Advanced: Break Models & LCEL intentionally and interpret the error.
Recap
- You can explain models & lcel clearly.
- You know one mistake to avoid.
- You see how this connects to the next lesson.
Next: Prompt Templates
