A powerful local RAG (Retrieval Augmented Generation) application that lets you chat with your PDF documents using Ollama and LangChain. This project includes both a Jupyter notebook for experimentation and a Streamlit web interface for easy interaction. Shout out to Tony Kipkemboi!
ollama_pdf_rag/
โโโ src/ # Source code
โ โโโ app/ # Streamlit application
โ โ โโโ components/ # UI components
โ โ โ โโโ chat.py # Chat interface
โ โ โ โโโ pdf_viewer.py # PDF display
โ โ โ โโโ sidebar.py # Sidebar controls
โ โ โโโ main.py # Main app
โ โโโ core/ # Core functionality
โ โโโ document.py # Document processing
โ โโโ embeddings.py # Vector embeddings
โ โโโ llm.py # LLM setup
โ โโโ rag.py # RAG pipeline
โโโ data/ # Data storage
โ โโโ pdfs/ # PDF storage
โ โ โโโ sample/ # Sample PDFs
โ โโโ vectors/ # Vector DB storage
โโโ notebooks/ # Jupyter notebooks
โ โโโ experiments/ # Experimental notebooks
โโโ tests/ # Unit tests
โโโ docs/ # Documentation
โโโ run.py # Application runner
- ๐ Fully local processing - no data leaves your machine
- ๐ PDF processing with intelligent chunking
- ๐ง Multi-query retrieval for better context understanding
- ๐ฏ Advanced RAG implementation using LangChain
- ๐ฅ๏ธ Clean Streamlit interface
- ๐ Jupyter notebook for experimentation
-
Install Ollama
- Visit Ollama's website to download and install
- Pull required models:
ollama pull llama3.2 # or your preferred model ollama pull nomic-embed-text
-
Clone Repository
git clone https://github.com/aghoshpro/OllamaRAG.git cd ollama_pdf_rag -
Set Up Environment
python -m venv myvenv
# On Windows .\myvenv\Scripts\activate **OR** # On Linux or Mac source myvenv/bin/activatepip install -r requirements.txt
python run.pyThen open your browser to local url http://localhost:8501
Streamlit interface showing ChatPDFx StreamLit App
jupyter notebookOpen updated_rag_notebook.ipynb to experiment with the code
- Upload PDF: Use the file uploader in the Streamlit interface or try the sample PDF
- Select Model: Choose from your locally available Ollama models
- Ask Questions: Start chatting with your PDF through the chat interface
- Adjust Display: Use the zoom slider to adjust PDF visibility
- Clean Up: Use the "Delete Collection" button when switching documents
- Ensure Ollama is running in the background
- Check that required models are downloaded
- Verify Python environment is activated
- For Windows users, ensure WSL2 is properly configured if using Ollama
DLL load failed while importing onnx_copy2py_export: a dynamic link Library (DLL) initialization routine failed.
Try these solutions:
-
Install Microsoft Visual C++ Redistributable:
- Download and install both x64 and x86 versions from Microsoft's official website
- Restart your computer after installation
-
If the error persists, try installing ONNX Runtime manually:
pip uninstall onnxruntime onnxruntime-gpu pip install onnxruntime
If you're running on a CPU-only system:
-
Ensure you have the CPU version of ONNX Runtime:
pip uninstall onnxruntime-gpu # Remove GPU version if installed pip install onnxruntime # Install CPU-only version
-
You may need to modify the chunk size in the code to prevent memory issues:
- Reduce
chunk_sizeto 500-1000 if you experience memory problems - Increase
chunk_overlapfor better context preservation
- Reduce
Note: The application will run slower on CPU-only systems, but it will still work effectively.
TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
Try this solution from stackoverflow:
-
Install tesseract using windows installer available at: https://github.com/UB-Mannheim/tesseract/wiki
-
Note the tesseract path from the installation C:\Program Files\Tesseract-OCR add it to system environmental variables path.
-
Restart the system to adapt the variable effect
-
Activate the
myenvand run the app again.
-
-
pip install pytesseract[OPTIONAL] -
Set the tesseract path in the script before calling image_to_string [OPTIONAL]
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\USER\AppData\Local\Tesseract-OCR\tesseract.exe'
Lookup error ... nltk.download('averaged_perceptron_tagger_eng') is not found
-
Add the following to
main.pyand run againimport nltk nltk.download('averaged_perceptron_tagger_eng')
# Run all tests
python -m unittest discover tests
# Run tests verbosely
python -m unittest discover tests -vThe project uses pre-commit hooks to ensure code quality. To set up:
pip install pre-commit
pre-commit installThis will:
- Run tests before each commit
- Run linting checks
- Ensure code quality standards are met
The project uses GitHub Actions for CI. On every push and pull request:
- Tests are run on multiple Python versions (3.9, 3.10, 3.11)
- Dependencies are installed
- Ollama models are pulled
- Test results are uploaded as artifacts
Feel free to:
- Open issues for bugs or suggestions
- Submit pull requests
- Comment on the YouTube video for questions
- Star the repository if you find it useful!
This project is open source and available under the MIT License.