feat: vision LLM description pipeline for image documents#111
Open
nv78 wants to merge 1 commit intoclaude/add-multimodal-support-QBQcafrom
Open
feat: vision LLM description pipeline for image documents#111nv78 wants to merge 1 commit intoclaude/add-multimodal-support-QBQcafrom
nv78 wants to merge 1 commit intoclaude/add-multimodal-support-QBQcafrom
Conversation
When a user uploads an image file (JPEG, PNG, GIF, WebP, BMP, TIFF) via the document upload flow, instead of attempting text extraction through Tika, the new vision pipeline: 1. Reads the raw image bytes from the upload 2. Calls describe_image() in the new services/vision_service.py module which invokes the configured vision-capable LLM (GPT-4o with detail=high or Claude 3.5 Sonnet) with a detailed indexing prompt that asks the model to transcribe text, describe charts/diagrams/objects, and capture layout 3. Stores the resulting description as document_text in the documents table (media_type='image', mime_type=<actual mime>) 4. Feeds the description into the existing chunk_document Ray task so it is split, embedded, and indexed — making the image fully searchable via RAG services/vision_service.py: - describe_image(bytes, mime_type, prompt?) -> str - _describe_openai(): uses openai.OpenAI client with image_url content block (detail=high for better OCR accuracy) - _describe_anthropic(): uses anthropic.Anthropic client with source block - Respects ENABLE_MULTIMODAL and MAX_IMAGE_BYTES config flags - Never raises — returns a placeholder string on failure so the document record is always created documents/handler.py: - New elif category == "image" branch reads bytes, calls describe_image(), stores description, and enqueues chunking via Ray remote - video/audio remain as binary-only stubs (PRs 3 & 4) https://claude.ai/code/session_01C9mHttiQ4ZAaBbQecVV7uu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a user uploads an image file (JPEG, PNG, GIF, WebP, BMP, TIFF) as a document, instead of attempting extraction through Apache Tika (which produces nothing useful for images), the new vision pipeline generates a rich text description via GPT-4o or Claude 3.5 Sonnet and feeds it into the existing RAG chunking + embedding pipeline. The image becomes fully searchable.
New file:
backend/services/vision_service.pydescribe_image(bytes, mime_type, prompt?)— main entry point; dispatches to the correct provider based onAgentConfig.DEFAULT_AGENT_MODEL_TYPE_describe_openai()— callsopenai.OpenAIwith animage_urlcontent block usingdetail=highfor better OCR accuracy_describe_anthropic()— callsanthropic.Anthropicwith asourcecontent block_INDEXING_PROMPTthat asks the model to transcribe text verbatim, describe charts/diagrams/objects/layout, and be thorough for search indexingENABLE_MULTIMODALandMAX_IMAGE_BYTESconfig flagsUpdated:
backend/api_endpoints/documents/handler.pyNew
elif category == "image"branch inIngestDocumentsHandler:describe_image()document_text(withmedia_type='image',mime_type)chunk_document_fn.remote()so the description is split, embedded, and indexedVideo and audio remain as binary-only stubs — to be wired up in PRs 3 & 4.
Test plan
media_type='image'chunkstable after the Ray task completesdescribe_imagereturns a size-limit placeholder, document still createdENABLE_MULTIMODAL=false→ placeholder text stored, no LLM call madehttps://claude.ai/code/session_01C9mHttiQ4ZAaBbQecVV7uu