Skip to content

Langchain

  • 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.


  • 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.


  • Unified API to call models (OpenAI, Hugging Face, Cohere, Anthropic).

  • Abstraction for switching between models easily.

  • Standardized way to create structured prompts with variables.

  • Example: “Answer the question based on context: {context} Question: {question}”.

  • Sequential pipelines combining prompts, LLMs, and logic.

  • Example:

    1. Retrieve docs →

    2. Summarize →

    3. Generate answer.

  • LLMs that decide which tools to call and in what sequence.

  • Tools = APIs, calculators, DB queries.

  • Example: Agent decides: “Search → Retrieve → Generate.”

  • Store conversation history or intermediate data.

  • Types:

    • ConversationBufferMemory (stores full history).

    • ConversationSummaryMemory (summarized context).

    • VectorStoreRetrieverMemory (semantic memory).

  • Connect LLMs with external knowledge bases.

  • Vector stores: FAISS, Pinecone, Weaviate, Chroma.

  • Used in RAG pipelines.


  1. User Query →

  2. Retriever finds relevant docs →

  3. LLM processes docs with prompt →

  4. Chain executes reasoning →

  5. Memory stores context →

  6. Final Answer returned.


  • 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.


  • Modular (LLM + Retriever + Memory + Tools).

  • Easy integration with multiple backends (OpenAI, HuggingFace, APIs).

  • Supports RAG, multi-step reasoning, tool usage.

  • Fast-growing ecosystem.


  • Complexity (can get heavy for simple tasks).

  • Still experimental, frequent updates.

  • Performance depends on external LLM + retriever quality.


  • 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?