A Retrieval-Augmented Generation (RAG) application using LangChain, OpenSearch, and Ollama for local LLM inference.
This project implements a document processing and question-answering system that:
- Processes documents from various formats (PDF, TXT, MD, PY)
- Generates embeddings using local models via Ollama
- Stores document chunks and embeddings in OpenSearch
- Provides a Gradio web interface for document upload and querying
- Uses Redis for caching to improve performance
The system consists of the following components:
- App Service: Python application with Gradio web interface
- OpenSearch: Vector database for storing document embeddings
- OpenSearch Dashboards: Web interface for OpenSearch management
- Redis: Caching layer that saves metadata from processed documents
- Ollama: Local inference for embeddings and LLM responses
- Docker and Docker Compose
- Ollama installed locally (optional, can use containerized version)
- At least 8GB RAM for running all services
- Git
-
Clone the repository:
git clone https://github.com/yourusername/langchain-opensearch-rag.git cd langchain-opensearch-rag
-
Create a
.env
file in theinfra/secrets
directory:mkdir -p infra/secrets touch infra/secrets/.env
-
Start the services:
docker-compose -f infra/docker-compose.yml up -d
-
Access the web interface at http://localhost:8081
Key environment variables that can be configured:
Variable | Description | Default |
---|---|---|
OLLAMA_HOST | URL for Ollama API | http://host.docker.internal:11434 |
EMBEDDINGS_MODEL | Model for generating embeddings | mxbai-embed-large |
LLM_MODEL | Model for text generation | phi3.5 |
OPENSEARCH_URL | URL for OpenSearch | http://opensearch:9200 |
REDIS_HOST | Hostname for Redis | redis |
CHUNK_SIZE | Size of document chunks | 1000 |
CHUNK_OVERLAP | Overlap between chunks | 200 |
The default configuration uses your local Ollama installation. Make sure Ollama is running:
ollama serve
And that you have the required models:
ollama pull mxbai-embed-large
ollama pull phi3.5
- Upload Documents: Use the web interface to upload documents (PDF, TXT, MD, PY)
- Process Documents: The system will chunk, embed, and store the documents
- Ask Questions: Query the system about the content of your documents
- View Sources: See which document chunks were used to generate the answer
langchain-opensearch-rag/
├── infra/ # Infrastructure configuration
│ ├── docker-compose.yml # Docker Compose configuration
│ ├── redis/ # Redis configuration
│ └── scripts/ # Helper scripts
├── src/ # Source code
│ └── app/ # Application code
│ ├── loader/ # Document loading and processing
│ ├── ui/ # Gradio UI components
│ └── main.py # Application entry point
└── README.md # This file
To develop locally:
-
Create a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python src/app/main.py
- Redis Connection Issues: Ensure Redis is running and accessible from the app container
- Ollama Connection Issues: Verify Ollama is running and the OLLAMA_HOST is correctly set
- OpenSearch Connection Issues: Check OpenSearch logs and ensure it's healthy
To view logs:
# All services
docker-compose -f infra/docker-compose.yml logs -f
# Specific service
docker-compose -f infra/docker-compose.yml logs -f app