Skip to content

fix(knowledge): lazy-load heavy deps to fix pipeline test imports (#1514)#1929

Merged
mrveiss merged 2 commits intoDev_new_guifrom
fix/aioredis-test-stubs-1514
Mar 20, 2026
Merged

fix(knowledge): lazy-load heavy deps to fix pipeline test imports (#1514)#1929
mrveiss merged 2 commits intoDev_new_guifrom
fix/aioredis-test-stubs-1514

Conversation

@mrveiss
Copy link
Owner

@mrveiss mrveiss commented Mar 19, 2026

Summary

  • Pipeline tests (knowledge/pipeline/cognifiers/cognifiers_test.py) failed locally because knowledge/__init__.py eagerly imported all 14 mixins, pulling in redis, llama_index, and chromadb — unavailable in the dev Python 3.13 env
  • Moved the KnowledgeBase composed class and singleton factory to knowledge/_composed.py
  • knowledge/__init__.py now uses module-level __getattr__ to lazy-load on first access
  • from knowledge.pipeline.cognifiers.entity_extractor import EntityExtractor no longer triggers the heavy import chain

Changes

  • autobot-backend/knowledge/__init__.py: Replaced eager imports with __getattr__ lazy loading
  • autobot-backend/knowledge/_composed.py: New module containing KnowledgeBase class and factory functions

Test plan

  • from knowledge.pipeline.cognifiers.entity_extractor import EntityExtractor works without heavy deps
  • knowledge._composed NOT loaded until explicitly accessed
  • from knowledge import KnowledgeBase still works in production env (full deps available)
  • Existing knowledge base tests pass unchanged

Closes #1514

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.
@github-actions
Copy link

github-actions bot commented Mar 19, 2026

✅ 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.
@mrveiss mrveiss merged commit ecaa7d2 into Dev_new_gui Mar 20, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant