VOOZH about

URL: https://www.geeksforgeeks.org/artificial-intelligence/modules-of-langchain/

โ‡ฑ Modules of LangChain - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Modules of LangChain

Last Updated : 23 Jul, 2025

LangChain is a modular framework designed to build applications powered by large language models (LLMs). Its architecture allows developers to integrate LLMs with external data, prompt engineering, retrieval-augmented generation (RAG), semantic search, and agent workflows. Below is a detailed walkthrough of LangChainโ€™s main modules, their roles, and code examples, following the latest practices and your provided context.

LangChainโ€™s modularity enables:

  • Flexible prompt creation and chaining.
  • Integration with various LLMs (OpenAI, Anthropic, Gemini etc).
  • Parsing and structuring LLM outputs.
  • Retrieval-augmented generation (RAG) for grounding responses in external data.
  • Semantic search using embeddings and vector databases.
  • Agentic workflows for multi-step reasoning and tool use.

1. Prompt Module

Purpose : Structure and format user input into prompts that LLMs can interpret, supporting both plain text and chat-based roles.

Types:

  • PromptTemplate: For single-turn, string-based prompts.
  • ChatPromptTemplate: For multi-turn, role-based conversations.

Output

๐Ÿ‘ Prompt
Prompt Output


2. Chat Model and LLM Module

Purpose : Interface with LLMs for text or chat completion. Supports providers like OpenAI, Anthropic, Gemini, etc.

Example (Gemini 2.0 Flash):

Output

๐Ÿ‘ Chat-Model
Chat Model and LLM Module


3. Output Parser Module

Purpose : Parse and structure the raw output from LLMs into usable formats (e.g., extracting values, JSON, or structured text).

Output

๐Ÿ‘ Output
Output Parser

4. Retrieval-Augmented Generation (RAG) Module

Purpose : Augment LLM outputs by retrieving relevant data from external sources (HTML, DOC, S3, web buckets, etc.) and injecting it into prompts.

๐Ÿ‘ How-Rag-works
Retrieval-Augmented Generation (RAG)

Components:

  • Document loaders: Ingest data from HTML, DOC, S3, etc.
  • Embeddings: Convert documents to semantic vectors.
  • Vector database: Store vectors for similarity search (e.g., FAISS, Pinecone).
  • Retriever: Finds relevant docs for a query.
  • LLM Integration: Supplies retrieved content as context.

Output

๐Ÿ‘ RAG
RAG Module

5. Embedding & Vector Database Module

Purpose:

  • Embeddings: Capture semantic meaning of text for similarity search.
  • Vector DB: Store and index embeddings for fast retrieval.

6. Data Storage (HTML, DOC, S3, Web Buckets)

Purpose : Store and manage unstructured data for retrieval. LangChain supports loading documents from HTML, DOC, S3, and web buckets, which are then embedded and stored in a vector DB(database) for RAG.

7. Agent Module

Purpose : Enable autonomous, multi-step reasoning by chaining LLM calls with tool use (calculators, web search, database queries, etc).

๐Ÿ‘ ai2
AI Agent

Example:

Output

๐Ÿ‘ Agent-module
Agent Module

Colab link:Modules of LangChain

Comment
Article Tags:

Explore