# Learning Hub and CMS

This document covers the Learning Hub feature, including content types, user-facing features, the content management system (CMS), presentation export, semantic search, and database schema.

---

## Content Types

The Learning Hub supports four content types:

| Type | Description |
|------|-------------|
| `article` | Rich HTML body with an optional attached quiz. |
| `pearl` | Concise clinical snippets for quick reference. |
| `quiz` | Quiz-only resources (no article body). |
| `presentation` | Marp markdown rendered as slides. |

---

## User Features

### Browsing and Search

- Browse content by category.
- Search supports three modes: **keyword**, **semantic** (vector similarity), and **hybrid** (combined).

### Articles

- View articles with rich HTML content.
- Articles may include an embedded quiz.

### Quizzes

- Question types: multiple choice (MCQ), multi-select, and true/false.
- Scoring is calculated on submission.
- Explanations are shown per question after submission.
- Users can view quiz progress and past attempts.

### Presentations

- Marp-rendered slides displayed in a modal viewer.
- Navigation via keyboard arrows and touch/swipe gestures.

---

## CMS (Moderator and Admin)

### Content Editing

- Create, edit, and publish content using a **Tiptap** rich text editor.
- Content can be saved as draft or published.

### AI Content Generation

AI can generate content from several input sources:

- **Topic description:** Provide a text prompt describing the desired content.
- **Uploaded files:** Supports PDF, TXT, MD, HTML, CSV, and JSON. Up to 100 MB per file, maximum 10 files.
- **Nextcloud WebDAV:** Pull files directly from a connected Nextcloud instance.

Generation options:

- Select the AI model used for generation.
- Configure target **slide count** (for presentations) or **word count** (for articles).

### Quiz Builder

- Add and remove questions.
- Add and remove answer options per question.
- Mark correct answers and provide explanations.

### Marp Slide Editor

- Edit Marp markdown directly.
- **Preview** button renders slides in real time.
- **PPTX Download** exports slides to PowerPoint format.

---

## PPTX Export

Presentation export uses the `pptxgenjs` library to produce PowerPoint files.

### Layout

- 16:9 widescreen aspect ratio.
- Slide numbers rendered in the bottom-right corner.

### Supported Content

- **Tables:** Header row with alternating row colors.
- **Inline formatting:** Bold, italic, and inline code.
- **Numbered lists** and **bullet lists**.
- **Code blocks:** Rendered with a grey background.
- **Blockquotes:** Rendered with a blue accent bar on the left.
- **Sub-headings.**
- **Mixed content per slide:** Slides can contain any combination of the above elements.

---

## Semantic Search

### Vector Storage

- Uses the **pgvector** PostgreSQL extension.
- Embeddings are stored as **768-dimensional** vectors.
- An **IVFFLAT** index is used for fast approximate nearest-neighbor similarity search.

### Embedding Models

| Priority | Model | Provider |
|----------|-------|----------|
| Default | `text-embedding-005` | Google Vertex AI |
| Fallback | `text-embedding-3-small` | OpenAI |

### Hybrid Search

Hybrid search combines keyword matching (PostgreSQL full-text search) with vector similarity results to produce a merged, ranked result set.

---

## Database Tables

| Table | Purpose |
|-------|---------|
| `learning_categories` | Content categories for organizing resources. |
| `learning_content` | Content records including body, metadata, and an `embedding` vector column. |
| `learning_questions` | Quiz questions linked to content. |
| `learning_options` | Answer options for each question. |
| `learning_progress` | Per-user quiz attempt history and scores. |
