This is a simple Retrieval-Augmented Generation (RAG) pipeline that allows users to ask context-specific questions about a syllabus document (PDF). It leverages the LangChain framework with FAISS for vector storage, HuggingFace for embeddings, and Ollama to run the LLaMA3.2 model locally.
- Loads a
syllabus.pdfusingPyMuPDF - Splits the text into manageable chunks for embedding
- Generates dense vector embeddings using HuggingFace's
all-MiniLM-L6-v2 - Stores and retrieves chunks via FAISS similarity search
- Uses Ollama's LLaMA3.2 model for answering questions
- Continuously answers syllabus-related questions in a loop
├── syllabus.pdf # The syllabus document (you need to place it here)
├── main.py # The script described below
└── README.md # You're reading this file
Make sure you have Python 3.8+ installed, then install the required libraries:
pip install langchain langchain-community faiss-cpu PyMuPDF langchain-huggingface langchain-ollamaDownload and install Ollama. Then pull the required model:
ollama pull llama3Ensure
ollamais running in the background.
- Loads and reads
syllabus.pdf - Splits the document into 500-character chunks (with 100-character overlap)
- Generates vector embeddings using
all-MiniLM-L6-v2 - Stores them in a FAISS vector database
- Uses LLaMA3.2 model from Ollama to answer user queries
- Retrieves top 3 most relevant chunks as context
python main.pyYou'll see a prompt like:
Question:
Ask your syllabus-related question and get a crisp, context-aware answer.
Example:
Question: Do we study about drones in the course?
Answer: Yes, we do learn about drones...
- Change PDF: Replace
syllabus.pdfwith any document. - Switch Models: Modify the embedding or LLM model to suit your performance needs.
- Tweak Retriever: Adjust the number of returned documents (
k) or switch tommrsearch for diversity.
- Python 3.8+
- Ollama installed and running
syllabus.pdfplaced in the working directory
- The prompt in the script is wrapped with:
"And only Crisp to the Question asked only with respect to the context:\n\nQuestion: ..."This ensures responses are concise and context-bound. - The script runs in an infinite loop; press
Ctrl+Cto exit.
This project is free to use under the MIT License.