Skip to content

HirthikBalaji/PDF_CHATBOT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📄 Syllabus Q&A Bot using LangChain, FAISS, and Ollama

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.


🔧 Features

  • Loads a syllabus.pdf using PyMuPDF
  • 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

📁 File Structure

├── syllabus.pdf             # The syllabus document (you need to place it here)
├── main.py                  # The script described below
└── README.md                # You're reading this file

🚀 Getting Started

1. Install Dependencies

Make sure you have Python 3.8+ installed, then install the required libraries:

pip install langchain langchain-community faiss-cpu PyMuPDF langchain-huggingface langchain-ollama

2. Set Up Ollama

Download and install Ollama. Then pull the required model:

ollama pull llama3

Ensure ollama is running in the background.


🧠 How It Works

  1. Loads and reads syllabus.pdf
  2. Splits the document into 500-character chunks (with 100-character overlap)
  3. Generates vector embeddings using all-MiniLM-L6-v2
  4. Stores them in a FAISS vector database
  5. Uses LLaMA3.2 model from Ollama to answer user queries
  6. Retrieves top 3 most relevant chunks as context

▶️ Running the Script

python main.py

You'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...

🛠 Customization

  • Change PDF: Replace syllabus.pdf with 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 to mmr search for diversity.

✅ Requirements

  • Python 3.8+
  • Ollama installed and running
  • syllabus.pdf placed in the working directory

📌 Notes

  • 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+C to exit.

📜 License

This project is free to use under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages