A Retrieval-Augmented Generation (RAG) system that answers questions grounded in your own documents — notes, PDFs, DOCX files, or web pages — with source citations, and an explicit refusal when it isn't confident enough to answer reliably.
Most RAG demos retrieve context and pass it straight to an LLM, which will happily generate a fluent answer even when nothing relevant was found. This project adds a confidence threshold on retrieval: if no retrieved chunk is similar enough to the query, the system tells the user it doesn't know, instead of guessing. It also includes a small evaluation harness to measure retrieval quality with a concrete number, rather than eyeballing it.
Streamlit UI
│
▼
Upload PDFs / URLs / TXT / DOCX
│
▼
Document Loader (core/loader.py)
│
▼
Text Cleaning → Chunking (core/splitter.py)
│
▼
Sentence-Transformer Embeddings (core/embeddings.py)
│
▼
ChromaDB (core/vectorstore.py)
│
▼
Retrieval + confidence threshold (core/retriever.py)
│
├── below threshold → explicit refusal, no LLM call
│
▼
Groq Llama 3.3 (core/llm.py)
│
▼
Answer + Source Citations (pages/2_Chat.py)
See docs/design_decisions.md for the reasoning
behind the chunking strategy, the similarity threshold, and other choices.
- Multi-format ingestion: PDF, TXT, DOCX, and web URLs
- Two chunking strategies (fixed-size and paragraph-aware) that can be compared empirically via the evaluation harness
- Confidence-gated generation: refuses to answer rather than hallucinate when retrieval is weak
- Source citations: every answer links back to the source document, page, and chunk, with similarity score shown
- Evaluation harness: hand-labeled question set + hit-rate scoring in
evaluation/ - Dashboard: index stats, last-query retrieval scores, and eval results
git clone <your-repo-url>
cd AI_Research_Assistant
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# then edit .env and add your GROQ_API_KEY (free tier: https://console.groq.com)streamlit run app.pyOpen the app, go to Upload, and index the file in sample_data/sample.txt
(or your own documents) to try it immediately.
python evaluation/run_eval.pyThis runs the questions in evaluation/eval_questions.json against the
current index and reports retrieval hit-rate. Results are saved to
evaluation/results/ and shown on the Dashboard page. Edit
eval_questions.json to add your own labeled questions once you've indexed
your real documents.
AI_Research_Assistant/
├── app.py # Streamlit entry point
├── rag.py # Pipeline orchestrator — read this first
├── config.py # Settings, loaded from .env
├── prompts.py # Prompt templates
│
├── core/
│ ├── loader.py # PDF / TXT / DOCX / URL → raw text
│ ├── splitter.py # Chunking strategies
│ ├── embeddings.py # Sentence-transformer wrapper
│ ├── vectorstore.py # ChromaDB operations
│ ├── retriever.py # Top-k + confidence threshold + refusal
│ ├── llm.py # Groq client
│ └── utils.py # Shared helpers
│
├── pages/ # Streamlit multi-page UI
├── evaluation/ # Eval question set + hit-rate scoring
├── resources/ # Uploaded files + persisted vector store
├── docs/ # Architecture + design decision notes
└── sample_data/ # Ready-to-use demo content
- UI: Streamlit
- Embeddings:
sentence-transformers(all-MiniLM-L6-v2) - Vector store: ChromaDB (local, persistent)
- LLM: Groq (Llama 3.3)
- Loaders:
pypdf,python-docx,beautifulsoup4
- Hybrid search (BM25 + vector similarity, merged via reciprocal rank fusion) to catch exact keyword/name matches that embeddings miss
- Cross-encoder reranking of top-k results before generation
- Query rewriting for vague user questions before retrieval