LangChain Examples
December 4, 2025 ยท View on GitHub
Updated 2025: This directory contains example implementations using LangChain, a framework for building applications with LLMs.
LangChain v1.0 (October 22, 2025): LangChain reached v1.0, providing a standard tool calling architecture, provider-agnostic design, and middleware for production deployments. Key features include create_agent abstraction, standard content blocks, streamlined package surface area, and Python 3.10+ requirement (3.9 support dropped). It positions itself as the fastest way to build an AI agent with maximum control over workflows across any model/provider.
MultiModal RAG Example
The multimodal_rag.py example demonstrates how to build a Retrieval-Augmented Generation (RAG) system that can handle both text and images. It uses:
- GPT-4 Vision for image understanding
- ChromaDB for vector storage
- LangChain's document loaders for text and images
- Recursive text splitting for efficient chunking
Prerequisites
- Python 3.9+
- OpenAI API key
- Tesseract OCR (for image text extraction)
- Required packages (install using
pip install -r requirements.txt)
Setup
- Create a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Install Tesseract OCR:
- On macOS:
brew install tesseract - On Ubuntu:
sudo apt-get install tesseract-ocr - On Windows: Download from GitHub
- Set your OpenAI API key:
export OPENAI_API_KEY=your_api_key_here
Usage
- Create a
datadirectory and add your documents:
mkdir data
# Add .txt files for text documents
# Add .png, .jpg, or .jpeg files for images
- Run the example:
python multimodal_rag.py
Features
- Multi-modal Document Loading: Handles both text and image files
- Vector Storage: Uses ChromaDB for efficient document storage and retrieval
- Text Splitting: Implements recursive text splitting for optimal chunking
- Vision Capabilities: Uses GPT-4 Vision for image understanding
- Persistence: Saves the vector store for future use
Example Queries
The example includes sample queries:
- "What is shown in the images?"
- "Can you describe the main topics in the text documents?"
- "What are the key points from both text and images?"
Customization
You can customize the implementation by:
- Modifying the prompt template in
_create_rag_chain() - Adjusting chunk size and overlap in the text splitter
- Adding more document loaders for different file types
- Implementing custom retrieval strategies
Notes
- The system uses GPT-4 Vision for image understanding, which requires an OpenAI API key
- Image processing may be slow depending on the size and number of images
- Text extraction from images depends on Tesseract OCR quality