Langchain
1. Definition
Section titled “1. Definition”-
LangChain = an open-source framework for building applications using LLMs (Large Language Models) with context, memory, and external integrations.
-
Provides tools to connect LLMs with data sources, APIs, and reasoning workflows.
2. Motivation
Section titled “2. Motivation”-
LLMs are powerful but limited:
-
Can hallucinate.
-
Lack memory of past interactions.
-
Cannot access private or dynamic data directly.
-
-
LangChain solves this by adding retrieval, memory, and orchestration.
3. Core Components
Section titled “3. Core Components”a) LLM Wrappers
Section titled “a) LLM Wrappers”-
Unified API to call models (OpenAI, Hugging Face, Cohere, Anthropic).
-
Abstraction for switching between models easily.
b) Prompt Templates
Section titled “b) Prompt Templates”-
Standardized way to create structured prompts with variables.
-
Example:
“Answer the question based on context: {context} Question: {question}”.
c) Chains
Section titled “c) Chains”-
Sequential pipelines combining prompts, LLMs, and logic.
-
Example:
-
Retrieve docs →
-
Summarize →
-
Generate answer.
-
d) Agents
Section titled “d) Agents”-
LLMs that decide which tools to call and in what sequence.
-
Tools = APIs, calculators, DB queries.
-
Example: Agent decides: “Search → Retrieve → Generate.”
e) Memory
Section titled “e) Memory”-
Store conversation history or intermediate data.
-
Types:
-
ConversationBufferMemory (stores full history).
-
ConversationSummaryMemory (summarized context).
-
VectorStoreRetrieverMemory (semantic memory).
-
f) Retrievers & Vector Stores
Section titled “f) Retrievers & Vector Stores”-
Connect LLMs with external knowledge bases.
-
Vector stores: FAISS, Pinecone, Weaviate, Chroma.
-
Used in RAG pipelines.
4. LangChain Workflow Example
Section titled “4. LangChain Workflow Example”-
User Query →
-
Retriever finds relevant docs →
-
LLM processes docs with prompt →
-
Chain executes reasoning →
-
Memory stores context →
-
Final Answer returned.
5. Use Cases
Section titled “5. Use Cases”-
Chatbots (with memory + external data).
-
RAG (Retrieval-Augmented Generation) systems.
-
Question Answering over documents.
-
Code assistants.
-
Agents for automation (tool-using LLMs).
-
Knowledge management in enterprises.
6. Advantages
Section titled “6. Advantages”-
Modular (LLM + Retriever + Memory + Tools).
-
Easy integration with multiple backends (OpenAI, HuggingFace, APIs).
-
Supports RAG, multi-step reasoning, tool usage.
-
Fast-growing ecosystem.
7. Limitations
Section titled “7. Limitations”-
Complexity (can get heavy for simple tasks).
-
Still experimental, frequent updates.
-
Performance depends on external LLM + retriever quality.
8. Related Tools
Section titled “8. Related Tools”-
LlamaIndex (GPT Index): Focused on document ingestion & retrieval.
-
Haystack: Similar framework for RAG & QA.
-
Semantic Kernel (Microsoft): Orchestration like LangChain.
Do you want me to also prepare a short 1-page revision version of LangChain (just bullets: components + use cases + advantages) for quick exam recall?