--- title: Groundwork emoji: ๐Ÿ“š colorFrom: blue colorTo: indigo sdk: gradio sdk_version: 6.26.0 app_file: app.py pinned: false --- # Groundwork **Multi-Document RAG with Citations** โ€” GenAI Course, Topic 183 (Model Making) Jury 1 Submission --- ## What this is Groundwork answers questions by retrieving relevant passages from a set of source documents and generating an answer that cites **exactly which passage** supports each claim โ€” instead of relying on the model's memory. Every claim in the answer is traceable back to a specific paper and page. **Live demo:** `https://huggingface.co/spaces/cynstl/groundwork` --- ## The problem this solves Large language models answer confidently even when they don't actually know something โ€” a well-documented failure mode called hallucination. This is a real, practical problem anywhere an answer needs to be trustworthy and checkable: research assistants, legal/policy tools, internal documentation search. Retrieval-Augmented Generation (RAG) addresses this by forcing the model to ground its answer in retrieved source text and to show its work via citations, rather than answering from parametric memory alone. --- ## Document corpus Five real, publicly available research papers on generative AI itself โ€” chosen so the system can be tested on genuine cross-document synthesis, including a real scholarly disagreement: | Paper | Role in the corpus | |---|---| | Kaplan et al. 2020 โ€” *Scaling Laws for Neural Language Models* | Position A on compute-optimal scaling | | Hoffmann et al. 2022 โ€” *Training Compute-Optimal LLMs* (Chinchilla) | Position B โ€” directly conflicts with Kaplan | | Pearce & Song 2024 โ€” *Reconciling Kaplan and Chinchilla Scaling Laws* | Resolves the Kaplan/Chinchilla disagreement | | Lewis et al. 2020 โ€” *Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks* | The original RAG paper โ€” this system's own architecture | | Kalai et al. 2025 โ€” *Why Language Models Hallucinate* | Independent theme: why grounding matters | The Kaplan/Chinchilla pair gives the system a genuine conflicting-source case to handle, not a synthetic one. --- ## How it works (architecture) 1. **Ingest** โ€” each PDF is loaded page-by-page and split into ~500-character chunks, each tagged with its source paper and page number. 2. **Embed & index** โ€” chunks are embedded with `all-MiniLM-L6-v2` (sentence-transformers) and stored in a FAISS vector index. 3. **Retrieve** โ€” for a given question, the top-k most similar chunks are retrieved via similarity search. 4. **Generate with citations** โ€” the retrieved chunks are numbered and passed to the LLM (Groq, Llama 3.3 70B) with an explicit instruction: answer using *only* these excerpts, and tag every claim with a `[n]` citation. 5. **Display** โ€” the UI shows the answer plus a citation key underneath, mapping each `[n]` back to the exact paper, page, and excerpt text. ``` PDFs โ†’ chunk (w/ source metadata) โ†’ embed โ†’ FAISS index โ”‚ question โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ similarity search โ”€โ”€โ”˜ โ”‚ top-k chunks โ”‚ LLM (answer ONLY from chunks, cite [n]) โ”‚ answer + citation key ``` --- ## Mapping to the rubric | Criterion | Marks | How this submission addresses it | |---|---|---| | **Technical depth & correctness** | 12 | Implements embeddings, similarity-based retrieval, and prompt-constrained generation โ€” concepts spanning both the prompt-engineering and transformer/LLM units of the syllabus | | **Problem understanding & real-world grounding** | 8 | Addresses a documented, real problem (LLM hallucination / lack of source traceability) using a real, verifiable source corpus | | **Implementation / demo quality** | 10 | Working, live, interactive demo (Gradio) โ€” not a static notebook. Jury can ask its own questions in real time | | **Results, evaluation & analysis** | 6 | *Jury 1 scope: qualitative testing on multi-document questions (see below).* Quantitative faithfulness/citation-accuracy metrics are planned for Jury 2 | | **Presentation & communication** | 6 | This README + live demo walkthrough; architecture explicitly mapped to syllabus concepts above | | **Individual viva / Q&A** | 5 | Each team member can speak to their part โ€” ingestion/chunking, retrieval, citation-prompting, or UI/deployment | | **Teamwork & contribution** | 3 | Balanced ownership across ingestion, retrieval logic, prompt design, and deployment | --- ## What's tested (Jury 1) The system was tested on questions that genuinely require combining information from more than one document, for example: - *What do Kaplan et al. and the Chinchilla paper disagree about?* - *How was the Kaplan/Chinchilla disagreement resolved?* - *Why do language models hallucinate, and how does retrieval help?* For each, we checked manually: (a) did the retrieved chunks actually contain the relevant information, and (b) did every citation in the answer correctly point to a chunk that supports the claim it's attached to. --- ## Anticipated jury questions **"How do you ensure a citation actually supports the answer?"** Currently: the prompt constrains the model to answer *only* from numbered, retrieved excerpts, and every claim must carry a `[n]` tag pointing to one of them โ€” this is enforced structurally, not just requested. For Jury 2, this will be extended with an automated faithfulness check (e.g. an entailment check between each cited claim and its source chunk, using the `ragas` evaluation library) to measure this quantitatively rather than by manual inspection. **"How do you handle conflicting sources?"** The corpus was deliberately built to include a real conflict (Kaplan vs. Chinchilla scaling laws) plus its resolution paper. Currently the prompt instructs the model to surface disagreement explicitly rather than silently picking a side. Explicit, structured conflict-surfacing (e.g. detecting when retrieved chunks contradict each other and presenting both positions with separate citations) is planned for Jury 2. --- ## What's next (Jury 2 / ESE โ€” not yet built) This is a Model Making submission, so the same system deepens across all three juries: - **Jury 2:** reranking of retrieved chunks, a formal citation-accuracy / faithfulness evaluation (grounded vs. hallucinated answer rate), explicit conflicting-source detection and side-by-side presentation - **ESE:** hallucination guardrails, full evaluation harness (retrieval precision/recall + citation faithfulness rate), and a limitations analysis --- ## Tech stack Python ยท LangChain ยท FAISS ยท sentence-transformers (`all-MiniLM-L6-v2`) ยท Groq (Llama 3.3 70B) ยท Gradio ยท Hugging Face Spaces ## Running locally See `SETUP.md` for local installation and Hugging Face deployment steps. ## Team Add team member names + individual contribution areas here before submission (maps to the Teamwork & Individual Viva criteria).