This repository contains a basic Retrieval-Augmented Generation (RAG) system built using LangChain, ChromaDB, and Ollama. The goal is to demonstrate how to use a Large Language Model (LLM) to answer questions based on a custom knowledge base (PDF documents) running entirely locally.
- Custom Knowledge Base: Load your own PDF documents to create a domain-specific knowledge base.
- Local LLM and Embeddings: Utilizes Ollama to run both the embedding model (
nomic-embed-text) and the Large Language Model (mistral) locally on your machine, ensuring data privacy and reducing API costs. - Vector Database: Employs ChromaDB as a lightweight, local vector store to efficiently search and retrieve relevant document chunks.
- Modular Design: Separated concerns for embedding function, database population, and querying.
- Makefile for Convenience: Simple commands to set up the database and run the query agent.
Follow these steps to get your RAG system up and running.
Before you begin, ensure you have the following installed:
- Python 3.8+:
python3 --version
pip(Python package installer):pip --version
- Ollama: Download and install Ollama from ollama.com.
- Once installed, start the Ollama server in a dedicated terminal:
ollama serve
- Pull the necessary models:
ollama pull nomic-embed-text ollama pull mistral
- Once installed, start the Ollama server in a dedicated terminal:
-
Clone the Repository:
git clone https://github.com/callmemehdy/docAssistantChatBot.git cd docAssistantChatBot -
Create a Virtual Environment (Recommended):
python3 -m venv v_env source v_env/bin/activate # On Windows, use `v_env\Scripts\activate`
-
Install Python Dependencies:
pip install -r requirements.txt
- Create a folder named
datain the root of your project directory:mkdir data
- Place your PDF documents (
.pdffiles) that you want to query into thisdatafolder. For example:callmemehdy-docAssistantChatBot/ ├── data/ │ ├── my_document_1.pdf │ └── my_document_2.pdf └── ...
This step processes your PDF documents, splits them into manageable chunks, creates numerical embeddings for these chunks using nomic-embed-text, and stores them in a local ChromaDB instance.
-
Using
Makefile(Recommended):make setup_db
This will create a
chromadirectory in your project containing the vector database. -
Manually:
python3 ./src/pop_db.py
-
To reset and rebuild the database:
make reset_db # or manually: python3 ./src/pop_db.py --reset
Once the database is populated, you can start asking questions! The system will retrieve relevant information from your PDFs and use the mistral LLM to formulate an answer.
-
Using
Makefile(Recommended):make all
This will first ensure the database is set up, then start the interactive query agent.
-
Manually:
python3 ./src/evaluate_queries.py
The agent will prompt you with query:. Type your question and press Enter. To exit, type EXIT.
In case you feed the agent the MariaDB documentation PDF:
agent loading...
query: which port the mariadb service runs on?
you will get your response after a while...
Response: port 3306.
query: EXIT
Bye!