A professional-grade Retrieval-Augmented Generation (RAG) application that leverages LangChain, Streamlit, and Ollama. This tool allows you to upload PDF documents and interact with their content locally using the Gemma:2b model.
The application is built using a modular design to ensure scalability and ease of maintenance.
- Frontend: Streamlit (Responsive web interface)
- Orchestration: LangChain (Managing the RAG pipeline)
- Local LLM: Ollama (Running Gemma:2b)
- Vector Database: Chroma (Storing and retrieving document embeddings)
├── app.py # Main Streamlit UI and session management
├── data_loaders/
│ └── DataLoader.py # logic for PDF extraction and temp file handling
├── transform/
│ ├── Splitter.py # Document chunking logic
│ └── Embeddings.py # Logic for creating and storing vectors
├── retriever/
│ └── Retrieval.py # RAG chain construction and prompt templates
└── requirements.txt # Project dependencies
DataLoader.py: Handles raw file bytes, saves them to a temporary file, and converts them into LangChain Document objects.
Splitter.py: Breaks large text into smaller segments (chunks). This is vital so the LLM context window isn't overwhelmed.
Embeddings.py: Uses Ollama to transform text chunks into mathematical vectors and stores them in a local Chroma database.
Retrieval.py: Defines how the system searches the database and structures the final prompt for the Gemma model.
Before running the app, ensure you have the following installed:
Python 3.9+
Ollama
Gemma Model: Pull the model locally by running:
ollama pull gemma:2b
Install Dependencies:
pip install -r requirements.txt
Run the App:
streamlit run app.py
Upload a PDF in the sidebar.
Wait for the "Finished!" or "Document indexed" success message.
Type your question in the main chat input.
Chat History: Implement StreamlitChatMessageHistory so the model remembers your previous questions in the same session.
Persistent Storage: Currently, the VectorDB is deleted when the session ends. You could update Embeddings.py to save the Chroma database to a local directory for permanent access.