WeKnora/internal/application
tayadwx 7ea5bf4349
fix(image): stop appending KB custom instructions to the OCR prompt OCR提示词不再错误的附加图片解析用户自定义提示词 (#3291)
* fix(image): stop appending KB custom instructions to the OCR prompt

CustomInstructions is documented as adding image interpretation guidance
"without replacing the system-owned OCR and Markdown output contract"
(types.VLMConfig.CustomInstructions), and the UI states the same. But
image_multimodal.go appended the same custom-instruction string to both
the caption prompt and the OCR prompt, so free-form business rules
(e.g. output-marker rules intended for descriptions) competed with the
OCR prompt's own contract that a text-free image must reply exactly
"No text content".

On a production knowledge base this poisoned 116/255 (45%) of image_ocr
chunks: the 8B VLM leaned on the nearest output-format rule and emitted
the KB's fixed marker phrase instead of "No text content", which passed
the sanitizer (it only recognizes known empty replies), created enabled
image_ocr child chunks with vectors, and made real photos retrievable as
decorative-image hits. Section names from the custom instructions
appeared verbatim in OCR output, confirming prompt cross-contamination.

Caption prompts keep their custom instructions; only the OCR append is
removed.

* test(image): pin the OCR prompt contract against custom instructions

Extract buildVLMOCRPrompt so the OCR prompt assembly is unit-testable and
add a regression test asserting that KB custom instructions never reach
the OCR prompt (while the caption prompt keeps them), and that the
No text content contract stays intact for both source types.

---------

Co-authored-by: tayadwx <tayadwx@users.noreply.github.com>
2026-09-19 23:37:28 +08:00
..
access refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
repository fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
service fix(image): stop appending KB custom instructions to the OCR prompt OCR提示词不再错误的附加图片解析用户自定义提示词 (#3291) 2026-09-19 23:37:28 +08:00