Skip to content

RAG (Retrieval-Augmented Generation) chatbot using LangChain, ChromaDB, and Ollama for local document querying. Features custom knowledge base from PDFs, local LLM with mistral, vector storage, and modular architecture.

Notifications You must be signed in to change notification settings

callmemehdy/docAssistantChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Simple RAG System with LangChain and Ollama

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.

✨ Features

  • 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.

🚀 Getting Started

Follow these steps to get your RAG system up and running.

Prerequisites

Before you begin, ensure you have the following installed:

  1. Python 3.8+:
    python3 --version
  2. pip (Python package installer):
    pip --version
  3. 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

Installation

  1. Clone the Repository:

    git clone https://github.com/callmemehdy/docAssistantChatBot.git
    cd docAssistantChatBot
  2. Create a Virtual Environment (Recommended):

    python3 -m venv v_env
    source v_env/bin/activate  # On Windows, use `v_env\Scripts\activate`
  3. Install Python Dependencies:

    pip install -r requirements.txt

Prepare Your Data

  1. Create a folder named data in the root of your project directory:
    mkdir data
  2. Place your PDF documents (.pdf files) that you want to query into this data folder. For example:
    callmemehdy-docAssistantChatBot/
    ├── data/
    │   ├── my_document_1.pdf
    │   └── my_document_2.pdf
    └── ...
    

Populate the Database

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 chroma directory 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

💬 Querying the System

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.

Example Interaction

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!

About

RAG (Retrieval-Augmented Generation) chatbot using LangChain, ChromaDB, and Ollama for local document querying. Features custom knowledge base from PDFs, local LLM with mistral, vector storage, and modular architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published