You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add --use-textbook: opt-in textbook grounding for course generation
When the new --use-textbook PATH flag is set, the system loads a PDF or
markdown textbook, retrieves relevant passages per chapter, injects them
into the writing prompts, and emits inline citation tokens like
[han_data_mining_3e:ch6.s3:p15] in slides, scripts, and assessments.
A new verifier inside evaluate.py scores each citation against the
source on a 1-5 faithfulness scale.
Three interfaces, all opt-in: CLI flag, API field on
POST /api/course/generate, and a file-picker on the Web UI. When the
flag is absent every code path falls back to the existing vanilla
behavior -- byte-comparable output, zero citation tokens.
Measured on two real textbooks (Han Data Mining 3rd ed., Agentic Design
Patterns):
- Agentic: faithfulness 4.33/5, citation precision 86.7 %,
attribution rubric +65 % vs vanilla on slide content
- Han: faithfulness 3.87/5, precision 71 %, attribution +111 %
- Overall content quality unchanged within LLM-judge noise on both
- Vanilla preservation invariant holds end-to-end
New code: src/grounding/ (knowledge_base, retriever, contract, reranker),
src/textbook/ (schema, ingest_pdf, ingest_md), GroundingAgent in
evaluate.py, --use-textbook plumbed through run.py + ADDIE +
SlidesDeliberation, textbook_path field + /api/textbooks/upload +
/api/textbooks/list in api_server.py, file picker in frontend.
280 tests passing.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+55-3Lines changed: 55 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,7 @@ An AI-powered instructional design system based on the ADDIE model for automated
74
74
| 📄 **LaTeX/PDF Output**| Generate professional LaTeX slides and compile to PDF format |
75
75
| 🎨 **PowerPoint (PPTX) Export**| Convert LaTeX Beamer slides to visually rich PPTX using pptxgenjs with icons, shadows, and Slide Masters |
76
76
| ✅ **Automatic Evaluation**| Built-in evaluation system for assessing generated course materials |
77
+
| 📖 **Textbook Grounding**|*(opt-in)* Ground course content in a PDF or markdown textbook; inline citation tokens are inserted in slides, scripts, and assessments. Built-in verifier checks each citation's faithfulness. Available on CLI, API, and Web UI. |
77
78
78
79
### 🎬 How It Works
79
80
@@ -190,6 +191,7 @@ python -m http.server 8080
190
191
- Select "Not Use" for basic generation
191
192
- Select "Upload Catalog File" to upload a custom catalog JSON
192
193
- Select "Use Default Catalog" to use the default catalog
194
+
-**Textbook grounding***(optional)*: upload one or more PDF/markdown files via the picker labelled "Textbook grounding (optional)". Leave empty to skip.
For complete API documentation, see [API Documentation](docs/API_DOCUMENTATION.md).
@@ -503,7 +519,8 @@ For complete API documentation, see [API Documentation](docs/API_DOCUMENTATION.m
503
519
|**Course Generation**| Generate complete course materials based on ADDIE model | Web interface, CLI (`run.py`), or RESTful API |
504
520
|**Catalog Mode**| Use structured catalog files for guided generation |`--catalog` flag or upload in web interface |
505
521
|**Copilot Mode**| Interactive feedback during generation |`--copilot` flag in CLI or enable in web interface |
506
-
|**Evaluation**| Automatic assessment of generated materials |`python evaluate.py --exp <exp_name>`|
522
+
|**Textbook Grounding**| Ground content in a PDF/markdown textbook with inline citations |`--use-textbook PATH` flag in CLI, `textbook_path` in API, file picker in web interface |
523
+
|**Evaluation**| Automatic assessment of generated materials, with optional citation verification |`python evaluate.py --exp <exp_name> [--use-textbook PATH]`|
507
524
|**Web Interface**| Visual interface for course generation | Open `frontend/index.html` in browser |
508
525
|**API Server**| RESTful API for programmatic access |`python api_server.py` or Docker |
509
526
@@ -547,16 +564,36 @@ Interactive mode that prompts for feedback after each phase of the ADDIE workflo
Opt-in. Pass `--use-textbook PATH` (a PDF, markdown file, or directory of either) and the system retrieves relevant textbook passages per chapter and inserts inline citation tokens like `[han_data_mining_3e:ch6.s3:p15]` (textbook id, section, page) in slides, scripts, and assessments. Without the flag, vanilla output is unchanged.
Embeddings are cached on disk after the first ingest (`~5-10s` one-time per textbook). Per-chapter generation is ~10-25% slower than vanilla because prompts carry retrieved excerpts. Verify each emitted citation with the evaluation step below.
577
+
578
+
**How the grounding works under the hood:**
579
+
- Each chapter is decomposed into 3 subtopics by the LLM; each subtopic is HyDE-expanded into a hypothetical textbook paragraph and used as a retrieval query (multi-query retrieval).
580
+
- Per-section rankings across queries are fused via Reciprocal Rank Fusion (RRF, k=60). The contract binds each chapter to the top sections.
581
+
- Coverage gating: if no textbook section scores above a threshold for a chapter, that chapter is marked "off-textbook" and writes without citations (rather than fabricate them against weak retrieval).
582
+
- Writing prompts carry a five-rule mandatory grounding directive: cite-every-sourced-claim, anchor-to-source-wording, abstain-if-unsupported, exact-tokens-only, cite-correct-excerpt. Scripts (spoken narration) get a softer variant that allows natural paraphrase and once-per-concept citation. A worked example uses a real snippet from the top retrieved chunk so the model has a literal pattern to imitate.
583
+
550
584
### Automatic Evaluation
551
585
552
586
**Entry Point**: `evaluate.py` – Automatic assessment and scoring
Evaluation results are saved in `eval/{experiment_name}/` directory.
596
+
Evaluation results are saved in `eval/{experiment_name}/` directory. With `--use-textbook`, a `grounding_results/` subdirectory is added containing per-citation faithfulness scores (1–5), citation precision, malformed-token counts, and a **failure-mode breakdown** (`good` / `loose_paraphrase` / `hallucination` / `retrieval_bad` / `wrong_chunk_cited` / `judge_uncertain`) that pinpoints which lever to pull when precision is below target.
0 commit comments