# Long-Context Study Plan Studio

## PURPOSE
The video's strongest knowledge-work claim is concrete: you can "feed it mountains of
documents, papers, course materials, and it can create a useful study plan out of them."
This project turns that demo into a runnable Gradio app. A student drops in course
material, the app chunks and indexes it in ChromaDB, retrieves the passages relevant to
the topics they name, and asks a model to build a week-by-week plan that cites the real
source chunks instead of inventing a syllabus.

## WHY THIS MATTERS
Naive "summarize this whole PDF" prompting breaks on long inputs — sections get ignored
and citations are fabricated. The transcript stresses that Gemini 4 Argon "remembers
details across long conversations" and handles document mountains well. Teaching
retrieval-augmented generation over long context is how you turn that marketing claim
into an engineering skill you can measure: does every plan item trace back to a chunk?

## HOW TO BUILD
1. `pip install -r requirements.txt` (Gradio + ChromaDB, no API key required to start).
2. Split uploaded text into ~800-character chunks and embed them; store ids, text, and
   vectors in a persistent ChromaDB collection.
3. Embed the student's topic list and query the collection for the top-k chunks.
4. Prompt a planner model to emit strict JSON: weeks, topics, source chunk ids, and
   self-check questions per week.
5. Render the plan as markdown in Gradio and expose the retrieved chunks for inspection.

```python
import chromadb, gradio as gr
client = chromadb.PersistentClient(path="./chroma")
col = client.get_or_create_collection("course_material")
col.add(ids=ids, documents=texts, embeddings=[embed(t) for t in texts])
hits = col.query(query_embeddings=[embed(topic)], n_results=4)
```

The starter uses a deterministic hash-based embedding so the whole pipeline runs offline;
swap it for a real embedding model when you have network access.

## WHEN TO USE IN PRODUCTION
Strong fit for onboarding portals, university LMS add-ons, and paid study-plan products
where the corpus is the moat. Do NOT use it where answers must be authoritative — legal,
medical, or exam-certified content still hallucinates even with RAG. Skip RAG entirely for
inputs under a page; plain prompting is cheaper and just as good.

## HOW IT HELPS STUDENTS
Practises chunking, embedding, retrieval evaluation, prompt templating, and shipping an
actual UI. They learn to prove grounding with chunk-id citations rather than trusting the
model's tone.

## STARTER CODE
See `starter/main.py` — ingestion, retrieval, and a deterministic stub planner are wired
end to end. Replace `stub_plan()` with a real Gemini 4 Argon call at the marked `# TODO`.
