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:
@@ -261,11 +261,19 @@ func (s *vectorStoreService) SaveDetectedVersion(ctx context.Context, store *typ
|
||||
// transient infrastructure failures can be classified, but the returned
|
||||
// StoreDisplay is still UnavailableStoreDisplay so a handler that ignores
|
||||
// the error degrades gracefully rather than panicking on a zero value.
|
||||
// EnvDefaultStoreView is the env-fallback display, enriched with the
|
||||
// active env store's engine type when one is configured. Exposed
|
||||
// separately from ResolveStoreView so list paths can fill the
|
||||
// env-bound entries without invoking the single-KB resolver.
|
||||
func (s *vectorStoreService) EnvDefaultStoreView(_ context.Context) types.StoreDisplay {
|
||||
return s.defaultStoreDisplay()
|
||||
}
|
||||
|
||||
func (s *vectorStoreService) ResolveStoreView(
|
||||
ctx context.Context, tenantID uint64, storeID string,
|
||||
) (types.StoreDisplay, error) {
|
||||
if storeID == "" {
|
||||
return types.DefaultStoreDisplay(), nil
|
||||
return s.defaultStoreDisplay(), nil
|
||||
}
|
||||
store, err := s.repo.GetByID(ctx, tenantID, storeID)
|
||||
if err != nil {
|
||||
@@ -359,7 +367,7 @@ func (s *vectorStoreService) BatchResolveStoreView(
|
||||
// sentinel so callers can rely on a key for every requested ID.
|
||||
for _, id := range storeIDs {
|
||||
if id == "" {
|
||||
out[id] = types.DefaultStoreDisplay()
|
||||
out[id] = s.defaultStoreDisplay()
|
||||
continue
|
||||
}
|
||||
if _, ok := out[id]; !ok {
|
||||
@@ -369,6 +377,19 @@ func (s *vectorStoreService) BatchResolveStoreView(
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// defaultStoreDisplay returns the env-fallback display, enriched with the
|
||||
// active env store's engine type when one is configured. Callers receive a
|
||||
// fully populated StoreDisplay so UIs can render the same badge shape for
|
||||
// env-bound and user-bound KBs (e.g. "postgres" vs "qdrant") without
|
||||
// branching on Source.
|
||||
func (s *vectorStoreService) defaultStoreDisplay() types.StoreDisplay {
|
||||
d := types.DefaultStoreDisplay()
|
||||
if len(s.envStores) > 0 {
|
||||
d.EngineType = string(s.envStores[0].EngineType)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// registerInRegistry creates an engine service and registers it in the registry.
|
||||
// Logs and skips on failure — the store is already persisted in DB,
|
||||
// and will be loaded on next app restart (self-healing).
|
||||
|
||||
Reference in New Issue
Block a user