How swipyknows/rag-hallucination-detector works
This project builds a medical question-answering RAG system and evaluates how well its answers stay grounded in retrieved PubMedQA context. Its main workflow is ingesting and embedding source text, answering through retrieval and generation, then scoring answer quality. Users can run the system through a Streamlit interface or the API; separate scripts compare a no-retrieval baseline and retrieval, chunk-size, and top-k variants. Some runtime modules are documented but were not sampled, so their internal links are limited to documented behavior.
Main entry points: ablation_chunking.py Chunk-size study · ablation_retrieval.py Retriever study · ablation_topk.py Top-k study · qa_pairs.json Reference QA set
Components 18
Data ingestion
- PubMedQA corpus
- Chunk and embed
embedder.py - FAISS index
RAG runtime
- RAG pipeline
rag_pipeline.py - Query API
api.py - Answer generation
api.py
User interfaces
- Web interface
app.py - Unified application
unified_app.py
Evaluation and experiments
- Reference QA set
qa_pairs.json - Quality scoring
hallucination_scorer.py - Baseline comparison
hallucination_baseline.py - Chunk-size study
ablation_chunking.py - Retriever study
ablation_retrieval.py - Top-k study
ablation_topk.py - Experiment outputs
results
Other components
- Gemini services
- Ragas evaluator
- Streamlit user
Connections 30
- PubMedQA corpus → Chunk and embed: loads contexts
README.md - Chunk and embed → Gemini services: requests embeddings
embedder.py - Chunk and embed → FAISS index: saves index
README.md - FAISS index → RAG pipeline: retrieves documents
README.md - RAG pipeline → Gemini services: generates answers
README.md - Streamlit user → Web interface: uses interface
README.md - Web interface → Query API: posts query
app.py - Streamlit user → Unified application: uses interface
README.md - Query API → Answer generation: dispatches strategy
api.py - Answer generation → Gemini services: generates answers
api.py - Query API → Ragas evaluator: scores answers
api.py - Unified application → Gemini services: generates answers
unified_app.py - Unified application → Ragas evaluator: scores answers
README.md - Reference QA set → Quality scoring: provides references
hallucination_scorer.py - Quality scoring → Ragas evaluator: evaluates quality
hallucination_scorer.py - Reference QA set → Baseline comparison: provides questions
hallucination_baseline.py - Baseline comparison → Gemini services: requests baseline answers
hallucination_baseline.py - Baseline comparison → Ragas evaluator: compares faithfulness
hallucination_baseline.py - Chunk-size study → PubMedQA corpus: loads sample data
ablation_chunking.py - Chunk-size study → Gemini services: embeds and generates
ablation_chunking.py - Chunk-size study → Ragas evaluator: scores variants
ablation_chunking.py - Retriever study → Reference QA set: loads questions
ablation_retrieval.py - Retriever study → Gemini services: generates answers
ablation_retrieval.py - Retriever study → Ragas evaluator: scores variants
ablation_retrieval.py - Top-k study → Reference QA set: loads questions
README.md - Top-k study → Gemini services: generates answers
README.md - Top-k study → Ragas evaluator: scores variants
README.md - Chunk-size study → Experiment outputs: writes results
ablation_chunking.py - Retriever study → Experiment outputs: writes results
README.md - Top-k study → Experiment outputs: writes results
README.md