fix(ingest): QA follow-up — preserve OCR text and close remaining filename leaks
Self-review of the prior commit surfaced one critical regression and
several smaller issues. This change addresses them.
Critical: the old stripImageMarkup stripped the WHOLE <image>...</image>
block, but searchutil.EnrichContentWithImageInfo wraps successful VLM OCR
output in exactly that shape — so a scanned PDF where OCR worked was
being rejected by hasSufficientTextContent and routed to the same
"failed" path as the OCR-empty case. The fix splits stripping into:
* <image_original>...</image_original> blocks removed entirely
(they only carry the redundant Markdown ref already stripped above)
* <image>, <images>, <image_caption>, <image_ocr> tags removed at
the tag level, INNER TEXT PRESERVED, so OCR / caption text reaches
the threshold check and the LLM call.
A regression test pins this down with realistic enriched-image XML that
the previous code failed silently on.
Other fixes:
* Threshold lowered from 50 to 10 runes — short legitimate documents
(brief memos, single-line notes) must still pass.
* Summary chunk content no longer prefixes "# Document\n<filename>";
only the LLM-generated summary is indexed, so filenames cannot
leak back into RAG retrieval context.
* Wiki summary slug is now derived from the knowledge ID rather than
the upload filename, eliminating filename-based slugs like
"summary/mx5280-pdf" that downstream wiki-edit prompts can read.
* Citation sourceRef likewise drops the "|<docTitle>" suffix.
* Dead docTitle parameter removed from extractCandidateSlugs,
extractEntitiesAndConceptsNoUpsert, classifyChunkCitations.
* The redundant stripImageMarkup pass in the warning log is gone;
realTextRuneCount caches the count once and uses
utf8.RuneCountInString to avoid the rune-slice allocation.
Wiki-page display titles still flow through DocTitle (filename) into
later wiki-edit / index-rebuild prompts. That is a larger refactor of
the wiki pipeline and is intentionally left for a separate PR.
This commit is contained in:
@@ -122,7 +122,24 @@ func TestStripImageMarkup(t *testing.T) {
|
||||
},
|
||||
{"mixed text and image keeps text", "Intro paragraph.\n\nConclusion.", "Intro paragraph.\n\nConclusion."},
|
||||
{"html img tag stripped", `Before <img src="x.png" alt="y"/> after`, "Before after"},
|
||||
{"images xml block stripped", "Body <images><image>x</image></images> tail", "Body tail"},
|
||||
{
|
||||
// Regression guard: an earlier version stripped the WHOLE
|
||||
// <image>...</image> block (including <image_ocr> content),
|
||||
// silently destroying successful VLM OCR results. The fix must
|
||||
// preserve the inner OCR / caption text.
|
||||
"enriched <image> block keeps inner OCR + caption text",
|
||||
`<image url="images/page_1.png">
|
||||
<image_original></image_original>
|
||||
<image_caption>scanned letter on letterhead</image_caption>
|
||||
<image_ocr>SEHR GEEHRTER HERR MUSTERMANN, ...</image_ocr>
|
||||
</image>`,
|
||||
"\n\nscanned letter on letterhead\nSEHR GEEHRTER HERR MUSTERMANN, ...\n",
|
||||
},
|
||||
{
|
||||
"empty <image> block (OCR failed) reduces to whitespace",
|
||||
`<image url="x"><image_original></image_original></image>`,
|
||||
"",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -147,20 +164,31 @@ func TestHasSufficientTextContent(t *testing.T) {
|
||||
"\n",
|
||||
false,
|
||||
},
|
||||
{"short text below threshold", "tiny", false},
|
||||
{"too-short text below 10-rune threshold", "hi", false},
|
||||
{
|
||||
"short text mixed with images still below threshold",
|
||||
"\nshort\n",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"sufficient text passes",
|
||||
"This is a substantial paragraph of real content describing a legal matter and the parties involved.",
|
||||
"short legitimate note above threshold",
|
||||
"Meeting at 3pm tomorrow.",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"image-only with successful VLM OCR (the fix)",
|
||||
`<image url="images/p1.png">
|
||||
<image_original></image_original>
|
||||
<image_caption>scanned letter</image_caption>
|
||||
<image_ocr>Sehr geehrter Herr Mustermann, in der Sache 4711/2024 ...</image_ocr>
|
||||
</image>`,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"image-only with failed VLM OCR (still rejected)",
|
||||
`<image url="images/p1.png">
|
||||
<image_original></image_original>
|
||||
</image>`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"sufficient text mixed with images still passes",
|
||||
"\nThis is a substantial paragraph of real content describing a legal matter and the parties involved.\n",
|
||||
"\nDie Beklagte hat die Klage anerkannt.\n",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user