Skip to content

KBismark/pdf-tutor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdf-tutor 🎓

A RAG-based Generative AI tutor for providing interactive document assistance. Ask questions about your documents, research papers or technical manuals and receive an instant response locally.


Features

  • Context-Aware Learning (RAG): Uses a vector database to get answers from the provided document.
  • Vector Persistence: Caches document embeddings locally using FAISS, making subsequent queries on the same document instant.

Tech Stack

  • LLM: Ollama (Running Phi-3 )
  • Orchestration: LangChain
  • Vector DB: FAISS
  • Embeddings: all-MiniLM-L6-v2 (HuggingFace Transformers)
  • Document Parsing: PyPDF

Local Setup

1. Prerequisites

  • Python 3
  • Ollama installed on your machine.

2. Install AI Models

Open your terminal and pull the models required. I currently use phi3 because it's fast on my 8GB RAM MacBook. You can choose other models available on Ollama. E.g. Llama 3.1 and replace the model name in the main.py to 'llama3.1':

ollama pull phi3

# Or 
ollama pull the_model_name_of_your_choice

3. Clone and Install Dependencies

git clone https://github.com/kbismark/pdf-tutor.git
cd pdf-tutor

# Create a virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install required packages
pip install -r requirements.txt

4. Folder Structure

Ensure your directory looks like this:

pdf-tutor/
├── files/
│   └── your_document_name.pdf  <-- Place your PDF here. You will find "sql.pdf" there used for the demo.
├── vector_db_cache/       <-- Generated automatically on first run
├── main.py
└── requirements.txt

Usage

  1. Place the PDF you want to learn from inside the files/ folder.
  2. Open main.py and update the PDF_PATH variable with your filename.
  3. Run the tutor:
python3 main.py

How it works under the hood:

  1. Ingestion: The app loads your PDF and splits it into chunks of 1000 characters.
  2. Embedding: Chunks are converted into 384-dimensional vectors using HuggingFace models.
  3. Storage: Vectors are saved locally to vector_db_cache for instant reloading.
  4. Retrieval: When you ask a question, the system finds the most relevant sections of the PDF.
  5. Generation: The AI tutor receives the question + the relevant text and streams a structured response.

About

A RAG-based Generative AI tutor for providing interactive document assistance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages