Welcome! This repository contains a complete document question-answering system that lets you upload PDF documents and then ask questions about them using AI. The system uses Retrieval-Augmented Generation (RAG) to provide accurate, contextual answers based on your documents.
Think of this as your personal research assistant that can read through your documents and answer questions about them. Here's the simple process:
- Upload Documents: You give the system PDF files to read and understand
- Ask Questions: You ask questions in natural language about those documents
- Get Answers: The AI provides answers based specifically on your document content
The system works by converting your documents into mathematical representations (vectors) that capture their meaning, then finding the most relevant parts when you ask questions.
This repository contains four main parts that work together:
This script takes your PDF files and prepares them for the AI system. It:
- Reads PDF files and extracts all the text content
- Breaks large documents into smaller, manageable chunks
- Converts the text into numerical vectors that capture meaning
- Stores everything in a searchable database
This part teachs the system to "read" and "understand" your documents.
This script lets you ask questions about your uploaded documents. It:
- Takes your question and converts it to the same vector format
- Searches through your documents to find the most relevant sections
- Combines the relevant content with your question
- Uses AI to generate a comprehensive answer
This will initiate the AI Assistant which can instantly find and summarize relevant information.
This provides a user-friendly browser interface that combines both document upload and question answering in one place. It:
- Offers a clean chat interface for asking questions
- Provides drag-and-drop file upload with progress tracking
- Shows real-time processing status
- Displays conversation history and source attribution
Think of this as: A complete web application that makes the system accessible to anyone through their browser.
Drag and drop interface for easy document upload
Interactive chat interface for asking questions about your documents
README_MAC_SETUP.md: Complete setup instructions for macOSSCRIPT_USAGE.md: Detailed guide for uploading documentsQUERY_USAGE.md: Detailed guide for asking questionsWEB_INTERFACE_GUIDE.md: Complete guide for using the web interface
You'll need to have Ollama running with the qwen3:0.6b model. The README_MAC_SETUP.md file has complete installation instructions, but here's the short version:
# Install and start Ollama with Docker
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
docker exec ollama ollama pull qwen3:0.6b- Set up your environment (one time only):
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Upload a document (repeat for each PDF):
python3 upload_and_embed_pdf.py /path/to/your/document.pdf- Ask questions - you have two options:
Option A: Use the web interface (recommended for most users):
python3 web_app.pyThen open your browser to http://localhost:5000 for a complete web interface.
Option B: Use command line:
python3 query_documents.py "What is the main topic of the document?"Or start an interactive conversation:
python3 query_documents.py --interactiveThe easiest way to use the system is through the web interface:
python3 web_app.pyThen open http://localhost:5000 in your browser. The web interface provides:
- Upload Page: Drag-and-drop PDF upload with progress tracking
- Chat Interface: Ask questions with a clean, easy-to-use chat interface
- Real-time Status: See processing progress and system status
- Source Attribution: Know which documents your answers come from
# Upload a research paper
python3 upload_and_embed_pdf.py ~/Documents/research_paper.pdf
# Upload an experiment protocol
python3 upload_and_embed_pdf.py ~/Downloads/protocol_rna_extraction.pdf
# Upload with verbose logging to see progress
python3 upload_and_embed_pdf.py --verbose ~/Documents/report.pdf# Ask about main topics
python3 query_documents.py "What are the key findings?"
# Ask for specific information
python3 query_documents.py "What methodology was used in this study?"
# Ask for practical information
python3 query_documents.py "How do I configure the system?"
# Get more context by retrieving more document chunks
python3 query_documents.py --max-results 5 "What are all the requirements?"For a conversation-like experience:
python3 query_documents.py --interactiveThis starts a chat interface where you can ask follow-up questions and explore your documents naturally.
A well-set up directory will look like this:
ai_research_assistant_rag/
├── upload_and_embed_pdf.py # Script to process PDF documents
├── query_documents.py # Script to ask questions
├── web_app.py # Web interface application
├── templates/ # HTML templates for web interface
│ ├── base.html # Base template
│ ├── index.html # Chat interface
│ └── upload.html # Upload page
├── requirements.txt # Python dependencies
├── README_MAC_SETUP.md # Installation instructions
├── SCRIPT_USAGE.md # Upload script documentation
├── QUERY_USAGE.md # Query script documentation
├── WEB_INTERFACE_GUIDE.md # Web interface guide
├── chromadb_storage/ # Database where document vectors are stored
└── your_documents.pdf # Your uploaded PDF files
- Documents up to 100MB in size
- PDFs with clear text content (not just images)
- Technical documents, research papers, manuals, reports
- Questions about specific content in your documents
- Only processes PDF files (not Word docs, web pages, etc.)
- Works best with text-based PDFs (scanned images may not work well)
- CPU-only processing (slower than GPU but still effective)
- Maximum 1000 pages per document
- Use clear, specific questions
- If you don't get good results, try rephrasing your question
- For large documents, the system automatically breaks them into chunks
- Multiple shorter documents often work better than one very long document
You need to upload documents first:
python3 upload_and_embed_pdf.py /path/to/document.pdf- Try different keywords or phrasing
- Make sure your documents contain information related to your question
- Use
--verboseto see what the system is finding
Make sure Ollama is running:
docker ps # Should show ollama container
docker start ollama # If it's not running- Make sure the PDF file exists and isn't corrupted
- Try using
--verboseto see detailed processing information - Very large files may need to be split into smaller parts
If you run into issues:
- Check the detailed documentation: Each script has its own detailed usage guide
- Use verbose mode: Add
--verboseto see what's happening - Verify prerequisites: Make sure Ollama is running and models are downloaded
- Check file paths: Ensure your PDF files exist and are accessible
# Process all PDFs in a directory
for pdf in *.pdf; do
python3 upload_and_embed_pdf.py "$pdf"
doneThe system is configured to use qwen3:0.6b for both embedding and chat, which works well on CPU. If you have other models available in Ollama, you can modify the model names in the script configuration sections.
Both scripts have configuration constants at the top that you can modify:
- Chunk sizes for document processing
- Number of results returned from searches
- Context limits for AI responses
- Database storage locations
This system is designed to be easily understandable and modifiable. The code includes extensive comments explaining how each part works. Feel free to:
- Modify the scripts for your specific needs
- Add support for other document types
- Experiment with different AI models
- Enhance the user interface
The goal is to provide a solid foundation that you can build upon for your specific use cases.
I hope this system helps you work more effectively with your documents. The combination of semantic search and AI generation can be quite powerful for research, analysis, and information retrieval tasks.