LangChain Basics
Raw SDK calls do not scale past a demo. You need swappable loaders and stores without rewriting the app. LangChain is the plumbing. LangGraph (a later phase) is the control loop for agents.
LangChain is like React for LLM apps: reusable components you wire together instead of rewriting fetch-and-prompt for every project.
Visual Workflows
Start here — scroll inside each diagram frame to explore, then use + / − to zoom up to 200% if needed.
Overview
Scroll inside the frame to explore · use + / − to zoom up to 200%
Scroll inside the frame to explore · use + / − to zoom up to 200%
Minimal LCEL RAG
Scroll inside the frame to explore · use + / − to zoom up to 200%
Each box is swappable. Keep the interfaces, change the backends.
Where it stops
Scroll inside the frame to explore · use + / − to zoom up to 200%
LangChain wires RAG. LangGraph (later phase) owns loops, retries, and HITL.
Key Takeaways
- 1.LangChain is a toolkit for composing RAG pieces — loaders, splitters, embeddings, vector stores, retrievers, prompts, and chat models — behind one set of interfaces.
- 2.Core RAG objects: Document loaders, RecursiveCharacterTextSplitter, embeddings wrappers, vector stores (Chroma, Pinecone, etc.), retrievers, ChatPromptTemplate, and chat models.
- 3.LCEL lets you pipe retriever | prompt | llm with streaming.
- 4.In 2026 use LangChain for integrations and retrieval; do not hide evaluation inside an opaque chain — log retrieved docs.
- 5.Prefer LangGraph when you need retries, branching, or human-in-the-loop.
Real Example
Scenario
Handbook RAG: load a PDF, split to 512-token chunks, store in Chroma, retrieve top-4, and ask gpt-4o-mini to answer only from that context with citations.
What you would do
In RAG Engineering, apply LangChain Basics to this scenario: Handbook RAG: load a PDF, split to 512-token chunks, store in Chroma, retrieve top-4, and ask gpt-4o-mini to answer only from that context with citations. 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.
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", temperature=0)6splitter = RecursiveCharacterTextSplitter(chunk_size=512, chunk_overlap=64)7chunks = splitter.split_text(open("handbook.txt").read())8store = Chroma.from_texts(chunks, OpenAIEmbeddings())9retriever = store.as_retriever(search_kwargs={"k": 4})10
11question = "How many PTO days do we get?"12docs = retriever.invoke(question)13context = "\n\n".join(d.page_content for d in docs)14print(llm.invoke(f"Answer using only this context:\n{context}\n\nQ: {question}").content) # show output for debuggingCommands
Commands to Remember
pip install langchain langchain-openai langchain-chroma langchain-text-splittersRecursiveCharacterTextSplitter → Chroma.from_texts → as_retrieverretriever.invoke(question) # list of DocumentsUse LangChain for RAG plumbing; LangGraph later for agent control
Cheat Sheet
Quick recap
quick ref- •LangChain = RAG plumbing
- •Loader → splitter → store → retriever → LLM
- •LCEL pipes, not hidden magic
- •LangGraph later for agent loops
Common Mistakes
- ✕Treating LangChain as an agent framework — that is LangGraph
- ✕Never logging which chunks were retrieved
- ✕One giant chain you cannot eval stage by stage
