evanderpool/rag-knowledge-base
0
RAG Knowledge Base Builder
Status: Phase 2 — Complete (Streamlit UI built) Started: 2026-05-09 Target MVP: 3 days | Target v1: 7 days (Streamlit UI + HuggingFace Spaces deploy)
Description
A local RAG system that lets anyone upload company documents and ask questions in plain English — getting accurate answers with source citations. Built with HuggingFace embeddings, ChromaDB, and Groq API (all free).
Tech Stack
Python · Groq API (Llama 3.3 70B) · HuggingFace sentence-transformers · ChromaDB · PyMuPDF · Streamlit (Phase 2)
Quick Start
# 1. Install dependencies
pip install --user -r requirements.txt
# 2. Add your Groq API key (free at console.groq.com)
cp .env.example .env # Windows: copy .env.example .env
# 3a. Web UI (Phase 2)
streamlit run app.py
# 3b. CLI (Phase 1)
python ingest.py company_policy.pdf
python query.pyKey Dates
- 2026-05-09: Project scoped and brief created
- 2026-05-09: Phase 1 MVP complete — loader, embedder, query engine, CLI
- 2026-05-09: Phase 2 complete — Streamlit UI with file upload, chat, source panel
Full Pipeline
Document
→ loader.load_document()
→ PyMuPDF page-by-page extraction # preserves page numbers for citations
→ _clean() # strip artifacts, fix hyphenation
→ _recursive_split() + _merge() # 1000-char boundary-aware chunks
→ _apply_overlap() # 150-char overlap between chunks
→ list[Chunk] # text + source + page + file_hash + token_estimate
→ kb.ingest(chunks) # KnowledgeBase in embedder.py
→ is_ingested(file_hash)? # skip if already in store (dedup)
→ SentenceTransformer.encode() # all-MiniLM-L6-v2, batch=32
→ ChromaDB.add() # cosine similarity, persistent local storage
→ engine.ask(question) # QueryEngine in query.py
→ kb.retrieve(question, top_k=5) # embed query → cosine similarity search
→ _apply_token_budget() # fit chunks within 4000-token context limit
→ Groq(Llama 3.3 70B) # structured prompt with context + citation rules
→ QueryResult(answer, sources, ...) # answer + deduplicated source listFiles
CLI Reference
# Ingest
python ingest.py policy.pdf # single file
python ingest.py doc1.pdf doc2.txt # multiple files
python ingest.py docs/ # whole folder
python ingest.py --list # show what's in the knowledge base
python ingest.py --delete policy.pdf # remove a document
# Query
python query.py # interactive Q&A with streamingKey Design Decisions
Project Brief
Saved to Google Drive: 2026-05-09 AI Project Brief — RAG Knowledge Base Builder
Phase 3 — Next (Stretch Goals)
- Deploy to HuggingFace Spaces for a public live demo URL
- Multi-turn conversation with chat history injected into the Groq prompt
.docxand.mdloader support (add one entry to_LOADERSin loader.py)- Relevance threshold filter — skip chunks below a minimum score
- Re-ranking pass on retrieved chunks before sending to Groq
