LightRAG/logs/2025-12-04-21-30-multi-tenant-implementation.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

3.2 KiB

Multi-Tenant Implementation and Testing Log

Date: 2025-12-04 Mode: beastmode

Summary

Successfully implemented and tested full multi-tenant support for LightRAG WebUI. Both multi-tenant and single-tenant modes are now fully functional.

Actions Performed

  1. Fixed Vite proxy configuration (lightrag_webui/vite.config.ts)

    • Changed from conditional import.meta.env (doesn't work in config) to proper loadEnv
    • Added comprehensive proxy rules for all API endpoints: /api/v1/, /api/, /documents/, /query/, /graph/, /retrieval/, /health/, /auth-status/, /docs, /redoc, /openapi.json
    • Used 127.0.0.1 instead of localhost to avoid IPv6 resolution issues
    • Removed circular dependency by inlining webuiPrefix constant
  2. Tested Multi-Tenant Mode

    • Verified /api/v1/tenants endpoint returns tenant list (acme-corp, techstart)
    • Verified /api/v1/knowledge-bases endpoint returns KBs per tenant
    • Login page shows tenant dropdown with all available tenants
    • Tenant selection loads associated knowledge bases
    • KB dropdown allows switching between KBs within tenant
    • Switch Tenant modal shows tenant cards with stats (KBs, Docs, GB)
    • Tenant switching properly resets context and loads new KBs
    • Document upload works with proper tenant/KB context
    • Query/Retrieval tab sends requests with tenant/KB headers
    • Knowledge Graph tab loads with graph controls
  3. Tested Single-Tenant Mode

    • Set LIGHTRAG_MULTI_TENANT=false in .env
    • WebUI auto-redirects to dashboard without tenant selection
    • Default tenant/KB ("default") used automatically
    • All tabs functional (Documents, Knowledge Graph, Retrieval, API)
    • No tenant selector shown in header

Key Decisions

  • Used 127.0.0.1 instead of localhost in Vite proxy to ensure consistent IPv4 connections
  • Inlined webuiPrefix constant in vite.config.ts to avoid circular import with path alias
  • Started Vite with node ./node_modules/vite/bin/vite.js < /dev/null & to prevent TTY suspension issues

Files Modified

  • lightrag_webui/vite.config.ts - Fixed proxy configuration and removed problematic import

Test Results

Test Status
Vite proxy for /api/v1/ routes Pass
Tenant list API Pass
Knowledge bases API Pass
Login page tenant dropdown Pass
Tenant selection and KB loading Pass
Tenant switching Pass
KB switching within tenant Pass
Document upload with tenant context Pass
Query/Retrieval with tenant context Pass
Knowledge Graph tab Pass
Single-tenant mode auto-redirect Pass
Single-tenant mode default KB Pass

Known Issues / Minor Items

  1. SwaggerUI static files not found at /static/swagger-ui/ - not critical, only affects /docs page
  2. Some "KB context required but missing" errors during tenant switching - timing issue, doesn't affect functionality

Next Steps

  • Consider adding loading spinner during tenant/KB switch to avoid timing issues
  • Add SwaggerUI static files to Vite proxy or configure fallback

Environment

  • Branch: premerge/integration-upstream
  • API Port: 9621
  • WebUI Port: 5173
  • PostgreSQL: 15432
  • Redis: 16379