Source Code:
src/gaia/llm/vlm_client.pyComponent: VLMClient
Module:
gaia.llm.vlm_client
Import: from gaia.llm import VLMClientOverview
VLMClient provides Vision-Language Model capabilities for extracting text from images using Lemonade server. It handles image-to-markdown conversion with on-demand model loading and downloading, and context manager support. Key Features:- Image-to-text extraction via VLM
- Automatic model loading and downloading
- Base64 image encoding
- Batch processing for multiple images
- Context manager for resource cleanup
- Integration with LemonadeClient
Requirements
Functional Requirements
-
Model Management
- Load VLM model (Gemma-4-E4B-it-GGUF)
- Automatic model download via Lemonade
- Model availability checking
- Every request re-checks the model is loaded at its required context size
-
Image Extraction
extract_from_image()- Extract text from single imageextract_from_page_images()- Batch extraction from page- Custom extraction prompts
- Progress logging
-
Image Format Support
- PNG images (base64 encoded)
- JPEG images (base64 encoded)
- Automatic image optimization (handled by caller)
- Size and dimension tracking
-
Resource Management
- Context manager support (
with VLMClient()) - Cleanup after processing
- Context manager support (
-
Error Handling
- Model availability errors
- Loading failures (the real load error text, e.g. out of memory)
- Extraction failures
- Connection errors
Non-Functional Requirements
-
Performance
- 300-second timeout for VLM image extraction (5 minutes for complex forms)
- Model loads use LemonadeClient’s load timeout, not the extraction timeout
- Low temperature (0.1) for accuracy
- Up to 2048 tokens per extraction
- Progress logging for user feedback
-
Reliability
- Automatic model download (may take hours)
- Graceful error handling
- Helpful error messages
- Connection retry via LemonadeClient
-
Usability
- Simple initialization
- Auto-load option
- Clear progress messages
- Context manager pattern
API Specification
File Location
Public Interface
Implementation Details
Model Loading
There is no separate pre-load.extract_from_image() passes
auto_download=self.auto_load to LemonadeClient.chat_completions(), which
loads the model at its required context size (and downloads it if missing)
while holding the model-slot lease, then runs the request. A load failure
propagates and is re-raised as VLMExtractionError with the original error
text and the cause attached. Because every request re-checks the load, a model
evicted mid-batch is reloaded on the next page.
Image Extraction
Error Handling
A failure raises rather than returning text. Callers translate it at their own boundary — the RAG PDF/PPTX paths skip the page and record a warning, the vision tools return an error envelope, andproviders.lemonade.vision() propagates.
Nothing that failed is ever indexed as content (#3555).
Server URL Parsing
Testing Requirements
Unit Tests
File:tests/llm/test_vlm_client.py
Integration Tests
Dependencies
Required Packages
Import Dependencies
Usage Examples
Example 1: Basic Image Extraction
Example 2: Context Manager (Recommended)
Example 3: Batch Processing
Example 4: Custom Extraction Prompt
Example 5: Remote Lemonade Server
Example 6: Error Handling
Documentation Updates Required
docs/sdk/sdks/vlm.mdx
Add to Vision Section:VLMClient Technical Specification