Retrieval-Augmented Generation
Jul 14–17 · RAG concepts + ComplianceGPT RAG strategy · Deliverable: mid-point pitch (5 min) + preliminary results
Learning Goals
- Understand what RAG is and why it exists
- Know how embeddings and vector search work conceptually
- Understand how ComplianceGPT uses RAG to retrieve relevant HIPAA sections
- Have preliminary results from your project to present at mid-point
Also this week — Contextual Integrity & Compliance (slides + notebooks/contextual_integrity.ipynb): the theory this whole system is built on — Nissenbaum's CI 5-tuple, why it alone isn't enough (with a real example from this lab's own data), and how to reframe your project's research question in CI terms. Worth doing before your mid-point pitch — it'll sharpen how you describe your own results.
Day 1 — Monday, July 14: What is RAG?
The Problem RAG Solves
- LLMs have a knowledge cutoff — they don't know your documents
- Fine-tuning is expensive and doesn't always generalize
- Solution: give the model relevant context at query time
- RAG = Retrieval + Augmented Generation
The RAG Pipeline
- Chunk the knowledge base into segments
- Embed each chunk as a vector
- Store vectors in a vector database
- Query: embed the question, find nearest chunks
- Inject retrieved chunks into the prompt
- Generate: LLM answers with context
Analogy
RAG is like an open-book exam. Without RAG, the model takes a closed-book exam — it has to rely on what it memorized during training. With RAG, you hand it the relevant textbook pages before it answers. The model doesn't need to have memorized HIPAA — it gets the relevant section retrieved and injected into its prompt at runtime.
Open notebooks/week4_rag_intro.ipynb. Walk through: embedding a sentence using sentence-transformers, computing cosine similarity between two sentences, finding the most similar HIPAA section from a list of 5. Run all cells. Modify one cell to test a sentence of your own.
Day 2 — Wednesday, July 16: RAG in ComplianceGPT + Mid-Point Pitches
How ComplianceGPT Uses RAG
- Strategy: "rag" and "rag_bm25" in
batch_runner.py - Retrieval corpus: HIPAA sections, preamble, enforcement guidance
- Query: the last 3 sentences of the scenario (not the full text)
- Why 3 sentences: full scenario floods BM25 with unrelated terms
- Retrieved sections injected into LLM1 extraction prompt
Vector Search vs. BM25
- BM25: keyword-based scoring (TF-IDF variant). Fast, interpretable
- Vector search: semantic similarity via embeddings. Better for paraphrase
- Hybrid: rank-bm25 combines both signals
- ComplianceGPT finding: BM25 outperforms pure vector on this corpus
- Your project might test: why? What scenarios does each strategy handle better?
Each student presents a 5-minute update. Structure:
- What I've done — experiments run, data collected so far
- What I've found — even preliminary: trends, surprises, anything
- What's blocked — any technical issues, unclear methodology, missing data
- Plan for weeks 5–6 — what experiments remain, what you'll write up
Run the same 20 scenarios with --strategy formal and --strategy rag_bm25. Compare accuracy. Are there rows where RAG helps? Where does it hurt? Write 3 sentences summarizing what you observe.
Day 3 — Friday, July 17: Chunking, Embedding Models, and Limits
Chunking Strategies
- Fixed-size: split every N tokens. Simple but breaks sentences
- Sentence-based: split on punctuation. Cleaner but variable size
- Semantic: group sentences by topic. Best quality, slower
- For legal text: section-based is often best (HIPAA § per chunk)
Embedding Model Choices
all-MiniLM-L6-v2: fast, small, good for short textall-mpnet-base-v2: slower, higher qualitytext-embedding-3-small(OpenAI): very good, not free- Legal-specific models:
legal-bert,law-ai/InLegalBERT
Week 4 Deliverable
Due: Wednesday, July 16 (pitch) + Friday, July 18 (written)
1. Mid-point pitch (5 min) — Wednesday morning. See structure above.
2. Experiment log + preliminary results — Friday. A structured log of every experiment you've run:
- Date, experiment name, configuration (model, strategy, rows)
- Result (accuracy or relevant metric)
- Observation (1 sentence: what did you learn?)
Also: at least 1 result table or chart — even if preliminary. Something visual showing a comparison between conditions.
Recommended Reading This Week
- Lewis et al. — "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (2020) — The original RAG paper. Read abstract, intro, and Section 2.
- LangChain documentation — Retrieval section — The conceptual overview of how chains and retrievers work together. (~10 minute read)