[Bug]: Images whose VLM caption/OCR fails are silently dropped (0 chunks, no retry, span marked done) — pages vanish from gallery and retrieval
Affected Component
Backend Service & API
Bug Description
When the per-image VLM step fails (HTTP timeout, or the completion hits the 5000-token cap), every product of that image is discarded and no chunk is written at all. The parent span is still marked done, the task never retries, and nothing surfaces the loss. The page disappears from both the image gallery and retrieval.
Concretely: a 48-page PDF produced 48 page images upstream, but the knowledge base ended up with 40 image_vector chunks. 8 pages were gone with no error visible anywhere in the UI or API.
The relevant code path (internal/application/service/image_multimodal.go, the chunk-building block):
if len(newChunks) == 0 {
// Deferred finalize will count this image on success.
out["skipped"] = "no_extracted_content"
if out["ocr_status"] == "failed" {
out["skipped"] = "ocr_failed"
}
return nil // <-- reported as success, never retried
}
So an image whose caption failed and whose OCR also failed writes zero chunks and returns nil. chunks_created stays 0 and the span is done.
Two hard-coded limits make this easy to trigger (internal/models/vlm/remote_api.go):
defaultTimeout = 180 * time.Second // line 23
defaultMaxToks = 5000 // line 24
...
MaxTokens: defaultMaxToks, // line 116
if resp.FinishReason == "length" {
return "", fmt.Errorf("%w at %d tokens (finish_reason=length)", ErrTruncatedCompletion, defaultMaxToks)
}
defaultMaxToks has no env override, so dense-table pages (hundreds of numbers) on a full-page scan routinely exceed it, and their OCR text is thrown away entirely rather than truncated-and-kept.
Steps to Reproduce
- Docker Compose deployment, KB with
image_vector_enabled=trueand per-file-typeparser_engine_rulesroutingpdfto MinerU (self-hosted adapter that returns one full-page PNG per page). - Set
WEKNORA_ASYNQ_ENRICHMENT_CONCURRENCYhigh (we had 64; official default 12) so the image queue saturates the VLM endpoint. - Upload a 48-page scanned/drawing PDF whose pages include several full-page data tables. We used a 250-DPI, 4136×2924 PNG per page.
- Let processing finish. Observe:
SELECT chunk_type, count(*) FROM chunk_images
WHERE knowledge_id = '<id>' GROUP BY chunk_type;
-- image_caption | 38
-- image_vector | 40
-- image_ocr | 30
SELECT name, output FROM knowledge_processing_spans
WHERE knowledge_id = '<id>' AND name LIKE 'multimodal.image[%'
AND name NOT LIKE '%.ocr' AND output->>'chunks_created' = '0';
{"chunks_created": 0,
"caption_error": "VLM request: create chat completion: send request: Post \"http://<vlm>/v1/chat/completions\": context deadline exceeded",
"ocr_error_code": "OCR_TRUNCATED",
"ocr_error": "VLM completion truncated at 5000 tokens (finish_reason=length)",
"outcome": "failed", "skipped": "ocr_failed"}
POST /api/v1/knowledge-bases/{id}/imagesreportstotal: 40for a 48-page PDF, and the 8 pages are unfindable via/knowledge-search.
Expected Behavior
- If only one of caption / OCR fails, the other product should still be persisted (today it depends on which round failed — images whose OCR truncated but whose caption succeeded do survive; images whose caption timed out do not).
- A failed VLM step should be retried, or at least marked as a failed subtask rather than
done. - A page image whose products are all empty should not vanish silently. Either keep an
image_vectorchunk with a placeholder, or mark the knowledge itempartialand reportpages_expectedvsimages_indexed. defaultMaxToks = 5000should be configurable (env or per-KB), since dense tables legitimately need more output budget.
Actual Behavior
- 8 of 48 pages produced
chunks_created: 0and are absent fromchunk_images, the gallery, and retrieval. - Spans are
done;parse_statusiscompleted. Both the UI and the API report success. - No retry, no warning in logs at default level (
[ImageMultimodal] Skipping ...is not emitted for this path).
WeKnora Version
App Version: v0.8.3 (image wechatopenai/weknora-app:v0.8.3)
Deployment Method
Docker Compose
Operating System
Ubuntu (kernel 6.8.0-136), Docker Compose on Linux
Relevant Logs
# asynq pool startup (showing the concurrency that caused the timeouts)
asynq enrichment-pool server starting with concurrency=64 total_upstream=152
# span output for one of the 8 lost pages
{"outcome":"failed","skipped":"ocr_failed","ocr_chars":0,
"ocr_error":"VLM completion truncated at 5000 tokens (finish_reason=length)",
"ocr_prompt":"default","ocr_status":"failed","image_bytes":897252,
"vlm_model_id":"<model-id>",
"caption_error":"VLM request: create chat completion: send request: Post \"http://<vlm>/v1/chat/completions\": context deadline exceeded",
"chunks_created":0,"ocr_error_code":"OCR_TRUNCATED"}
Side note that confirms it is load-dependent, not model-dependent: re-running the same 8 images individually against the same VLM returned 653–3381 tokens each with finish_reason=stop in 12–66 s. After lowering WEKNORA_ASYNQ_ENRICHMENT_CONCURRENCY to 12 and setting VLM_HTTP_TIMEOUT_SECONDS=300, a full reparse produced 48/48 image_caption and 48/48 image_vector. So the data loss is caused by saturation hitting the 180 s default, and the 5000-token cap remains the second, independent failure source.
Verified in v0.9.0 (tag f17ee8a8) — both halves of this report are addressed, closing.
1. defaultMaxToks is now configurable (internal/models/vlm/remote_api.go):
// defaultMaxToks is the fallback completion budget ... Reasoning vision models
// spend part of it on hidden thinking tokens, so a dense scanned page can stop
// at finish_reason=length; raise it via VLM_MAX_TOKENS.
func vlmMaxTokens() int { ... os.Getenv("VLM_MAX_TOKENS") ... }
2. An image that produces no content now fails loudly and retries (internal/application/service/image_multimodal.go):
if len(newChunks) == 0 && extractionFailed {
out[keyOutcome] = outcomeFailed
handleErr = fmt.Errorf("image produced no content: %w", rc.vlmErr) // retried, SkipRetry for permanent
return handleErr
}
v0.8.3 returned nil here, which is why the pages vanished with a green span.
Measurement that motivated this, in case it helps others tune VLM_MAX_TOKENS: on a dense rebar-quantity sheet at 250 DPI, Qwen3.8-27B-NVFP4 through an OpenAI-compatible endpoint used 5000 completion tokens with thinking on (finish_reason=length, reasoning_content 7529 chars) versus 2496 tokens with enable_thinking:false for the identical prompt. Same page, twice the budget consumed by hidden thinking.