fix(knowledge): lazy-load heavy deps to fix pipeline test imports (#1514)#1929
Merged
mrveiss merged 2 commits intoDev_new_guifrom Mar 20, 2026
Merged
fix(knowledge): lazy-load heavy deps to fix pipeline test imports (#1514)#1929mrveiss merged 2 commits intoDev_new_guifrom
mrveiss merged 2 commits intoDev_new_guifrom
Conversation
Importing knowledge.pipeline.* no longer triggers the full dependency chain (redis, llama_index, chromadb). The KnowledgeBase class and factory functions are moved to knowledge/_composed.py and loaded on first access via module-level __getattr__. This allows pipeline unit tests to run in dev envs without the full runtime dependency stack.
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
Address code review: eliminate triple redundancy of export names. __all__ is now the sole source of truth. Each name is resolved via getattr(_composed, name) and cached in module globals. Also clarified the docstring about what is being deferred.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
knowledge/pipeline/cognifiers/cognifiers_test.py) failed locally becauseknowledge/__init__.pyeagerly imported all 14 mixins, pulling inredis,llama_index, andchromadb— unavailable in the dev Python 3.13 envKnowledgeBasecomposed class and singleton factory toknowledge/_composed.pyknowledge/__init__.pynow uses module-level__getattr__to lazy-load on first accessfrom knowledge.pipeline.cognifiers.entity_extractor import EntityExtractorno longer triggers the heavy import chainChanges
autobot-backend/knowledge/__init__.py: Replaced eager imports with__getattr__lazy loadingautobot-backend/knowledge/_composed.py: New module containingKnowledgeBaseclass and factory functionsTest plan
from knowledge.pipeline.cognifiers.entity_extractor import EntityExtractorworks without heavy depsknowledge._composedNOT loaded until explicitly accessedfrom knowledge import KnowledgeBasestill works in production env (full deps available)Closes #1514