From 68fe9599cdb853eb1205499d44ed176613f875df Mon Sep 17 00:00:00 2001 From: tayadwx <42323260+tayadwx@users.noreply.github.com> Date: Fri, 25 Sep 2026 12:33:59 +0800 Subject: [PATCH] feat(gallery): add an image gallery tab with schema-driven filters (#3694) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(image): observe image attributes and let the policy decide OCR Describe each image with the VLM as before, but ask it to also observe two attributes about the image in the same round — how much body text it carries (contain.text) and whether it presents data visually (contain.data_visual) — then let a small pure function decide whether that image is worth a second, separate OCR round. Per-class OCR was the first shape of this idea; a class (chart / photo / logo) is only an indirect proxy for 'is there text worth reading here', and the class table has to grow whenever a new kind of image shows up. The decision actually needs the observed attributes, so it reads them directly, and the attribute set is a backend registry row rather than a new class. The observation and the caption share one VLM call; OCR stays a separate call (prompt isolation, see #3291). An attribute the model does not answer for is left absent rather than filled with a conservative default, so the trace never claims an observation that did not happen, and an incomplete observation falls back to the on_unobserved policy (OCR still runs). The registry also carries the panel's display text, so a new attribute needs no frontend change. Off by default: image_attrs_enabled=false keeps today's behaviour (one caption and one OCR per image). KB config: image_processing_config.image_attrs_enabled / image_actions; per-upload override via process_config. Registry: GET /api/v1/image-attrs/schema. * feat(gallery): add image gallery tab with schema-driven filters Adds a 4th knowledge-base tab parallel to Documents/Wiki/Graph that browses every image asset in a KB. Backend: - GET /api/v1/knowledge-bases/:id/images lists image assets projected from chunks.image_info, with keyword (caption/OCR), multi-value attribute (attr_=), is_enabled and sort filters applied in memory, plus pagination. - Resolves the source knowledge item title (SourceName) via a batched GetKnowledgeBatch so the viewer can show a human-readable source. Frontend: - ImageGallery.vue: thumbnail grid + search/sort + schema-driven filter panel (from GET /image-attrs/schema) + single-image viewer with prev/next, attributes/caption/OCR/source. - Wired as the gallery tab in KnowledgeBase.vue; i18n keys in all 5 locales. * feat(gallery): drive filters/search/sort from a configurable attribute contract The gallery UI is no longer hardcoded: it renders from a self-describing contract served by GET /knowledge-bases/:id/gallery-config (live attribute sources, every attribute's definition with usage flags merged across the config tiers, and the caller's search activation state). - Attribute sources form an open registry (types.RegisterGalleryAttrSource); a builtin source models caption/ocr_text/timestamps/enabled so the gallery has zero special cases. - Usage resolution: user > KB > system > source, field by field; the system tier lives in system_settings (gallery.policy, JSON, no rebuild), the KB tier slot is wired in the engine but not stored yet. - Search activation is the user's own record: mode (all|custom) plus per-field on/off in users.preferences.gallery; source declarations never set defaults (unrecorded = off in custom mode). - image_info is read through a gallery-local struct, removing the compile dependency on the attribute-pipeline types; the gallery builds and runs with or without that feature deployed. - ListImages validates search_in / sort_by / attr_filters against the contract; ineligible fields are dropped, not served. * fix(frontend): inline the shared graph-drawer stylesheet (@import instead of - + + diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index d39564ae..d8170d67 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -54,6 +54,7 @@ import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess'; import { useUploadConfirmStore, type UploadConfirmResult } from '@/stores/uploadConfirm'; import { useUploadTasksStore } from '@/stores/uploadTasks'; import WikiBrowser from './wiki/WikiBrowser.vue'; +import ImageGallery from './gallery/ImageGallery.vue'; import { getWikiStats } from '@/api/wiki'; import { isKnowledgeParseInFlight, @@ -91,7 +92,7 @@ const kbLoading = ref(false); const docListLoading = ref(true); const isFAQ = computed(() => (kbInfo.value?.type || '') === 'faq'); const isWiki = computed(() => !!kbInfo.value?.indexing_strategy?.wiki_enabled); -const validTabs = ['documents', 'wiki', 'graph'] as const +const validTabs = ['documents', 'wiki', 'graph', 'gallery'] as const type KbTab = typeof validTabs[number] const initTab = validTabs.includes(route.query.tab as any) ? (route.query.tab as KbTab) : 'documents' const activeKbTab = ref(initTab); @@ -2257,9 +2258,9 @@ const handleKBEditorSuccess = (kbIdValue: string) => { + {{ $t('knowledgeEditor.wikiBrowser.tabDocuments') }} - {{ $t('knowledgeEditor.document.title') }} + + {{ $t('knowledgeEditor.wikiBrowser.tabGallery') }} +
@@ -2316,7 +2321,12 @@ const handleKBEditorSuccess = (kbIdValue: string) => { @view-graph="onViewWikiInGraph" />
-