feat: expose KB ↔ vector store binding in list, editor, and detail UI

Backend
-------
ListKnowledgeBases now enriches each row with the resolved vector_store
metadata (name / source / engine_type / status) via a new
buildKBListResponse helper. Store views are batch-resolved once per
request through BatchResolveStoreView so an N-KB list costs one
vector-store service call rather than N — closing the N+1 limitation
flagged in #1372's known-limitations section. Cross-tenant shared KBs
continue to render via SharedStoreDisplay so the owning tenant's store
inventory cannot be correlated across rows; the underlying vector_store_id
UUID is stripped from those responses.

Resolver failures degrade gracefully: bound KBs render as unavailable
instead of breaking the list. Test coverage pins the env / bound /
shared distinction, the batch-call-count invariant, and the
graceful-failure path.

Frontend
--------
KB editor modal gains a new "Vector Store" section. Create mode shows a
dropdown that combines the system default (env store) and the tenant's
configured user stores, fetched once at mount via the existing
listVectorStores API. Edit mode shows the bound store read-only via a
new VectorStoreBadge component with an explicit immutability hint —
matching the backend's `<-:create` GORM tag and the service-layer
UpdateKnowledgeBaseRequest DTO that already omit the field.

KB list cards surface a small engine-type badge for own-tenant bound
KBs, and a warning badge when the bound store is unavailable. Env-bound
and shared KBs render no badge (visual noise control). KB detail header
shows the bound store via the same VectorStoreBadge component; shared
KBs fall through to the badge's internal "shared" branch with no name /
engine / id rendered.

The KB editor's create-time error handler translates the typed
ErrVectorStoreBindingInvalid (2200) and ErrVectorStoreUnavailable
(2201) into localized messages and jumps the user back to the
VectorStore section so they can pick a different store or fall back to
the system default.

The KB row type gains five optional fields (vector_store_id / name /
engine_type / source / status). i18n: 18 new keys added to en-US,
ko-KR, zh-CN; ru-RU receives English placeholders pending translation
(consistent with prior PRs in this locale).

