The Document Interrogation tab provides an interactive interface for analyzing and asking questions about documents (PDF, Markdown, or text files) using AI language models from Ollama.
The interface is divided into two main areas:
-
Document Viewer (Left Pane - 60% width)
- Displays the loaded document
- Supports PDF, Markdown (.md), and text (.txt) files
- Markdown files are rendered with GitHub-style formatting
- Text files displayed with syntax highlighting
- PDF preview (rendering to be implemented)
-
Chat Interface (Right Pane - 40% width)
- Dialogue-style chat interface
- User messages appear in blue bubbles (right-aligned)
- AI responses appear in grey bubbles (left-aligned)
- Auto-scrolls to latest messages
- Full conversation history visible
File Selector Button
- Click "Load Document" to open file picker
- Supports:
.pdf,.md,.txtfiles - Currently loaded document name displayed next to button
Model Selector Dropdown
- Select from available Ollama models
- Automatically populated from your Ollama server
- Refresh button to update model list
- Uses configuration from General Settings tab
-
Launch the GUI
uv run python bmlibrarian_config_gui.py
-
Navigate to Document Interrogation Tab
- Click the "Document Interrogation" tab (chat icon)
-
Configure LLM Model
- Select a model from the dropdown
- Use the refresh button if models don't appear
- Ensure Ollama server is running (default: http://localhost:11434)
-
Load a Document
- Click "Load Document" button
- Select a PDF, Markdown, or text file
- Document will appear in the left pane
-
Ask Questions
- Type your question in the message input field
- Press Enter or click Send button
- AI responses will appear in the chat area
Message Input
- Supports multi-line input (up to 3 lines visible)
- Press Enter to send message
- Press Shift+Enter for new line
- Input validated before sending (requires loaded document and selected model)
Message Bubbles
- User messages: Blue background, right-aligned, labeled "You"
- AI responses: Grey background, left-aligned, labeled "AI Assistant"
- All messages are selectable for copying
- Maximum bubble width: 500px for readability
System Messages
- Welcome message when tab first opened
- Confirmation when document loaded
- Notification when model changed
The Document Interrogation tab can be integrated with other plugins:
# Access the tab from the config app
doc_tab = app.tab_objects['document_interrogation']
# Load document programmatically
doc_tab.load_document_programmatically('/path/to/document.pdf')
# Clear chat history
doc_tab.clear_chat()┌─────────────────────────────────────────────────────────────────┐
│ Top Bar (60px height, grey background) │
│ [Load Document] 📄 filename.pdf [Model ▼] [🔄] │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────┬────────────────────────────────────┐ │
│ │ Document Viewer │ Chat │ │
│ │ (60% width) │ (40% width) │ │
│ ├────────────────────┼────────────────────────────────────┤ │
│ │ │ ┌──────────────────────────────┐ │ │
│ │ │ │ Chat Messages (scrollable) │ │ │
│ │ Document │ │ │ │ │
│ │ Content │ │ ┌─────────────────┐ │ │ │
│ │ Display │ │ │ AI: Welcome... │ │ │ │
│ │ Area │ │ └─────────────────┘ │ │ │
│ │ │ │ │ │ │
│ │ (Scrollable) │ │ ┌──────────────────┐ │ │ │
│ │ │ │ │ You: Question... │ │ │ │
│ │ │ │ └──────────────────┘ │ │ │
│ │ │ └──────────────────────────────┘ │ │
│ │ ├────────────────────────────────────┤ │
│ │ │ [Type message here...] [📤 Send] │ │
│ └────────────────────┴────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Top Bar
- Background: Grey 100 (#F5F5F5)
- Button: Blue 600 with white text
- Text: Black 87%
Document Viewer
- Background: White
- Border: Grey 400 on right side (separator)
- Header: Grey 200 background
Chat Interface
- Background: Grey 50
- Border: Grey 300
- User message bubbles: Blue 600 background, white text
- AI message bubbles: Grey 200 background, black 87% text
- Input area: White background with Blue 400 border
- Top bar height: 60px
- Top bar padding: 10px all sides
- Split pane ratio: 3:2 (60%:40%)
- Message bubble padding: 12px all sides
- Message bubble border radius: 12px (with one corner squared based on sender)
- Message bubble max width: 500px
- Message bubble spacing: 5px bottom margin
- Chat input height: Auto (1-3 lines)
- Enter: Send message
- Shift+Enter: New line in message input
- Ctrl+L: Load document (when button focused)
-
PDF Rendering
- Full PDF page rendering using PyMuPDF or pdf2image
- Page navigation controls
- Zoom in/out functionality
- Text selection and highlighting
-
LLM Integration
- Complete implementation of LLM processing
- Document context passing to LLM
- Streaming responses
- Citation extraction (highlight relevant passages)
-
Enhanced Document Support
- DOCX file support
- HTML rendering
- Code syntax highlighting for source files
- Image file display
-
Chat Features
- Export chat history
- Clear chat button
- Search within conversation
- Copy message buttons
- Message timestamps
-
Layout Improvements
- Draggable splitter between panes
- Collapsible document viewer
- Full-screen mode for document
- Resizable chat input
-
Document Analysis
- Automatic document summarization
- Table of contents extraction
- Key terms identification
- Reference extraction
File: src/bmlibrarian/gui/tabs/document_interrogation_tab.py
Main Class: DocumentInterrogationTab
Key Methods:
build(): Constructs the UI layout_build_top_bar(): Creates file selector and model dropdown_build_split_pane(): Creates two-pane layout_build_document_viewer_pane(): Left pane for documents_build_chat_interface_pane(): Right pane for chat_load_document(): Loads and displays documents_create_message_bubble(): Creates styled chat bubblesload_document_programmatically(): API for external integration
- Flet: UI framework
- Ollama: LLM model provider
- Python pathlib: File path handling
- Future: PyMuPDF for PDF rendering
Uses configuration from ~/.bmlibrarian/config.json:
ollama.host: Ollama server URLollama.timeout: Request timeoutollama.max_retries: Connection retry attempts
Problem: Model dropdown is empty
Solutions:
- Ensure Ollama server is running:
ollama serve - Check Ollama host in General Settings tab
- Click the refresh button (🔄) next to model dropdown
- Verify network connectivity to Ollama server
Problem: Error when loading document
Solutions:
- Check file permissions
- Verify file format is supported (.pdf, .md, .txt)
- Ensure file is not corrupted
- Check file size (very large files may timeout)
Problem: Send button doesn't work
Solutions:
- Ensure document is loaded
- Verify model is selected
- Check message input is not empty
- Confirm Ollama server is running
Status: PDF rendering is currently a placeholder
Workaround: For now, PDF content is loaded for LLM processing but not visually rendered. Use text or markdown files for full preview functionality until PDF rendering is implemented.
1. Load Document: research_paper.pdf
2. Select Model: gpt-oss:20b
3. Ask: "What are the main findings of this study?"
4. Ask: "What methods did the authors use?"
5. Ask: "Are there any limitations mentioned?"
1. Load Document: README.md
2. Select Model: medgemma4B_it_q8:latest
3. Ask: "Summarize the installation instructions"
4. Ask: "What are the main features?"
5. Ask: "Are there any API examples?"
1. Load Document: contract.txt
2. Select Model: gpt-oss:20b
3. Ask: "What are the key obligations?"
4. Ask: "Are there any termination clauses?"
5. Ask: "What are the payment terms?"
- Research GUI: Multi-agent workflow for literature search
- Document Interrogation: Single document Q&A interface
- Use case: Different focus - broad research vs. deep document analysis
- CLI: Programmatic access, scripting
- Document Interrogation: Visual, interactive, user-friendly
- Use case: GUI for human interaction, CLI for automation
class DocumentInterrogationTab:
"""Document interrogation tab with split-pane viewer and chat."""
def __init__(self, app: BMLibrarianConfigApp):
"""Initialize the tab with reference to main app."""
def build(self) -> ft.Container:
"""Build and return the tab UI layout."""
def load_document_programmatically(self, file_path: str):
"""
Load a document programmatically.
Args:
file_path: Absolute path to document
"""
def clear_chat(self):
"""Clear the chat history and reset to welcome message."""class ChatMessage:
"""Represents a single chat message."""
def __init__(self, text: str, is_user: bool):
"""
Create a chat message.
Args:
text: Message content
is_user: True if user message, False if AI response
"""-
Document Selection: Choose the right file format
- Use Markdown for best rendering quality
- Text files for simple content
- PDFs when necessary (rendering pending)
-
Model Selection: Match model to task
gpt-oss:20b: Complex analysis, research papersmedgemma4B_it_q8:latest: Fast responses, simple questions- Larger models: Better accuracy, slower responses
-
Question Formulation: Ask clear, specific questions
- ✅ "What are the three main conclusions?"
- ❌ "Tell me about this"
- ✅ "What methods are used in section 3?"
- ❌ "Summarize everything"
-
Chat Management: Keep conversations focused
- Clear chat when switching topics
- Load new document for different analysis
- Export important conversations (future feature)
To enhance the Document Interrogation tab:
- PDF Rendering: Implement using PyMuPDF or pdf2image
- LLM Processing: Add actual Ollama integration
- UI Enhancements: Draggable splitter, better styling
- Additional Formats: DOCX, HTML, images
See CLAUDE.md for development guidelines.