
TL;DR
You’ll build an offline AI chatbot that answers questions from your PDFs using local embeddings and a local LLM. Your documents stay on your machine. This guide covers setup, retrieval quality, evaluation, performance, and realistic privacy limits.
Github Link:
GitHub - sarveshtalele/personal-finance-using-RAG-level-1
Who This Is For
- Beginners who want to learn RAG end-to-end
- Engineers building privacy-first systems
- Anyone who wants an offline, ChatGPT-like assistant for personal documents
What Problem Are We Solving?
Cloud AI tools require uploading documents. For personal, legal, or internal files, that introduces privacy, compliance, and cost risks. A local RAG system lets you:
- Keep data on your machine
- Avoid API costs
- Work offline (after models download)
- Control models, storage, and evaluation
This is especially useful for PDFs: contracts, research papers, manuals, or financial records.
Core Concepts (Beginner-Friendly)
LLM (Large Language Model)
Generates text. Examples: phi-3 (fast, smaller), llama3 (larger, stronger reasoning).
Embeddings
Numeric vectors that represent the meaning of text. Used for semantic search.
Vector Database
Stores embeddings and retrieves the most relevant chunks (e.g., ChromaDB).
RAG (Retrieval-Augmented Generation)
Instead of guessing, the model answers using retrieved document context. This reduces hallucinations.
Why RAG Matters
LLMs alone can hallucinate. RAG grounds answers in your actual documents.
Architecture (Simple Mental Model)
User
↓
Streamlit UI
↓
FastAPI
↓
ChromaDB (Vector Search)
↓
Ollama (Local LLM)
↓
Answer + Sources
Tools
- UI: Streamlit
- API: FastAPI
- Retrieval: ChromaDB
- Models: Ollama (phi-3 + nomic-embed-text)
Step-by-Step Implementation (From Zero)
Step 1: Install Prerequisites
- Python 3.11+
- Ollama
ollama pull phi3
ollama pull nomic-embed-text
Model choice rationale
- phi-3: fast and lightweight (great for laptops).
- llama3: higher quality, more RAM/CPU.
- Choose based on latency vs. answer quality.
Step 2: Project Setup
git clone https://github.com/sarveshtalele/personal-finance-using-RAG-level-1.git
cd personal-finance-using-RAG-level-1
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
Reproducibility
- Pin model versions in ollama pull
: - Lock Python deps with requirements.txt or pip-tools
Step 3: Add Your PDFs
Place documents in:
data/
When documents change:
rm -rf vectordb/
This forces re-indexing. For production, use versioned collections instead of deleting everything.
Step 4: Start Services
uvicorn app.main:app --reload
streamlit run streamlit_app.py
Open the Streamlit UI and start querying your documents.
How Retrieval Works (Under the Hood)
- PDFs → text
- Text → chunks (e.g., 500 tokens with 50 overlap)
- Chunks → embeddings
- Query → embedding
- Similarity search → top-k chunks
- LLM answers using retrieved context
Chunking matters
- Too large → retrieval misses specifics
- Too small → loss of context
- Start with 300–600 tokens + 10–20% overlap
Improving Answer Quality (Important)
Add basic controls to reduce hallucinations:
- Similarity threshold (e.g., >= 0.7)
- Return sources with each answer
- If no relevant context is found → respond: “I don’t know based on your documents.”
- Prompt guardrail: “Only answer using the provided context.”
Failure mode to handle
When retrieval confidence is low, refuse to answer instead of guessing.
Evaluation: Don’t Skip This
Create a small manual test set:
- 10–20 real questions
- Expected answers + source references
- Log failures
- Wrong chunk retrieved
- No chunk retrieved
- Hallucinated answer
This loop is how RAG systems improve in practice.
Performance & Hardware Guidance
- 8 GB RAM minimum
- 16 GB RAM recommended
- CPU works; GPU improves latency
- Smaller models → faster, less accurate
- Larger models → slower, more accurate
Benchmarks to track
- Index time
- Query latency
- Retrieval time
- Answer accuracy on your test set
Security & Privacy
Local-first reduces cloud exposure, but it is not absolute security:
- Malware can access local files
- OS backups may sync data
- Logs can store queries
- Crash dumps may include prompts
Recommendations
- Encrypt sensitive files at rest
- Avoid logging raw queries
- Run on a dedicated user account
- Treat “local” as privacy-by-design, not air-gapped security
Common Beginner Mistakes
- Chunk size too large → poor retrieval
- No overlap → context loss
- No evaluation → silent hallucinations
- Re-ingesting on every query
- Using LLM without RAG for document Q&A
Extensions (When You’re Ready)
- CSV ingestion (bank exports, logs)
- Hybrid search (BM25 + vectors)
- Rerankers for better top-k results
- Multi-user auth
- Source citations in UI
- Automated evaluation pipelines
FAQ (Featured Snippet-Friendly)
Is local RAG better than cloud RAG?
For privacy and cost control, yes. For scale and managed infra, cloud may be easier.
Can this replace ChatGPT?
For private document Q&A, yes. For general reasoning and broad knowledge, we have to perform Fine-tuining on model to improve accuracy.
Does this work offline?
Yes, after models are downloaded.
Limitations
- Local models are weaker than GPT-4-class models but can be imporved by fine-tuning
- No built-in access control
- Requires basic ML engineering skills
- Vector DB versioning must be handled manually
Conclusion
Local RAG gives you control over data, cost, and privacy. This stack — Ollama, ChromaDB, FastAPI, Streamlit — is a strong foundation for private document intelligence. With evaluation, security hardening, and UX improvements, it can move from a demo to a production-ready internal tool.
Get the Code (Free & Open Source)
If you want to skip boilerplate and start building immediately, the complete working project used in this guide is available on GitHub:
🔗 GitHub Repository
GitHub - sarveshtalele/personal-finance-using-RAG-level-1
What you’ll get
- End-to-end Local RAG implementation
- PDF ingestion pipeline
- ChromaDB vector storage
- FastAPI backend + Streamlit UI
- Ollama integration (LLM + embeddings)
Recommended next steps
- Star the repo if it helps you
- Fork it to customize your own private RAG system
- Open issues or PRs to improve evaluation, security, and performance
This repository is a solid starting point for building privacy-first document intelligence systems locally.
Originally published on Medium.


