Spaces:
Running
Running
File size: 7,324 Bytes
e8a57cb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | # Knowledge Graph - Link PDF Pages to Questions
## Overview
The Knowledge Graph feature allows you to visually link PDF pages to specific questions using an interactive node-based editor. Linked pages become accessible as revision notes.
## Features
- **Visual Node Editor** - Drag-and-drop interface using React Flow
- **Link PDF Pages** - Connect any PDF page to any question
- **Revision Notes Integration** - Linked pages appear as revision notes
- **Auto-Save** - Links are saved to the existing database structure
- **Bidirectional Access** - Access linked pages from questions and vice versa
## How to Use
### 1. Open Graph Editor
From the Question Entry page (`/question_entry_v2/<session_id>`):
1. Scroll to the "Generate PDF" section
2. Click the **"Link PDF Pages to Questions"** button
3. The graph editor opens in a new page
### 2. Understanding the Interface
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β [β Back] [Clear] [Save & Link] β
ββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β β
β PDF β GRAPH CANVAS β
β Pages β β
β Panel β [Question Nodes] ββββ [Page Nodes] β
β β β
β [Page1] β β
β [Page2] β β
β [Page3] β β
β β β
ββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### 3. Create Links
1. **Drag a PDF page** from the left sidebar onto the canvas
2. **Drag from the page node** to a question node to create a link
3. **Repeat** for all pages you want to link
4. Click **"Save & Link"** to save
### 4. Access Linked Pages
After saving:
- Linked pages appear as revision notes for the connected questions
- Access them via the revision notes modal in Question Entry
- Pages are stored in the existing `images.note_json` and `images.note_filename` fields
## Node Types
### Question Node (Blue)
```
βββββββββββββββββββββββ
β β Q12 β
β π Physics β
β π Mechanics β
β β
Has Notes β
βββββββββββββββββββββββ
```
- Shows question number, subject, chapter
- Green border indicates existing notes
- Connection point on the right
### Page Node (Purple)
```
βββββββββββββββββββββββ
β π Page 5 β
β βββββββββββββββββββ β
β β Page Image β β
β βββββββββββββββββββ β
βββββββββββββββββββββββ
```
- Shows PDF page thumbnail
- Connection point on the left
- Drag from sidebar to create
## Data Structure
### Saved Link Format
```json
{
"type": "linked_page",
"source_page_id": 123,
"source_page_number": 5,
"source_filename": "upload_abc123.jpg",
"linked_at": "2026-03-17T10:30:00",
"original_note": null
}
```
### Database Schema
Links are stored in the existing `images` table:
| Column | Description |
|--------|-------------|
| `note_json` | JSON containing link data |
| `note_filename` | Reference to the linked page image |
| `session_id` | Session this belongs to |
## API Endpoints
### GET `/session/<session_id>/graph`
Open the graph editor for a session.
### POST `/session/graph/save`
Save graph links.
**Request:**
```json
{
"session_id": "abc123",
"links": [
{
"page_id": 5,
"question_image_id": 10,
"page_number": 5
}
]
}
```
**Response:**
```json
{
"success": true,
"message": "Linked 1 pages to questions",
"links_count": 1
}
```
### GET `/session/graph/load/<session_id>`
Load existing graph links.
### POST `/session/graph/delete/<session_id>`
Delete all graph links for a session.
## Workflow Example
### Scenario: Link difficult questions to reference pages
1. **Upload PDF** with questions and solutions
2. **Enter Question Entry** page
3. **Click "Link PDF Pages to Questions"**
4. **Drag solution page** (e.g., page 10) to Question 5
5. **Drag another page** (e.g., page 15) to Question 8
6. **Save & Link**
7. **Return to Question Entry**
8. **Click revision notes icon** on Question 5
9. **See linked solution page** as a revision note!
## Benefits
β
**Visual Organization** - See all connections at a glance
β
**Quick Reference** - Link solutions, formulas, diagrams
β
**Study Aid** - Create custom revision materials
β
**Flexible** - Link any page to any question
β
**Persistent** - Saved to database, survives page reloads
## Tips & Tricks
### Best Practices
1. **Link solution pages** to their corresponding questions
2. **Create formula sheets** by linking reference pages
3. **Group related questions** by linking them to the same reference
4. **Add diagrams** from appendix pages to relevant questions
### Keyboard Shortcuts
- `Delete/Backspace` - Delete selected node or edge
- `Ctrl+C/V` - Copy/paste nodes (coming soon)
- `Mouse Wheel` - Zoom in/out
- `Right-click + Drag` - Pan canvas
### Performance Tips
- Keep graphs under 100 nodes for best performance
- Use the MiniMap to navigate large graphs
- Clear unused nodes before saving
## Troubleshooting
### Page not showing in sidebar
- Ensure PDF was uploaded and processed
- Check that images exist in the database
- Refresh the page
### Can't create connection
- Make sure you're dragging FROM page TO question
- Release mouse over the question node
- Check browser console for errors
### Links not saving
- Ensure you clicked "Save & Link"
- Check network tab for failed requests
- Verify session ownership
## Technical Details
### Built With
- **React Flow** - Node-based graph editor
- **Preact** - Lightweight React alternative
- **Flask** - Python backend
- **SQLite** - Database storage
### File Structure
```
Report-Generator/
βββ templates/
β βββ graph_editor.html # React Flow editor
β βββ question_entry_v2.html # Entry point
βββ graph_routes.py # Backend routes
βββ docs/
βββ KNOWLEDGE_GRAPH.md # This file
```
## Future Enhancements
- [ ] Export graph as image/PDF
- [ ] Import/export graph data
- [ ] Multi-session graphs
- [ ] Collaborative editing
- [ ] Auto-suggest links based on content
- [ ] Graph templates
- [ ] Search and filter nodes
## Support
For issues or questions:
1. Check browser console for errors
2. Verify database integrity
3. Review this documentation
4. Report bugs with screenshots
|