feat: implement tenant default storage provider handling in Knowledge Base creation

This commit introduces functionality to utilize the tenant's default storage provider when creating a Knowledge Base. It includes updates to the frontend to load the default provider from settings and apply it during Knowledge Base initialization. Additionally, the backend has been enhanced to ensure that the storage provider is set correctly based on tenant configuration, improving consistency across the application. Tests have been added to verify the correct application of the default storage provider in various scenarios.
This commit is contained in:
wizardchen
2026-05-29 13:36:06 +08:00
committed by lyingbug
parent e0823eff31
commit 48381fbaf5
4 changed files with 86 additions and 10 deletions
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"sort"
"strings"
"time"
"github.com/Tencent/WeKnora/internal/application/service/retriever"
@@ -105,6 +106,7 @@ func (s *knowledgeBaseService) CreateKnowledgeBase(ctx context.Context,
kb.CreatorID = uid
}
kb.EnsureDefaults()
applyTenantDefaultStorageProvider(ctx, kb)
// Fold empty-string vector_store_id into nil so this path and the
// retrieve-engine factory's pre-condition share a single representation.
@@ -136,6 +138,23 @@ func (s *knowledgeBaseService) CreateKnowledgeBase(ctx context.Context,
return kb, nil
}
// applyTenantDefaultStorageProvider fills an empty KB storage provider from the
// tenant's global default (Settings → Storage engine). Frontend should send the
// same value; this keeps API clients and legacy UIs consistent.
func applyTenantDefaultStorageProvider(ctx context.Context, kb *types.KnowledgeBase) {
if kb == nil || strings.TrimSpace(kb.GetStorageProvider()) != "" {
return
}
tenant, _ := ctx.Value(types.TenantInfoContextKey).(*types.Tenant)
provider := "local"
if tenant != nil && tenant.StorageEngineConfig != nil {
if p := strings.ToLower(strings.TrimSpace(tenant.StorageEngineConfig.DefaultProvider)); p != "" {
provider = p
}
}
kb.SetStorageProvider(provider)
}
// validateVectorStoreBinding routes through retriever.VerifyBinding so the
// ownership + registry sentinel hierarchy stays the single source of truth.
// The service layer's responsibility is to: