Large PDF Summarization Support Enhancement
Version Implemented: 0.229.001
Overview
The Smart HTTP Plugin has been enhanced to support large PDF documents through intelligent chunked summarization. This enhancement allows users to access and extract meaningful information from PDF documents that would previously be rejected due to size limitations.
Version Information
- Version: 0.228.021
- Enhancement: Clearer, more readable summarization metrics with separated lines
- Previous Version: 0.228.020 (comprehensive metrics)
- Base Version: 0.228.015 (initial large PDF support)
Problem Addressed
Previously, the SmartHttpPlugin would reject PDF documents larger than ~150KB (max_content_size * 2) with the error:
Error: Content too large (1376852 bytes). Try a different URL or specific page.
This prevented access to many valuable documents, such as government reports, research papers, and comprehensive manuals.
Solution Implemented
1. Dynamic Size Limits
The plugin now uses different size limits based on content type:
- PDF Documents: Up to 1.5MB (max_content_size * 20)
- Other Content: 150KB (max_content_size * 2) - unchanged
2. Chunked Summarization Process
For large PDFs that exceed the normal content size after Document Intelligence processing:
- Full Text Extraction: Document Intelligence processes the entire PDF
- Content Analysis: Check if extracted text exceeds manageable size (225KB)
- Intelligent Chunking: Split content into ~100KB chunks for processing
- Individual Summarization: Each chunk is summarized using Azure OpenAI
- Summary Combination: All chunk summaries are combined
- Executive Summary: If needed, create a final executive summary
3. Fallback Mechanisms
- If summarization fails, content is truncated with clear messaging
- If Azure OpenAI is unavailable, falls back to traditional truncation
- Missing dependencies are handled gracefully
Technical Implementation
Key Methods Added
_summarize_large_content(content: str, uri: str) -> str
- Handles chunked summarization of large content
- Uses Azure OpenAI for intelligent summarization
- Implements retry logic and fallback mechanisms
Enhanced _process_pdf_content()
- Detects when content requires summarization
- Provides clear user messaging about content reduction
- Maintains full context while staying within limits
Updated _read_limited_content()
- Allows larger download sizes for PDFs
- Maintains efficient memory usage
- Respects content-type headers
Size Management
# Dynamic limits based on content type
pdf_limit = max_content_size * 20 # ~1.5MB
regular_limit = max_content_size * 2 # ~150KB
summarization_threshold = max_content_size * 3 # ~225KB
User Experience
Before Enhancement
Error: Content too large (1376852 bytes). Try a different URL or specific page.
After Enhancement (v0.228.021)
📄 **LARGE PDF PROCESSED WITH AI SUMMARIZATION**
📍 Source: https://example.com/large-document.pdf
🔄 Processing Method: Full text extracted using Azure Document Intelligence, then AI summarization
📏 Processing limits: 225,000 characters (~56,250 tokens)
⚠️ Original content exceeded limits by 512.4% so we summarized the document
📉 Summarization reduced document size: ~81.7%
📊 Character counts: 1,376,852 characters → 251,876 characters
📄 Page counts: 11 pages summarized to ~5 pages
🔢 Token estimates: ~344,213 tokens → ~62,969 tokens
⚠️ Important: This is an AI-summarized version preserving key information. For complete details, access the original PDF.
================================================================================
SUMMARIZED CONTENT (5 EQUIVALENT PAGES)
================================================================================
🔄 **AI-GENERATED SUMMARY SECTIONS**
The original content was divided into 14 chunks of ~100,000 characters each for processing.
Each section below represents an intelligent summary preserving key information:
📄 **SECTION 1 OF 14** (Original: 100,000 chars → Summary: 15,243 chars, 84.8% reduction)
[Comprehensive summary preserving key information, data points, and insights...]
📄 **SECTION 2 OF 14** (Original: 100,000 chars → Summary: 14,892 chars, 85.1% reduction)
[Detailed summary of second section with important findings...]
...
Clearer Messaging Features (v0.228.021)
- Separated Metrics: Each key measurement is on its own line for easy scanning
- Processing Limits First: Shows exact limits that triggered summarization
- Clear Exceeded Notice: Specific percentage by which content exceeded limits with clear action taken
- Reduction Percentage: Simple, clear percentage reduction achieved
- Character Transformation: Before → After format for easy comparison
- Page Conversion: Clear transformation from original pages to summarized equivalent
- Token Estimates: Before → After token counts for technical users
- Logical Grouping: Related information grouped with spacing for readability
📄 **LARGE PDF PROCESSED WITH AI SUMMARIZATION**
📍 Source: https://example.com/large-document.pdf
📊 Original Document: 11 pages • 1,376,852 characters • ~344,213 words • ~344,213 tokens
� Processing Limits: 225,000 characters • ~56,250 tokens (content exceeded limits by 512.4%)
🔄 Processing Method: Full text extracted using Azure Document Intelligence, then AI summarization
🧠 AI Summarization: Content reduced from 11 pages to ~3 equivalent pages
📉 Reduction: 85.2% reduction • 203,654 characters • ~50,914 words • ~50,914 tokens
⚠️ Important: This is an AI-summarized version preserving key information. For complete details, access the original PDF.
================================================================================
SUMMARIZED CONTENT (3 EQUIVALENT PAGES)
================================================================================
🔄 **AI-GENERATED SUMMARY SECTIONS**
The original content was divided into 14 chunks of ~100,000 characters each for processing.
Each section below represents an intelligent summary preserving key information:
📄 **SECTION 1 OF 14** (Original: 100,000 chars → Summary: 15,243 chars, 84.8% reduction)
[Comprehensive summary preserving key information, data points, and insights...]
📄 **SECTION 2 OF 14** (Original: 100,000 chars → Summary: 14,892 chars, 85.1% reduction)
[Detailed summary of second section with important findings...]
...
Comprehensive Messaging Features (v0.228.020)
- Detailed Original Metrics: Exact pages, characters, words, and token estimates
- Processing Limit Transparency: Shows specific limits and by how much content exceeded them
- Method Clarity: Clear explanation of Document Intelligence + AI summarization approach
- Page Equivalency: Shows transformation from original pages to equivalent summarized pages
- Comprehensive Reduction Stats: Characters, words, tokens, and percentage reduction
- Per-Section Metrics: Individual chunk sizes and reduction percentages for each section
- Chunking Transparency: Explains how content was divided for processing
- Technical Details: Token estimates, character counts, and processing methodology
Configuration Requirements
Azure OpenAI Access
The enhancement requires access to Azure OpenAI for summarization:
- GPT model deployment (configurable via settings)
- Either API key or managed identity authentication
- Sufficient quota for summarization requests
Document Intelligence
Continues to use existing Document Intelligence setup:
- Azure Document Intelligence service
- Authentication via key or managed identity
- Text extraction capabilities
Use Cases Improved
Government Documents
- Policy papers and regulations
- White papers and reports
- Legal documents and guidelines
Research Publications
- Academic papers and studies
- Technical specifications
- Industry reports
Business Documents
- Comprehensive manuals
- Annual reports
- Detailed specifications
Performance Considerations
Token Usage
- Moderate increase for large PDFs requiring summarization
- Intelligent chunking minimizes unnecessary token consumption
- Configurable model allows cost optimization
Processing Time
- Document Intelligence handles initial extraction (unchanged)
- Summarization adds processing time for large documents
- Async processing maintains responsiveness
Memory Usage
- Streaming download for efficient memory usage
- Chunked processing prevents memory spikes
- Cleanup routines ensure temporary files are removed
Error Handling
Summarization Failures
- Individual chunk failures don't stop the entire process
- Fallback to truncation with clear messaging
- Detailed logging for troubleshooting
Service Unavailability
- Graceful degradation when Azure OpenAI is unavailable
- Clear error messages for missing dependencies
- Maintains existing functionality for smaller PDFs
Configuration
The enhancement uses existing configuration settings:
Azure OpenAI Settings
azure_openai_gpt_endpointazure_openai_gpt_key(or managed identity)azure_openai_gpt_deploymentenable_gpt_apim(for API Management routing)
Document Intelligence Settings
- Existing Document Intelligence configuration (unchanged)
Benefits
Accessibility
- Large Document Access: Previously inaccessible documents now available
- Intelligent Summarization: Key information preserved through AI summarization
- User-Friendly Feedback: Clear messaging about content processing
Consistency
- Predictable Behavior: Large PDFs are processed reliably
- Quality Preservation: Important information retained through smart summarization
- Error Resilience: Multiple fallback mechanisms ensure robustness
Scalability
- Configurable Limits: Adjustable based on deployment requirements
- Efficient Processing: Chunked approach handles very large documents
- Resource Management: Controlled memory and token usage
Testing
Functional Test
The enhancement includes comprehensive functional testing:
python functional_tests/test_large_pdf_summarization_support.py
Test Coverage
- PDF URL detection patterns
- Size limit logic verification
- Chunked summarization logic
- Error handling scenarios
- Integration readiness validation
Future Enhancements
Potential improvements for future versions:
- Page-Specific Processing: Allow users to request specific page ranges
- Summary Customization: Configurable summarization prompts and styles
- Caching: Cache processed summaries for repeated requests
- Progress Indicators: Real-time feedback for long-running summarizations
- Quality Metrics: Summarization quality assessment and optimization
Migration Notes
This enhancement is backward compatible:
- Existing small PDF processing unchanged
- No configuration changes required
- Existing error handling preserved
- Performance impact minimal for small documents
Security Considerations
- Content Safety: Large content still subject to content safety filters
- Access Control: PDF processing respects existing authentication
- Data Privacy: Temporary files cleaned up after processing
- Token Management: Summarization uses existing Azure OpenAI authentication
Related Documentation
- Smart HTTP Plugin PDF Support
- Enhanced Citations Implementation
- Plugin Documentation and Testing Standards