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.
- 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.
- LLM: Ollama (Running Phi-3 )
- Orchestration: LangChain
- Vector DB: FAISS
- Embeddings:
all-MiniLM-L6-v2(HuggingFace Transformers) - Document Parsing:
PyPDF
- Python 3
- Ollama installed on your machine.
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_choicegit 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.txtEnsure 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
- Place the PDF you want to learn from inside the
files/folder. - Open
main.pyand update thePDF_PATHvariable with your filename. - Run the tutor:
python3 main.py- Ingestion: The app loads your PDF and splits it into chunks of 1000 characters.
- Embedding: Chunks are converted into 384-dimensional vectors using HuggingFace models.
- Storage: Vectors are saved locally to
vector_db_cachefor instant reloading. - Retrieval: When you ask a question, the system finds the most relevant sections of the PDF.
- Generation: The AI tutor receives the question + the relevant text and streams a structured response.