From 8b7d00b2604fcb8c49c7e738cd27f1e23fd16437 Mon Sep 17 00:00:00 2001 From: "ochan.kwon" Date: Mon, 18 May 2026 23:50:09 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20expose=20KB=20=E2=86=94=20vector=20stor?= =?UTF-8?q?e=20binding=20in=20list,=20editor,=20and=20detail=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- frontend/src/api/knowledge-base/index.ts | 37 +++ frontend/src/components/VectorStoreBadge.vue | 114 ++++++++ frontend/src/i18n/locales/en-US.ts | 30 ++ frontend/src/i18n/locales/ko-KR.ts | 30 ++ frontend/src/i18n/locales/ru-RU.ts | 30 ++ frontend/src/i18n/locales/zh-CN.ts | 30 ++ .../src/views/knowledge/KnowledgeBase.vue | 14 + .../knowledge/KnowledgeBaseEditorModal.vue | 86 +++++- .../src/views/knowledge/KnowledgeBaseList.vue | 91 ++++++ .../settings/KBVectorStoreSettings.vue | 268 ++++++++++++++++++ internal/application/service/vectorstore.go | 25 +- internal/handler/knowledgebase.go | 133 ++++++++- .../handler/knowledgebase_pr5_list_test.go | 244 ++++++++++++++++ internal/handler/organization.go | 36 ++- internal/types/interfaces/vectorstore.go | 9 + 15 files changed, 1165 insertions(+), 12 deletions(-) create mode 100644 frontend/src/components/VectorStoreBadge.vue create mode 100644 frontend/src/views/knowledge/settings/KBVectorStoreSettings.vue create mode 100644 internal/handler/knowledgebase_pr5_list_test.go diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index dfed0590..b7709832 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -20,6 +20,38 @@ export function listKnowledgeBases(params?: { return get(qs ? `/api/v1/knowledge-bases?${qs}` : '/api/v1/knowledge-bases'); } +// Read-only vector-store binding metadata enriched onto every KB +// response (list, create, get, update, pin). Source carries where the +// binding points; status reports whether that target is currently +// reachable by the server. +// +// - source 'env' → KB uses the tenant's env-configured store +// (RETRIEVE_DRIVER). vector_store_id is null and +// vector_store_name is the localized "System +// default" label; vector_store_engine_type still +// reports the underlying engine (e.g. "postgres"). +// - source 'user' → KB is bound to a tenant-owned VectorStore. +// vector_store_id / name / engine_type are real. +// - source 'shared' → KB belongs to a different tenant and is +// readable via cross-organization sharing. The +// server strips vector_store_id and engine_type +// to avoid leaking the owner tenant's store +// inventory; only this source marker arrives. +// - status 'unavailable' → the binding cannot be reached right now +// (deleted row, registry miss, transient infra +// failure). Operators recover via the global +// Vector Stores settings page. +export type VectorStoreSource = 'env' | 'user' | 'shared' | 'unavailable'; +export type VectorStoreStatus = 'available' | 'unavailable'; + +export interface KnowledgeBaseStoreView { + vector_store_id?: string | null; + vector_store_name?: string; + vector_store_engine_type?: string; + vector_store_source?: VectorStoreSource; + vector_store_status?: VectorStoreStatus; +} + export function createKnowledgeBase(data: { name: string; description?: string; @@ -27,6 +59,11 @@ export function createKnowledgeBase(data: { chunking_config?: any; embedding_model_id?: string; summary_model_id?: string; + // Opt-in binding to a specific tenant-owned VectorStore. Omit (or + // send undefined / empty string) to fall back to the env-configured + // store. Immutable after creation — UpdateKnowledgeBase intentionally + // does not accept this field. + vector_store_id?: string; vlm_config?: { enabled: boolean; model_id?: string; diff --git a/frontend/src/components/VectorStoreBadge.vue b/frontend/src/components/VectorStoreBadge.vue new file mode 100644 index 00000000..94fca065 --- /dev/null +++ b/frontend/src/components/VectorStoreBadge.vue @@ -0,0 +1,114 @@ + + + + + diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index d0489357..120d78a6 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -1708,6 +1708,7 @@ export default { sidebar: { basic: 'Basic Information', models: 'Model Configuration', + vectorStore: 'Vector Store', chunking: 'Chunking Settings', storage: 'Storage Engine', advanced: 'Advanced Settings', @@ -1720,6 +1721,12 @@ export default { share: 'Sharing', indexing: 'Indexing Strategy', }, + errors: { + vectorStoreBindingInvalid: + 'The selected vector store cannot be used. Choose a different store or use the system default.', + vectorStoreUnavailable: + 'The selected vector store is currently unavailable. Check its connection configuration in Settings → Vector Stores.', + }, basic: { title: 'Basic Information', description: 'Configure the knowledge base name and description', @@ -3737,7 +3744,30 @@ export default { think: 'Deep Thinking', todoWrite: 'Make Plan', }, + vectorStoreBadge: { + systemDefault: 'System default', + sharedFromOrg: 'Shared from another organization', + unknownStore: 'Unknown store', + unavailable: 'Unavailable', + }, kbSettings: { + vectorStore: { + title: 'Vector Store', + description: + 'Choose which vector store this knowledge base writes to. The binding is permanent — to move an existing KB to a different store, create a new KB and re-index.', + loading: 'Loading vector stores...', + engineLabel: 'Vector store', + engineDesc: + 'Pick a store from the global Vector Stores configuration, or leave as System default to use the tenant-wide RETRIEVE_DRIVER engine.', + boundLabel: 'Bound vector store', + systemDefault: 'System default', + immutableHint: + 'Cannot be changed after creation. To migrate later, create a new KB bound to the desired store and re-index.', + immutableEdit: 'Vector store binding cannot be changed after creation.', + unavailableHint: + 'The bound vector store is currently unavailable; check its connection configuration in Settings → Vector Stores.', + goGlobalSettings: 'Go to Vector Store Settings', + }, storage: { title: 'Storage Engine', description: 'Select the file storage engine. This affects how uploaded documents and images within documents are stored. Parameters are configured in global settings.', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 68b2819b..da202eb4 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -2375,6 +2375,7 @@ export default { sidebar: { basic: "기본 정보", models: "모델 설정", + vectorStore: "벡터 스토어", chunking: "청크 설정", advanced: "고급 설정", faq: "FAQ 설정", @@ -2387,6 +2388,12 @@ export default { datasource: "데이터 소스", indexing: "인덱싱 전략", }, + errors: { + vectorStoreBindingInvalid: + "선택한 벡터 스토어를 사용할 수 없습니다. 다른 스토어를 선택하거나 시스템 기본값을 사용하세요.", + vectorStoreUnavailable: + "선택한 벡터 스토어가 현재 사용할 수 없는 상태입니다. 설정 → 벡터 스토어에서 연결 상태를 확인하세요.", + }, basic: { title: "기본 정보", description: "지식베이스의 이름과 설명 정보 설정", @@ -3800,7 +3807,30 @@ export default { think: '깊이 생각하기', todoWrite: '계획 수립', }, + vectorStoreBadge: { + systemDefault: "시스템 기본값", + sharedFromOrg: "다른 조직에서 공유됨", + unknownStore: "알 수 없는 스토어", + unavailable: "사용 불가", + }, kbSettings: { + vectorStore: { + title: "벡터 스토어", + description: + "이 지식베이스가 사용할 벡터 스토어를 선택합니다. 생성 후에는 변경할 수 없습니다. 다른 스토어로 옮기려면 새 KB를 만들고 다시 인덱싱하세요.", + loading: "벡터 스토어 목록을 불러오는 중...", + engineLabel: "벡터 스토어", + engineDesc: + "전역 벡터 스토어 설정에서 등록한 스토어를 선택하거나, '시스템 기본값'을 유지하면 테넌트의 RETRIEVE_DRIVER 엔진을 사용합니다.", + boundLabel: "바인딩된 벡터 스토어", + systemDefault: "시스템 기본값", + immutableHint: + "생성 후 변경할 수 없습니다. 다른 스토어로 옮기려면 원하는 스토어에 바인딩된 새 KB를 만들고 다시 인덱싱하세요.", + immutableEdit: "벡터 스토어 바인딩은 생성 후 변경할 수 없습니다.", + unavailableHint: + "바인딩된 벡터 스토어가 현재 사용할 수 없는 상태입니다. 설정 → 벡터 스토어에서 연결 상태를 확인하세요.", + goGlobalSettings: "벡터 스토어 설정으로 이동", + }, storage: { title: '스토리지 엔진', description: '파일 스토리지 엔진을 선택합니다. 문서 업로드 및 문서 내 이미지 저장 방식에 영향을 미칩니다. 파라미터는 전역 설정에서 구성합니다.', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 12669654..33c68898 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -1963,6 +1963,7 @@ export default { sidebar: { basic: 'Основная информация', models: 'Конфигурация моделей', + vectorStore: 'Vector Store', chunking: 'Настройки разбиения', advanced: 'Дополнительные настройки', faq: 'FAQ настройки', @@ -1975,6 +1976,12 @@ export default { share: 'Sharing', indexing: 'Стратегия индексации', }, + errors: { + vectorStoreBindingInvalid: + 'The selected vector store cannot be used. Choose a different store or use the system default.', + vectorStoreUnavailable: + 'The selected vector store is currently unavailable. Check its connection configuration in Settings → Vector Stores.', + }, basic: { title: 'Основная информация', description: 'Укажите название и описание базы знаний', @@ -3375,7 +3382,30 @@ export default { think: 'Глубокое размышление', todoWrite: 'Составить план' }, + vectorStoreBadge: { + systemDefault: 'System default', + sharedFromOrg: 'Shared from another organization', + unknownStore: 'Unknown store', + unavailable: 'Unavailable', + }, kbSettings: { + vectorStore: { + title: 'Vector Store', + description: + 'Choose which vector store this knowledge base writes to. The binding is permanent — to move an existing KB to a different store, create a new KB and re-index.', + loading: 'Loading vector stores...', + engineLabel: 'Vector store', + engineDesc: + 'Pick a store from the global Vector Stores configuration, or leave as System default to use the tenant-wide RETRIEVE_DRIVER engine.', + boundLabel: 'Bound vector store', + systemDefault: 'System default', + immutableHint: + 'Cannot be changed after creation. To migrate later, create a new KB bound to the desired store and re-index.', + immutableEdit: 'Vector store binding cannot be changed after creation.', + unavailableHint: + 'The bound vector store is currently unavailable; check its connection configuration in Settings → Vector Stores.', + goGlobalSettings: 'Go to Vector Store Settings', + }, storage: { title: 'Хранилище', description: 'Выберите хранилище файлов. Это влияет на способ хранения загруженных документов и изображений в документах. Параметры настраиваются в глобальных настройках.', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index fb847704..0359cb4d 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -2350,6 +2350,7 @@ export default { sidebar: { basic: "基本信息", models: "模型配置", + vectorStore: "向量存储", chunking: "分块设置", storage: "存储引擎", advanced: "高级设置", @@ -2362,6 +2363,12 @@ export default { share: "共享管理", indexing: "索引策略", }, + errors: { + vectorStoreBindingInvalid: + "无法使用所选向量存储。请选择其他存储或使用系统默认值。", + vectorStoreUnavailable: + "所选向量存储当前不可用。请在设置 → 向量存储中检查其连接配置。", + }, basic: { title: "基本信息", description: "设置知识库的名称和描述信息", @@ -3732,7 +3739,30 @@ export default { think: "深度思考", todoWrite: "制定计划", }, + vectorStoreBadge: { + systemDefault: "系统默认", + sharedFromOrg: "来自其他组织的共享", + unknownStore: "未知存储", + unavailable: "不可用", + }, kbSettings: { + vectorStore: { + title: "向量存储", + description: + "选择此知识库要写入的向量存储。绑定不可更改 — 如需将现有 KB 迁移到其他存储,请创建新 KB 并重新索引。", + loading: "正在加载向量存储列表...", + engineLabel: "向量存储", + engineDesc: + "从全局向量存储配置中选择,或保持系统默认以使用租户的 RETRIEVE_DRIVER 引擎。", + boundLabel: "已绑定的向量存储", + systemDefault: "系统默认", + immutableHint: + "创建后不可更改。如需迁移,请创建一个绑定到目标存储的新 KB 并重新索引。", + immutableEdit: "向量存储绑定在创建后无法更改。", + unavailableHint: + "绑定的向量存储当前不可用,请在设置 → 向量存储中检查其连接配置。", + goGlobalSettings: "前往向量存储设置", + }, storage: { title: "存储引擎", description: "选择文件存储引擎,影响文档上传存储和文档中图片的存储方式。参数在全局设置中配置。", diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index d7dce069..250c7b14 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -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 { + +