<CodeChronicles/>
← Back to Blog

Understanding LangChain — What It Is, Why It Exists, and When to Use It

05/01/2026·8 min read

This post is part of my learning journey from full-stack developer to AI-native engineer. After watching the AI Jason RAG course and studying LangChain.js, here's my plain-English breakdown.


The Problem LangChain Solves

📌 Credit: The problems described in this section were widely documented by the developer community in 2022–2023. The framing of LangChain as the solution was articulated by Harrison Chase (LangChain creator) in his original launch thread and subsequent talks.

When you first use the OpenAI API directly, it's simple:

const response = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "What is RAG?" }],
});
console.log(response.choices[0].message.content);

That works for a single question. But real AI applications need much more:

❌ How do I load 50 PDF documents and search them?
❌ How do I remember what the user said 10 messages ago?
❌ How do I let the LLM call external APIs as tools?
❌ How do I chain multiple LLM calls together in a pipeline?
❌ How do I switch from OpenAI to Anthropic without rewriting everything?
❌ How do I stream responses while also doing retrieval?

Every team building on LLMs was solving these same problems from scratch — writing custom loaders, chunkers, vector store integrations, memory systems, and agent loops.

LangChain is the framework that solves all of this with reusable, composable building blocks.


What LangChain Actually Is

LangChain is an open-source framework for building LLM-powered applications. It provides:

Document Loaders    → Read PDF, markdown, URLs, databases, etc.
Text Splitters      → Chunk large documents into digestible pieces
Embedding Models    → Convert text to vectors (OpenAI, HuggingFace, etc.)
Vector Stores       → Store and search embeddings (Supabase, Pinecone, etc.)
LLM Wrappers        → Unified interface for OpenAI, Anthropic, Gemini, etc.
Chains              → Compose multiple steps into a pipeline
Memory              → Give the LLM conversation history
Agents              → Let the LLM decide which tools to call
Tools               → Web search, calculator, file system, APIs, etc.

Think of it like Spring Boot for AI — just as Spring Boot gives you abstractions over HTTP, databases, and security so you don't write everything from scratch, LangChain gives you abstractions over LLMs, vector databases, and AI patterns.

📌 Credit: LangChain was created by Harrison Chase and first released in October 2022. The JavaScript version (LangChain.js) is maintained by the LangChain team.


How It Solves the Problem — RAG Example

Without LangChain, building a RAG pipeline from scratch requires ~200 lines of custom code:

  • Custom PDF parser
  • Custom chunking logic
  • Direct OpenAI embedding API calls
  • Custom vector similarity search
  • Manual prompt construction
  • Custom output parsing

With LangChain, the same RAG pipeline is ~20 lines:

import { ChatOpenAI } from "@langchain/openai";
import { OpenAIEmbeddings } from "@langchain/openai";
import { SupabaseVectorStore } from "@langchain/community/vectorstores/supabase";
import { createRetrievalChain } from "langchain/chains/retrieval";
import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
import { ChatPromptTemplate } from "@langchain/core/prompts";

// 1. LLM
const llm = new ChatOpenAI({ model: "gpt-4o-mini" });

// 2. Vector store (already populated with your docs)
const vectorStore = await SupabaseVectorStore.fromExistingIndex(
  new OpenAIEmbeddings(),
  { client, tableName: "documents" }
);

// 3. Prompt
const prompt = ChatPromptTemplate.fromTemplate(`
  Answer the question using only the provided context.
  Context: {context}
  Question: {input}
`);

// 4. Chain — combines retrieval + generation in one call
const chain = await createRetrievalChain({
  combineDocsChain: await createStuffDocumentsChain({ llm, prompt }),
  retriever: vectorStore.asRetriever(),
});

// 5. Run it
const result = await chain.invoke({ input: "What are Java threading questions?" });
console.log(result.answer);

The document loading, embedding, vector search, prompt injection, and LLM call all happen inside those abstractions. Swap SupabaseVectorStore for PineconeVectorStore and the rest of the code stays identical.


Core Concepts to Know

Chains

A chain is a sequence of steps executed in order. The simplest chain:

Prompt Template → LLM → Output Parser

More complex chains:

User Input → Query Rewriter → Vector Search → Prompt → LLM → Answer

LCEL (LangChain Expression Language)

📌 Credit: LCEL was introduced by the LangChain team in August 2023 as a declarative way to compose chains. Official docs: python.langchain.com/docs/expression_language.

