Skip to main content

Document Quiz Flow Implementation

IntelliQ features an advanced document processing system that allows users to upload documents, automatically extract content, and generate relevant quizzes without manual question creation. This documentation explains the technical implementation of this feature.

Architecture Overview

The document quiz implementation in IntelliQ follows these key steps:
  1. Document Upload: User uploads a document (currently PDF) through the UI
  2. Storage & Processing: The document is stored and queued for asynchronous processing
  3. Text Extraction: Content is extracted from the document and stored
  4. Content Chunking: For large documents, content is split into meaningful chunks
  5. Quiz Generation: AI generates quiz questions based on document content
  6. Interactive Quiz: User takes the quiz with customized parameters
  7. Result Storage: Quiz results are stored with document reference

Technical Implementation

Document Upload Flow

The file upload component handles the user interface portion:
The backend handles the upload request through the API endpoint:

Document Processing

The document processing happens asynchronously through a queue:

Quiz Generation

Once a document is processed, quizzes can be generated from its content:
The actual quiz generation is handled by an AI model using structured generation:

Quiz Prompt Template

The system uses a specific prompt template to guide AI quiz generation:

Frontend Implementation

The frontend implements two primary components for document quiz generation:
  1. A dashboard to manage documents and start quizzes:
  1. A customization component for advanced quiz settings:

Data Schema

The system relies on a structured database schema:
Quiz submissions maintain a reference to their source document:

Performance and Security Considerations

Performance Optimizations

  1. Asynchronous Processing: Document processing happens asynchronously using QStash to prevent blocking the main application flow
  2. Chunking Strategy: Large documents are automatically split into smaller, meaningful chunks to avoid token limits
  3. Selective Content: For very large documents, only a representative subset of chunks is used for quiz generation
  4. Status Polling: Frontend polls for status updates to provide real-time feedback without server-sent events

Security Measures

  1. Document Ownership: All API endpoints validate that the requesting user owns the document
  2. Content Validation: Extracted content is validated to prevent injection attacks
  3. Access Controls: Supabase RLS policies restrict access to documents
  4. Rate Limiting: Built-in protection against abuse of document processing resources
  5. Isolated Processing: Background processing using admin tokens to prevent user impersonation

Future Enhancements

  1. Additional File Types: Support for DOCX, TXT, and other document formats
  2. Smart Chunking: More sophisticated document chunking based on semantic boundaries
  3. Hierarchical Questions: Questions at different difficulty levels or covering different topics
  4. Document Search: Full-text and semantic search across documents
  5. AI Explanations: Explanations for correct answers based on document content
  6. Interactive Document Links: Questions that link back to the relevant document section

Conclusion

The document quiz flow in IntelliQ leverages several advanced technologies to create a seamless experience:
  1. Cloud Storage: For secure document storage
  2. Document Processing: For text extraction and analysis
  3. Message Queues: For reliable background processing
  4. AI Integration: For intelligent quiz generation
  5. Vector Embeddings: For potential semantic search (future enhancement)
This feature transforms static documents into interactive learning experiences, making it easy to test knowledge from any uploaded material. Written by Ricky Raveanu