- Enhanced graph_routes.py and query_routes.py to support multi-tenant architecture by introducing tenant-specific RAG instances. - Updated create_graph_routes and create_query_routes functions to accept rag_manager for tenant management. - Added get_tenant_rag dependency to all relevant endpoints to ensure tenant context is utilized for operations. - Modified Vite configuration to include comprehensive API proxy rules for seamless interaction with backend services. - Implemented cascade delete functionality in tenant_service.py for tenant and knowledge base deletions. - Added detailed logging and error handling for tenant operations. - Created audit logs documenting the multi-tenant implementation process and decisions made.
3.3 KiB
3.3 KiB
Task Log: WebUI Single-Tenant/Multi-Tenant Mode Support
Date: 2025-01-06 09:30 Mode: Beastmode
Summary
Implemented single-tenant and multi-tenant mode support for the LightRAG WebUI to ensure it works correctly in both configurations.
Actions Performed
- Added
LIGHTRAG_MULTI_TENANTenv var tolightrag/api/lightrag_server.pyto control multi-tenant mode - Updated
/auth-statusand/healthendpoints to includemulti_tenant_enabledflag - Updated
LoginPage.tsxto auto-redirect in single-tenant mode (bypass tenant selection) - Updated
App.tsxto set default tenant AND KB in single-tenant mode - Updated
TenantSelector.tsxto skip API calls whenmultiTenantEnabled=false - Updated
SiteHeader.tsxto conditionally hide tenant selector in single-tenant mode - Updated
useTenantInitialization.tshook to skip tenant API calls in single-tenant mode - Updated
AuthStoreinstores/state.tswithmultiTenantEnabledstate andsetMultiTenantEnabledaction - Updated
lightrag.tsAPI types to includemulti_tenant_enabledinAuthStatusResponse - Rebuilt WebUI multiple times during development
Key Decisions
- Default mode is single-tenant (
LIGHTRAG_MULTI_TENANT=false) for backward compatibility - Default tenant/KB IDs are "default" to match API expectations
- Auto-set both tenant AND KB in single-tenant mode to avoid "KB context required" errors
- Multi-tenant mode requires separate tenant API routes to be configured (not fully implemented in current codebase)
Test Results
Single-Tenant Mode (Default)
- ✅ WebUI loads without errors
- ✅ Auto-login with free login mode
- ✅ Documents tab works (shows empty state)
- ✅ Knowledge Graph tab works (shows empty graph)
- ✅ Retrieval tab works with query parameters
- ✅ API tab loads Swagger UI (404 for docs endpoints expected)
- ✅ No tenant selection UI shown
- ✅ No 404 errors for tenant/KB API calls
Multi-Tenant Mode
- ⚠️ Requires tenant API routes to be configured
- ⚠️ Shows 404 errors for
/api/v1/tenantsendpoint - ℹ️ Needs TenantService and tenant routes to be included in API server
Files Modified
lightrag/api/lightrag_server.pylightrag_webui/src/App.tsxlightrag_webui/src/features/LoginPage.tsxlightrag_webui/src/features/SiteHeader.tsxlightrag_webui/src/components/TenantSelector.tsxlightrag_webui/src/hooks/useTenantInitialization.tslightrag_webui/src/stores/state.tslightrag_webui/src/api/lightrag.ts
Next Steps
-
To enable full multi-tenant support:
- Include tenant routes in API server when
LIGHTRAG_MULTI_TENANT=true - Set up tenant/KB tables in PostgreSQL
- Create default tenant and KB during initialization
- Test tenant CRUD operations
- Include tenant routes in API server when
-
Consider adding:
- Tenant creation UI in WebUI
- KB creation UI in WebUI
- Tenant switching without page reload
Lessons Learned
- The env var name is
LIGHTRAG_MULTI_TENANT, notENABLE_MULTI_TENANTorENABLE_MULTI_TENANTS - Both tenant AND KB context must be set for document/graph API calls to work
- The WebUI uses localStorage to persist tenant/KB selection - must clear for fresh testing
- React strict mode causes double initialization - need refs to prevent duplicate API calls