WeKnora/internal/searchutil
vicfei 2dd36212d6 fix(knowledge): bind extracted images to their document and unscope shared-KB parent lookups
Org-shared KB viewers got 403 for extracted images on current main even
though the retrieving chunk text carried the resource:// handle and the
share grant was valid (#3342, second report after #3022/#3069).

Root cause is a mismatch between ingestion and authorization: document
parses store extracted images through SaveBytes, which registers the
resource but never claims it, while both file proxies (ResolveKBFile and
the message fallback via resourceAccessibleViaSharedKB) authorize through
IsReferencedByKnowledgeBase — which accepts explicit resource_bindings
rows only. The binding-only hardening landed without adding the missing
bindings, so every extracted image became invisible cross-workspace.

Ingestion: bindStoredImages claims each stored image for its knowledge
(ResourceRelationExtractedImage), mirroring bindContentResources — best
effort, same-workspace resources only. Wired into both the file-parse
path (knowledge_process) and manual knowledge (triggerManualProcessing).

Merge: resolveParentChunks fetched parents, grandparents, and image_info
children with the caller's tenant, so shared-KB hits from the sharing
workspace resolved none of them and lost parent context and image_info
(the second defect in the #3342 audit). Those lookups now use the
existing *Only unscoped variants, matching their shared-KB precedent.

Historical documents parsed before this change still carry no bindings;
a backfill is tracked as the follow-up slice.

Verified end-to-end on a fresh stack: publishing a manual document with
an embedded image now records kind=image plus an extracted_image binding
alongside the content-derived attachment binding.
2026-09-22 17:52:49 +08:00
..
chunkmerge.go fix(chunk-merge): stop dropping content when contiguous chunks repeat text 2026-08-13 19:58:57 +08:00
chunkmerge_test.go fix(chunk-merge): stop dropping content when contiguous chunks repeat text 2026-08-13 19:58:57 +08:00
conversion.go feat(web-search): refactor web search provider 2026-03-31 20:22:34 +08:00
imageinfo.go fix(knowledge): bind extracted images to their document and unscope shared-KB parent lookups 2026-09-22 17:52:49 +08:00
imageinfo_disabled_test.go fix(retrieval): 分段中删除的图片不再被检索到 2026-08-20 12:01:28 +08:00
imageinfo_html_test.go fix(docparser): resolve remote images referenced by HTML img tags (#2355) 2026-07-28 21:08:31 +08:00
imageinfo_match.go fix(docparser): resolve remote images referenced by HTML img tags (#2355) 2026-07-28 21:08:31 +08:00
imageinfo_match_test.go fix(chat): keep OCR/caption text of scanned-page image hits in merge (#3064) 2026-09-07 11:38:47 +08:00
normalize.go refactor: Introduce searchutil package for web search result conversion and keyword score normalization 2025-12-01 18:27:12 +08:00
textutil.go refactor(chat_pipeline): enhance merging logic and add partial overlap removal 2026-03-25 22:08:29 +08:00