2.6 KiB
2.6 KiB
Task Log: Pipeline Screen Tenant Filtering Fix
Date: 2024-12-05 02:00 Mode: beastmode-chatmode Task: Fix pipeline screen not being filtered by tenant and KB
Summary
Implemented multi-tenant support for document routes to ensure the pipeline screen filters documents by the current tenant and knowledge base (KB) context.
Actions Performed
-
Updated
document_routes.py:- Added imports for
TenantRAGManager,TenantContext,get_tenant_context_optional - Modified
create_document_routes()signature to accept optionalrag_managerparameter - Created
get_tenant_ragdependency that returns tenant-specific RAG instance when context is available - Updated
/pipeline_statusendpoint to usetenant_ragdependency for workspace-isolated pipeline status - Updated
/paginatedendpoint to usetenant_ragdependency for tenant-filtered document listing - Updated
/status_countsendpoint to usetenant_ragdependency for tenant-filtered status counts
- Added imports for
-
Restructured
lightrag_server.py:- Moved multi-tenant component initialization (TenantRAGManager) before document routes registration
- Modified
create_document_routes()call to passrag_manager=rag_managerparameter - Separated tenant routes registration from multi-tenant initialization
Key Decisions
- Used FastAPI's Depends() injection to get tenant-specific RAG instance
- Pattern:
tenant_rag: LightRAG = Depends(get_tenant_rag)for tenant-aware endpoints - Fallback to global
ragwhen tenant context is not available (single-tenant mode compatibility) workspace = tenant_rag.workspacecontains the composite{tenant_id}:{kb_id}pattern for storage isolation
Files Modified
lightrag/api/routers/document_routes.pylightrag/api/lightrag_server.py
Next Steps
- Consider updating graph routes (
graph_routes.py) for tenant-aware graph operations - Consider updating query routes (
query_routes.py) for tenant-aware queries - Write/upload operations (upload, delete, etc.) may need similar tenant-aware treatment
Lessons/Insights
- The document routes were using the global
raginstance, which always used the default workspace - The fix pattern is: replace
rag.workspacewithtenant_rag.workspacewheretenant_ragcomes from the dependency - TenantRAGManager must be initialized before registering routes that depend on it
- The
get_tenant_ragdependency gracefully falls back to global RAG for backward compatibility
Testing
- Ran
ruff checkon modified files - all checks passed - No TypeScript/Python errors detected in modified files