LightRAG/logs/2025-01-06-09-30-beastmode-webui-single-multi-tenant.md
Raphaël MANSUY 730c406749 feat: Implement multi-tenant support across graph and query routes
- 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.
2025-12-05 00:04:29 +08:00

76 lines
3.3 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
1. **Added `LIGHTRAG_MULTI_TENANT` env var** to `lightrag/api/lightrag_server.py` to control multi-tenant mode
2. **Updated `/auth-status` and `/health` endpoints** to include `multi_tenant_enabled` flag
3. **Updated `LoginPage.tsx`** to auto-redirect in single-tenant mode (bypass tenant selection)
4. **Updated `App.tsx`** to set default tenant AND KB in single-tenant mode
5. **Updated `TenantSelector.tsx`** to skip API calls when `multiTenantEnabled=false`
6. **Updated `SiteHeader.tsx`** to conditionally hide tenant selector in single-tenant mode
7. **Updated `useTenantInitialization.ts`** hook to skip tenant API calls in single-tenant mode
8. **Updated `AuthStore`** in `stores/state.ts` with `multiTenantEnabled` state and `setMultiTenantEnabled` action
9. **Updated `lightrag.ts`** API types to include `multi_tenant_enabled` in `AuthStatusResponse`
10. **Rebuilt WebUI** multiple times during development
## Key Decisions
1. **Default mode is single-tenant** (`LIGHTRAG_MULTI_TENANT=false`) for backward compatibility
2. **Default tenant/KB IDs are "default"** to match API expectations
3. **Auto-set both tenant AND KB** in single-tenant mode to avoid "KB context required" errors
4. **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/tenants` endpoint
- Needs TenantService and tenant routes to be included in API server
## Files Modified
- `lightrag/api/lightrag_server.py`
- `lightrag_webui/src/App.tsx`
- `lightrag_webui/src/features/LoginPage.tsx`
- `lightrag_webui/src/features/SiteHeader.tsx`
- `lightrag_webui/src/components/TenantSelector.tsx`
- `lightrag_webui/src/hooks/useTenantInitialization.ts`
- `lightrag_webui/src/stores/state.ts`
- `lightrag_webui/src/api/lightrag.ts`
## Next Steps
1. 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
2. Consider adding:
- Tenant creation UI in WebUI
- KB creation UI in WebUI
- Tenant switching without page reload
## Lessons Learned
1. The env var name is `LIGHTRAG_MULTI_TENANT`, not `ENABLE_MULTI_TENANT` or `ENABLE_MULTI_TENANTS`
2. Both tenant AND KB context must be set for document/graph API calls to work
3. The WebUI uses localStorage to persist tenant/KB selection - must clear for fresh testing
4. React strict mode causes double initialization - need refs to prevent duplicate API calls