This application allows you to ask questions about your PDF documents and get relevant answers. It uses AI to understand your PDFs and provide accurate responses based on their content.
Clone the repository:
git clone https://github.com/mshojaei77/ollama_rag.git
cd ollama_ragThe cloned repository includes a sample PDF and embedding cache about MCP for testing.
Before you start, you'll need to:
- Have Python installed on your computer (version 3.8 or higher)
- Have Ollama installed on your computer
- Visit Ollama's website
- Download and install Ollama for your operating system (Windows/Mac/Linux)
Open your terminal/command prompt and run:
ollama pull nomic-embed-text
ollama pull gemma3:1bIn your terminal/command prompt, run:
pip install -r requirements.txt- Place your PDF files in the
knowledge_basefolder - The repository includes a sample PDF about MCP for testing
- Open
rag.pyin a text editor - Modify this line near the bottom:
response = rag_system.query("What is the purpose of the MCP?")
- Replace with your question
- Run the program:
python rag.py
Try these questions with the sample MCP document:
- "What is the purpose of the MCP?"
- "What are the main components of MCP?"
- "How does MCP handle process scheduling?"
Or use your own questions for your PDFs:
- "What are the main points of chapter 1?"
- "Can you summarize the conclusion?"
- "What does the document say about X?"
The system uses these default settings (configurable in RAGConfig):
- Embedding Model: nomic-embed-text
- LLM Model: gemma3:1b
- Chunk Size: 1000
- Chunk Overlap: 50
- Top K Results: 2
- Batch Size: 10
ollama_rag/
│
├── knowledge_base/ (PDF documents)
│ └── mcp.pdf (Sample PDF)
│
├── embeddings/ (Cached embeddings)
├── rag.py (Main program)
└── requirements.txt (Required packages)
- First-time queries may take longer due to PDF processing
- PDFs must be text-based (not scanned images)
- Answer quality depends on the chosen LLM
- Keep questions clear and specific
If you encounter issues:
- Ensure Ollama is running
- Verify PDFs are in the
knowledge_basefolder - Check all installation steps are complete
- Try restarting your computer if Ollama isn't responding
Feel free to:
- Open issues
- Submit pull requests
- Fork the repository
- Star the project if you find it useful