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:
@@ -2308,10 +2308,11 @@ func (s *knowledgeService) getSummary(ctx context.Context,
|
||||
// scanner model), and feeding that to the model would invite it to
|
||||
// hallucinate a scanner manual instead of admitting the document had no
|
||||
// extractable text.
|
||||
if !hasSufficientTextContent(chunkContents) {
|
||||
realTextLen := realTextRuneCount(chunkContents)
|
||||
if realTextLen < minTextContentRunes {
|
||||
logger.GetLogger(ctx).Warnf(
|
||||
"getSummary: content for knowledge %s has insufficient text after stripping image markup (len=%d); skipping LLM call",
|
||||
knowledge.ID, len([]rune(strings.TrimSpace(stripImageMarkup(chunkContents)))),
|
||||
"getSummary: content for knowledge %s has insufficient text after stripping image markup (real_text_runes=%d, min=%d); skipping LLM call",
|
||||
knowledge.ID, realTextLen, minTextContentRunes,
|
||||
)
|
||||
return "", errInsufficientSummaryContent
|
||||
}
|
||||
@@ -2536,12 +2537,17 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn
|
||||
}
|
||||
}
|
||||
|
||||
// Embed only the LLM-generated summary in the indexed chunk.
|
||||
// We deliberately omit knowledge.FileName here: filenames are an
|
||||
// unreliable signal (e.g. "MX5280.pdf" for a scanned legal letter)
|
||||
// and surfacing them in retrieved RAG context can re-introduce the
|
||||
// hallucination vector this branch is meant to close.
|
||||
summaryChunk := &types.Chunk{
|
||||
ID: uuid.New().String(),
|
||||
TenantID: knowledge.TenantID,
|
||||
KnowledgeID: knowledge.ID,
|
||||
KnowledgeBaseID: knowledge.KnowledgeBaseID,
|
||||
Content: fmt.Sprintf("# Document\n%s\n\n# Summary\n%s", knowledge.FileName, summary),
|
||||
Content: fmt.Sprintf("# Summary\n%s", summary),
|
||||
ChunkIndex: maxChunkIndex + 1,
|
||||
IsEnabled: true,
|
||||
CreatedAt: time.Now(),
|
||||
|
||||
Reference in New Issue
Block a user