Part of #993 (Phase 2: Per-KB VectorStore Binding).
Phase 2 roadmap item: PR 5 (KB binding UI + list-response enrichment).
Depends on #994, #1310, #1372, #1386 (all backend in the Phase 2 series).
This commit is contained in:
ochan.kwon
2026-05-18 23:50:09 +09:00
committed by lyingbug
parent 0f57bf3ff8
commit 8b7d00b260
15 changed files with 1165 additions and 12 deletions
@@ -5,6 +5,7 @@ import DocContent from "@/components/doc-content.vue";
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
import { useRoute, useRouter } from 'vue-router';
import EmptyKnowledge from '@/components/empty-knowledge.vue';
import VectorStoreBadge from '@/components/VectorStoreBadge.vue';
import { getSessionsList, createSessions, generateSessionsTitle } from "@/api/chat/index";
import { useMenuStore } from '@/stores/menu';
import { useUIStore } from '@/stores/ui';
@@ -2058,6 +2059,19 @@ async function createNewSession(value: string): Promise<void> {
</template>
</span>
</t-tooltip>
<!-- Bound vector store indicator. Cross-tenant shared KBs
render via the badge's internal "shared" branch with
no name or engine type, matching the server-side
response that strips those fields for non-owners. -->
<template v-if="kbInfo && (kbInfo as any)?.vector_store_source">
<span class="kb-access-meta-sep">·</span>
<VectorStoreBadge
:source="(kbInfo as any).vector_store_source"
:name="(kbInfo as any).vector_store_name"
:engine-type="(kbInfo as any).vector_store_engine_type"
:status="(kbInfo as any).vector_store_status"
/>
</template>
</div>
<t-tooltip v-if="canManage" :content="$t('knowledgeBase.settings')" placement="top">
<button type="button" class="kb-settings-button" :disabled="!kbId" @click="handleOpenKBSettings">
@@ -152,6 +152,20 @@
/>
</div>
<!-- VectorStore 绑定 -->
<div v-show="currentSection === 'vectorStore'" class="section">
<KBVectorStoreSettings
v-if="formData"
:mode="mode"
:vector-store-id="formData.vectorStoreId"
:bound-source="formData.vectorStoreInfo?.source"
:bound-name="formData.vectorStoreInfo?.name"
:bound-engine-type="formData.vectorStoreInfo?.engineType"
:bound-status="formData.vectorStoreInfo?.status"
@update:vector-store-id="handleVectorStoreIdUpdate"
/>
</div>
<!-- FAQ 配置 -->
<div v-if="isFAQ && formData" v-show="currentSection === 'faq'" class="section">
<div class="section-content">
@@ -365,6 +379,7 @@ import KBModelConfig from './settings/KBModelConfig.vue'
import KBParserSettings from './settings/KBParserSettings.vue'
import KBStorageSettings from './settings/KBStorageSettings.vue'
import KBChunkingSettings from './settings/KBChunkingSettings.vue'
import KBVectorStoreSettings from './settings/KBVectorStoreSettings.vue'
import KBAdvancedSettings from './settings/KBAdvancedSettings.vue'
import ModelSelector from '@/components/ModelSelector.vue'
import GraphSettings from './settings/GraphSettings.vue'
@@ -398,8 +413,9 @@ const hasFiles = ref(false)
const initialStorageProvider = ref<string>('')
const initialIndexingStrategy = ref<any>(null)
const dsCount = ref(0)
// KB.creator_id (added in PR 5). Empty for legacy KBs — those fall back
// to "no owner", so only tenant Admin+ can mutate share settings.
// Identifier of the user who created this KB. Empty for older rows
// that predate per-KB ownership tracking; those KBs have no "owner" and
// only tenant Admin+ can mutate their share settings.
const kbCreatorId = ref<string>('')
// Backend gate for /knowledge-bases/:id/shares (POST/PUT/DELETE) is
@@ -437,7 +453,11 @@ const DEFAULT_CHUNKING_PRESET = {
const navItems = computed(() => {
const items: { key: string; icon: string; label: string; badge?: number }[] = [
{ key: 'basic', icon: 'info-circle', label: t('knowledgeEditor.sidebar.basic') },
{ key: 'models', icon: 'control-platform', label: t('knowledgeEditor.sidebar.models') }
{ key: 'models', icon: 'control-platform', label: t('knowledgeEditor.sidebar.models') },
// VectorStore binding section — present in both create and edit
// modes. Create mode shows a dropdown; edit mode shows the bound
// store read-only with an immutability hint.
{ key: 'vectorStore', icon: 'data-base', label: t('knowledgeEditor.sidebar.vectorStore') }
]
if (formData.value?.type === 'faq') {
items.push({ key: 'faq', icon: 'help-circle', label: t('knowledgeEditor.sidebar.faq') })
@@ -555,6 +575,16 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
wikiEnabled: false,
graphEnabled: false,
},
// Vector-store binding. Empty string means "use the env-configured
// store"; create mode defaults to that, edit mode loads the
// existing binding from the KB response below.
vectorStoreId: '' as string,
vectorStoreInfo: {
source: undefined as string | undefined,
name: undefined as string | undefined,
engineType: undefined as string | undefined,
status: undefined as string | undefined,
},
}
}
@@ -661,6 +691,19 @@ const loadKBData = async () => {
wikiEnabled: kb.indexing_strategy?.wiki_enabled ?? false,
graphEnabled: kb.indexing_strategy?.graph_enabled ?? false,
},
// Vector-store binding. vectorStoreId is editor-only state; it
// is only included in the create request, never the update
// request, because the binding is immutable after creation.
// vectorStoreInfo carries the read-only display fields that the
// edit view renders below; they come straight from the KB
// response.
vectorStoreId: '',
vectorStoreInfo: {
source: kb.vector_store_source,
name: kb.vector_store_name,
engineType: kb.vector_store_engine_type,
status: kb.vector_store_status,
},
}
initialStorageProvider.value = formData.value.storageProvider
initialIndexingStrategy.value = { ...formData.value.indexingStrategy }
@@ -793,6 +836,16 @@ const handleStorageProviderUpdate = (value: string) => {
}
}
const handleVectorStoreIdUpdate = (id: string) => {
if (formData.value) {
// Empty string here means "use system default" (env-store fallback).
// The create-payload assembly below converts this back to `omit` so
// the backend stores NULL — keeping the wire shape identical to
// pre-Phase-2 clients.
formData.value.vectorStoreId = id || ''
}
}
const handleQuestionGenerationUpdate = (config: any) => {
if (formData.value) {
formData.value.questionGenerationConfig = { ...config }
@@ -886,6 +939,15 @@ const buildSubmitData = () => {
summary_model_id: formData.value.modelConfig.llmModelId
}
// Vector-store binding. Only attach the field when the user actively
// selected a non-default store. The server treats an empty string as
// NULL, but keeping the field absent on the wire matches what a
// client that doesn't know about this binding would send — which
// makes A/B response diffs easier to read.
if (formData.value.vectorStoreId) {
data.vector_store_id = formData.value.vectorStoreId
}
// 添加多模态配置
data.vlm_config = {
enabled: formData.value.multimodalConfig.enabled,
@@ -1130,7 +1192,23 @@ const doSubmit = async () => {
handleClose()
} catch (error: any) {
console.error('Knowledge base operation failed:', error)
MessagePlugin.error(error?.message || t('common.operationFailed'))
// Vector-store-binding error codes from the server. Both indicate
// the selected store cannot be used: 2200 is "the binding itself
// is invalid" (e.g. unknown id, foreign tenant), 2201 is "the
// store is currently unreachable". For either, swap in a localized
// message and jump the user back to the Vector Store section so
// they can pick a different store or fall back to the system
// default.
const code = error?.response?.data?.error?.code ?? error?.code
if (code === 2200) {
MessagePlugin.error(t('knowledgeEditor.errors.vectorStoreBindingInvalid'))
currentSection.value = 'vectorStore'
} else if (code === 2201) {
MessagePlugin.error(t('knowledgeEditor.errors.vectorStoreUnavailable'))
currentSection.value = 'vectorStore'
} else {
MessagePlugin.error(error?.message || t('common.operationFailed'))
}
} finally {
saving.value = false
}
@@ -277,6 +277,32 @@
<t-icon name="share" size="14px" />
</div>
</t-tooltip>
<!-- Vector-store badge: shows the underlying engine
type (e.g. "postgres", "qdrant") for any KB whose
binding is currently reachable. Cross-tenant
shared KBs are filtered out upstream (their
engine_type is stripped from the response).
Unreachable bindings surface a red warning so
operators can self-recover from the badge alone. -->
<t-tooltip
v-if="kb.vector_store_engine_type && kb.vector_store_status === 'available'"
:content="kb.vector_store_name || ''"
placement="top"
>
<div class="feature-badge store">
<t-icon name="data-base" size="14px" />
<span class="badge-count">{{ kb.vector_store_engine_type }}</span>
</div>
</t-tooltip>
<t-tooltip
v-else-if="kb.vector_store_status === 'unavailable'"
:content="$t('kbSettings.vectorStore.unavailableHint')"
placement="top"
>
<div class="feature-badge store-warn">
<t-icon name="error-circle" size="14px" />
</div>
</t-tooltip>
</div>
</div>
<div v-if="!authStore.isLiteMode" class="bottom-right">
@@ -502,6 +528,29 @@
<t-icon name="share" size="14px" />
</div>
</t-tooltip>
<!-- Vector-store badge: identical rendering rule to
the badge in the other card variant above; kept
in sync so users see the same engine indicator
regardless of which filter scope they browse. -->
<t-tooltip
v-if="kb.vector_store_engine_type && kb.vector_store_status === 'available'"
:content="kb.vector_store_name || ''"
placement="top"
>
<div class="feature-badge store">
<t-icon name="data-base" size="14px" />
<span class="badge-count">{{ kb.vector_store_engine_type }}</span>
</div>
</t-tooltip>
<t-tooltip
v-else-if="kb.vector_store_status === 'unavailable'"
:content="$t('kbSettings.vectorStore.unavailableHint')"
placement="top"
>
<div class="feature-badge store-warn">
<t-icon name="error-circle" size="14px" />
</div>
</t-tooltip>
</div>
</div>
<div v-if="!authStore.isLiteMode" class="bottom-right">
@@ -843,6 +892,17 @@ interface KB {
creator_id?: string;
// creator_name 由后端 list 接口回填,仅用于卡片右下角来源徽章的 tooltip。
creator_name?: string;
// Resolved vector-store binding metadata, populated by the list and
// detail endpoints. Fields are optional so callers that don't request
// (or that receive a stripped cross-tenant response) still type-check.
// vector_store_engine_type is the canonical render trigger — env-bound
// and user-bound KBs both carry it; shared KBs and unreachable
// bindings leave it unset.
vector_store_id?: string | null;
vector_store_name?: string;
vector_store_engine_type?: string;
vector_store_source?: 'env' | 'user' | 'shared' | 'unavailable';
vector_store_status?: 'available' | 'unavailable';
}
const kbs = ref<KB[]>([])
@@ -2631,6 +2691,37 @@ const handleUploadFinishedEvent = (event: Event) => {
}
}
/* Vector-store engine badge. Shares the green palette used by the
document/FAQ "type" badges so the card-bottom feature row reads as
one consistent visual group. The badge-count slot carries the
engine name (e.g. "qdrant"), so the badge uses the same
variable-width treatment as the type badges. */
&.store {
background: rgba(7, 192, 95, 0.08);
color: var(--td-brand-color-active);
width: auto;
padding: 0 6px;
gap: 3px;
&:hover {
background: rgba(7, 192, 95, 0.12);
}
.badge-count {
font-size: 11px;
font-weight: 500;
}
}
&.store-warn {
background: rgba(229, 57, 53, 0.08);
color: var(--td-error-color);
&:hover {
background: rgba(229, 57, 53, 0.14);
}
}
&.role-admin {
background: rgba(7, 192, 95, 0.1);
color: var(--td-brand-color-active);
@@ -0,0 +1,268 @@
<template>
<div class="kb-vector-store-settings">
<div class="section-header">
<h2>{{ $t('kbSettings.vectorStore.title') }}</h2>
<p class="section-description">{{ $t('kbSettings.vectorStore.description') }}</p>
</div>
<!-- CREATE mode: dropdown -->
<div v-if="props.mode === 'create'" class="settings-group">
<div v-if="loading" class="loading-inline">
<t-loading size="small" />
<span>{{ $t('kbSettings.vectorStore.loading') }}</span>
</div>
<div v-else class="setting-row">
<div class="setting-info">
<label>{{ $t('kbSettings.vectorStore.engineLabel') }}</label>
<p class="desc">{{ $t('kbSettings.vectorStore.engineDesc') }}</p>
</div>
<div class="setting-control">
<t-select
v-model="localVectorStoreId"
size="medium"
:placeholder="$t('kbSettings.vectorStore.systemDefault')"
:clearable="true"
style="width: 100%; min-width: 240px;"
@change="handleChange"
>
<t-option :value="''" :label="$t('kbSettings.vectorStore.systemDefault')">
<span class="select-option">
<span>{{ $t('kbSettings.vectorStore.systemDefault') }}</span>
<t-tag
v-if="envEngineType"
theme="primary"
variant="light"
size="small"
>
{{ envEngineType }}
</t-tag>
</span>
</t-option>
<t-option
v-for="s in userStores"
:key="s.id"
:value="s.id || ''"
:label="s.name"
>
<span class="select-option">
<span>{{ s.name }}</span>
<t-tag theme="success" variant="light" size="small">
{{ s.engine_type }}
</t-tag>
</span>
</t-option>
</t-select>
<p class="option-hint">{{ $t('kbSettings.vectorStore.immutableHint') }}</p>
<a
href="javascript:void(0)"
class="go-settings"
@click.prevent="goToVectorStoreSettings"
>
{{ $t('kbSettings.vectorStore.goGlobalSettings') }}
</a>
</div>
</div>
</div>
<!-- EDIT mode: read-only display -->
<div v-else class="settings-group">
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('kbSettings.vectorStore.boundLabel') }}</label>
<p class="desc">{{ $t('kbSettings.vectorStore.immutableEdit') }}</p>
</div>
<div class="setting-control">
<VectorStoreBadge
:source="props.boundSource"
:name="props.boundName"
:engine-type="props.boundEngineType"
:status="props.boundStatus"
/>
<p
v-if="props.boundStatus === 'unavailable'"
class="option-hint change-warning"
>
{{ $t('kbSettings.vectorStore.unavailableHint') }}
</p>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useUIStore } from '@/stores/ui'
import { listVectorStores, type VectorStoreEntity } from '@/api/vector-store'
import type { VectorStoreSource, VectorStoreStatus } from '@/api/knowledge-base'
import VectorStoreBadge from '@/components/VectorStoreBadge.vue'
const props = defineProps<{
mode: 'create' | 'edit'
// create mode — current selection (empty string for env-default)
vectorStoreId?: string
// edit mode — bound store info already on the KB
boundSource?: VectorStoreSource
boundName?: string
boundEngineType?: string
boundStatus?: VectorStoreStatus
}>()
const emit = defineEmits<{
(e: 'update:vectorStoreId', id: string): void
}>()
const { t } = useI18n()
const uiStore = useUIStore()
const loading = ref(false)
const allStores = ref<VectorStoreEntity[]>([])
const localVectorStoreId = ref<string>(props.vectorStoreId || '')
// Only show user-defined stores in the dropdown. The env store is
// surfaced via the explicit "System default" entry at the top of the
// list; including it twice would confuse users about which one is the
// fallback path.
const userStores = computed(() => allStores.value.filter((s) => s.source === 'user'))
// Engine type for the env store, shown as a tag next to the "System
// default" label so users know which storage backend handles unbound
// KBs (e.g. "postgres"). When the env-store entry is missing or its
// engine type is not populated, the tag is hidden entirely rather than
// showing a placeholder.
const envEngineType = computed(() => {
const envStore = allStores.value.find((s) => s.source === 'env')
return envStore?.engine_type || ''
})
watch(
() => props.vectorStoreId,
(v) => {
localVectorStoreId.value = v || ''
},
)
const handleChange = (val: string | undefined) => {
// t-select's clear emits undefined; normalize to empty string so the
// parent treats both as "use system default".
emit('update:vectorStoreId', val || '')
}
// Open the global Settings panel directly on the Vector Stores
// section. This follows the same pattern as the other KB editor "go
// to settings" links (parser, storage, models): it talks to the UI
// store rather than navigating via the router, so the host editor
// modal stays mounted and can be returned to once the user closes the
// settings panel.
const goToVectorStoreSettings = () => {
uiStore.openSettings('vectorstore')
}
onMounted(async () => {
if (props.mode !== 'create') return
loading.value = true
try {
const resp = await listVectorStores()
if (resp.success) allStores.value = resp.data || []
} catch (e) {
// Graceful degradation: if vector-store listing fails the dropdown
// simply renders only the "System default" entry, which is exactly
// the legacy behavior. The KB editor remains usable.
console.warn('[KBVectorStoreSettings] failed to load vector stores', e)
} finally {
loading.value = false
}
})
</script>
<style scoped>
.kb-vector-store-settings {
display: flex;
flex-direction: column;
gap: 16px;
}
.section-header h2 {
font-size: 16px;
font-weight: 600;
margin: 0 0 4px;
}
.section-description {
color: var(--td-text-color-secondary, #4e5969);
font-size: 13px;
margin: 0;
}
.settings-group {
background: var(--td-bg-color-container, #fff);
border: 1px solid var(--td-component-stroke, #dcdcdc);
border-radius: 6px;
padding: 16px;
}
.setting-row {
display: flex;
gap: 24px;
align-items: flex-start;
}
.setting-info {
flex: 0 0 220px;
}
.setting-info label {
font-weight: 500;
display: block;
margin-bottom: 4px;
}
.setting-info .desc {
font-size: 12px;
color: var(--td-text-color-secondary, #4e5969);
margin: 0;
}
.setting-control {
flex: 1;
display: flex;
flex-direction: column;
gap: 8px;
}
.option-hint {
font-size: 12px;
color: var(--td-text-color-secondary, #4e5969);
margin: 0;
}
.change-warning {
color: var(--td-error-color, #d54941);
}
.go-settings {
font-size: 12px;
color: var(--td-brand-color, #0052d9);
text-decoration: none;
}
.go-settings:hover {
text-decoration: underline;
}
.select-option {
display: flex;
align-items: center;
gap: 8px;
}
.loading-inline {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: var(--td-text-color-secondary, #4e5969);
}
</style>