0
RAG Engineering
Phase 3Module 15 of 18

LangChain Basics

Raw API calls don't scale to complex apps. LangChain provides abstractions for prompts, memory, retrieval, and tool routing so you ship faster.

LangChain is like React for LLM apps — reusable components (prompts, parsers, retrievers) you wire together instead of reinventing plumbing.

Visual Workflows

Start here — study each diagram, then use + / to zoom if needed.

100%
Loading diagram...

Scroll inside the frame · use + / − to zoom

Key Takeaways

  • 1.LangChain is a Python/JS framework for composing LLM applications — chains, retrievers, tools, and agents with standardized interfaces.
  • 2.Core pieces: Chat models (OpenAI, Anthropic wrappers), prompt templates, output parsers, document loaders, text splitters, embeddings, vector stores, retrievers, and LCEL for declarative pipelines.
  • 3.In 2026, use LangChain for integrations but prefer LangGraph for agent control flow.

Real Example

Scenario

Build a RAG chain: load PDF → split → embed → store in Chroma → retrieve top-k chunks → pass to LLM with a prompt template.

What you would do

In RAG Engineering, apply LangChain Basics to this scenario: Build a RAG chain: load PDF → split → embed → store in Chroma → retrieve top-k chunks → pass to LLM with a prompt template. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

Practice Task

Open the Code Walkthrough below and run it locally. Change one parameter related to LangChain Basics (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

Code Walkthrough

Highlighted lines show where LangChain Basics happens in the code.

LangChain Basics
1from langchain_openai import ChatOpenAI, OpenAIEmbeddings  # import dependencies2from langchain_chroma import Chroma  # import dependencies3from langchain_text_splitters import RecursiveCharacterTextSplitter  # import dependencies4
5llm = ChatOpenAI(model="gpt-4o-mini")6splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)7docs = splitter.split_text(open("handbook.txt").read())8vectorstore = Chroma.from_texts(docs, OpenAIEmbeddings())9retriever = vectorstore.as_retriever(search_kwargs={"k": 4})10context = "\n".join(d.page_content for d in retriever.invoke("PTO policy"))11print(llm.invoke(f"Answer using context:\n{context}\nQ: How many PTO days?").content)  # show output for debugging

Cheat Sheet

Quick recap

quick ref
  • LangChain Basics
  • LCEL
  • Retrievers
  • Vector Stores

Common Mistakes

  • Treating LangChain Basics as a black box without evaluation
  • Ignoring cost and latency in production
  • Skipping error handling for langchain basics