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
@@ -131,6 +131,33 @@ func ctxWithTenant(tenantID uint64) context.Context {
return context.WithValue(context.Background(), types.TenantIDContextKey, tenantID)
}
func ctxWithTenantStorage(tenantID uint64, defaultProvider string) context.Context {
ctx := ctxWithTenant(tenantID)
tenant := &types.Tenant{
ID: tenantID,
StorageEngineConfig: &types.StorageEngineConfig{
DefaultProvider: defaultProvider,
},
}
return context.WithValue(ctx, types.TenantInfoContextKey, tenant)
}
func TestCreateKnowledgeBase_DefaultStorageProviderFromTenant(t *testing.T) {
repo := newFakeKBRepo()
svc := newPR3KBService(repo, &fakeRegistry{registered: map[string]struct{}{}}, &fakeOwnership{})
kb, err := svc.CreateKnowledgeBase(ctxWithTenantStorage(1, "minio"), &types.KnowledgeBase{Name: "kb"})
require.NoError(t, err)
assert.Equal(t, "minio", kb.GetStorageProvider())
kbExplicit, err := svc.CreateKnowledgeBase(ctxWithTenantStorage(1, "minio"), &types.KnowledgeBase{
Name: "kb2",
StorageProviderConfig: &types.StorageProviderConfig{Provider: "cos"},
})
require.NoError(t, err)
assert.Equal(t, "cos", kbExplicit.GetStorageProvider())
}
// ---------------------------------------------------------------------------
// CreateKnowledgeBase — vector_store_id binding validation matrix
// ---------------------------------------------------------------------------