This project implements a Retrieval-Augmented Generation (RAG) system that allows users to:
- Upload a PDF document
- Ask questions based on the document
- Get AI-generated answers using a local LLM
- Store chat history persistently using PostgreSQL
Unlike basic chatbot systems, this project combines:
- Vector search (FAISS)
- Embeddings (Sentence Transformers)
- Local LLM (Ollama)
- Persistent memory (PostgreSQL)
PDF → Text Extraction → Chunking → Embeddings → FAISS Index
↓
Query Embedding
↓
Relevant Chunk Retrieval
↓
Ollama (LLM) → Answer Generation
↓
PostgreSQL → Store History
- 📄 PDF-based question answering
- 🧠 Retrieval-Augmented Generation (RAG)
- 🤖 Local LLM using Ollama (no API cost)
- 🗄️ Persistent chat history (PostgreSQL)
- 👤 Multi-user support with session tracking
- ⚡ Fast similarity search using FAISS
- Python 3.10
- PyMuPDF (PDF processing)
- FAISS (vector search)
- Sentence Transformers (embeddings)
- Ollama (local LLM)
- PostgreSQL (database)
git clone https://github.com/your-username/rag-pdf-system.git
cd rag-pdf-systempython -m venv venv
venv\Scripts\activatepip install -r requirements.txtCreate database:
CREATE DATABASE ragdb;Update credentials in code:
DB_CONFIG = {
"dbname": "ragdb",
"user": "postgres",
"password": "your_password",
"host": "localhost",
"port": "5432"
}Download from: https://ollama.com/download
Run:
ollama pull llama3.2Ollama runs automatically in the background.
Run the script:
python rag_postgres.pyFollow prompts:
Enter PDF path
Enter user ID (e.g., user1)
Ask questions
- What is Artificial Intelligence?
- Summarize the document
- Explain Machine Learning
Table: userchat_history
| Column | Type |
|---|---|
| id | SERIAL |
| user_id | TEXT |
| session_id | TEXT |
| question | TEXT |
| answer | TEXT |
| timestamp | TIMESTAMP |
- Ensure the PostgreSQL service is running
- Ollama must be installed and running
- First-time model download may take time
- Multi-PDF support
- Web UI (Streamlit / React)
- pgvector integration
- Source highlighting
- API deployment (FastAPI)
This project is for educational purposes.