The modern way to compose chains using the pipe | operator:

const chain = prompt | llm | outputParser;
const result = await chain.invoke({ question: "What is RAG?" });

Each | passes the output of one step as the input to the next — like Unix pipes but for AI.

Memory

Keeps conversation history so the LLM doesn't forget earlier messages:

import { BufferMemory } from "langchain/memory";
const memory = new BufferMemory();
// Now the chain remembers what was said in previous turns

Agents

📌 Credit: The ReAct (Reason + Act) pattern underlying LangChain agents was introduced in the paper ReAct: Synergizing Reasoning and Acting in Language Models by Yao et al. (Google Brain / Princeton, 2022).

Instead of a fixed chain, an agent lets the LLM decide what to do next:

User: "What's the weather in London and summarise today's AI news?"

Agent loop:
  → LLM decides: call weather_tool("London")
  → LLM decides: call web_search("AI news today")
  → LLM decides: I have enough info, generate final answer
  → Returns combined answer

Advantages of LangChain

AdvantageDetail
Huge ecosystem100+ integrations — every LLM, every vector DB, every document type
Provider agnosticSwap OpenAI → Anthropic → Gemini in one line
Speeds up developmentRAG in 20 lines instead of 200
LangSmith observabilityBuilt-in tracing/debugging tool — see every chain step
Active communityMost popular LLM framework, massive Stack Overflow + Discord
LangGraphOfficial extension for stateful multi-agent workflows
Battle-testedUsed in production by thousands of companies

Disadvantages of LangChain

These are real — the community talks about them openly.

📌 Credit: The "abstraction leakage" and "over-engineering" critiques were popularised in posts by Hamel Husain and Eugene Yan — both ML engineers with production LLM experience. Worth reading if you want the full picture.

DisadvantageDetail
Abstraction leakageWhen things go wrong, debugging through the layers is painful
Over-engineered for simple tasksA basic LLM call doesn't need LangChain
Rapid API changesBreaking changes between versions were common in early days (stabilising now)
Bundle sizeHeavy for frontend use — better kept on the backend
Learning curveLCEL, chains, runnables, agents — many concepts to learn upfront
"Magic" hides internalsEasy to copy-paste without understanding what's happening

My take: For anything beyond a single LLM call — RAG, agents, multi-step pipelines — LangChain is absolutely worth it. For a simple chatbot with no retrieval, just use the OpenAI SDK directly.


When to Use LangChain vs Not

USE LangChain when:
  ✅ Building RAG (document retrieval + QA)
  ✅ Building AI agents with tools
  ✅ Connecting multiple LLM calls in a pipeline
  ✅ Need to switch between LLM providers easily
  ✅ Need conversation memory
  ✅ Building production apps that need observability

SKIP LangChain when:
  ❌ Simple single-turn chatbot
  ❌ One-off script calling an LLM
  ❌ You just need one API call
  ❌ Bundle size is critical (e.g. edge functions)

What I'm Building Next

Now that I understand what LangChain solves and how it works, my next step is building the actual RAG pipeline — loading my interview prep markdown files, embedding them into Supabase, and building a chatbot that can answer questions from my own notes.

The architecture I'll implement:

My markdown files (50+ docs)
         ↓
LangChain Document Loaders + Text Splitters
         ↓
OpenAI text-embedding-3-small → vectors
         ↓
Supabase pgvector (stored)
         ↓
User question → embedding → similarity search → top 5 chunks
         ↓
Chunks injected into prompt → GPT-4o-mini → streamed answer
         ↓
React UI (in this portfolio site)

Post incoming once it's built. 🚀


Resources & Credits

ResourceAuthorLink
LangChain.js DocumentationLangChain Teamjs.langchain.com
RAG from Scratch (video course)AI JasonYouTube
LangChain GitHubHarrison Chase et al.github.com/langchain-ai/langchainjs
LCEL announcementLangChain Teamblog.langchain.dev
LangSmith (tracing/debugging)LangChain Teamsmith.langchain.com
ReAct: Synergizing Reasoning and ActingYao et al., Google Brain / PrincetonarXiv:2210.03629
OpenAI API ReferenceOpenAIplatform.openai.com/docs
LangChain critique (honest take)Hamel Husainhamel.dev

Part of my 6-month journey from full-stack developer to AI-native engineer. Follow along on GitHub.