fix: lazy-import document_search in evaluate pipelines to avoid breaking CLI#947
fix: lazy-import document_search in evaluate pipelines to avoid breaking CLI#947MichaelMcCulloch-deepsense-ai wants to merge 2 commits intodevelopfrom
Conversation
…ing CLI The top-level import of ragbits.document_search in the evaluate pipelines __init__.py caused a ModuleNotFoundError when ragbits-document-search was not installed, breaking all ragbits CLI commands due to eager autoregister. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Coverage SummaryDetailsDiff against mainResults for commit: 9b63733 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
There was a problem hiding this comment.
Wouldn't it be better to just add ragbits-document-search as a dependency of ragbits-evaluate? It's imported unconditionally at the module level, so without it the package is effectively broken anyway.
If the intent is for these to be truly optional (i.e., you can use ragbits-evaluate without document search), then the try/except approach is fine but in that case they should be declared as optional dependencies (extras), e.g. pip install ragbits-evaluate[document-search], so the installation path is clear to users.
Also worth noting that ragbits-agents has the same problem. It's not listed as a dependency either, but modules like question_answer.py and the agent_simulation subpackage import from it unconditionally, so the same ModuleNotFoundError will happen there too.
Longer term, if we expect more pipeline types to be added by different packages, it might be worth considering Python's entry points mechanism instead of try/except blocks. Each package would self-register its pipeline in its own pyproject.toml:
# in ragbits-document-search/pyproject.toml
[project.entry-points."ragbits.evaluate.pipelines"]
document_search = "ragbits.evaluate.pipelines.document_search:DocumentSearchPipeline"And ragbits-evaluate would discover them at runtime via importlib.metadata.entry_points() so no hard imports, no try/except, and zero changes needed in ragbits-evaluate when a new pipeline type is added. But that's a bigger refactor and probably out of scope for this PR.
…f ragbits-evaluate Both packages are imported unconditionally throughout ragbits-evaluate (pipelines, metrics, dataloaders, agent_simulation) but were not declared as dependencies. This caused ModuleNotFoundError that broke all CLI commands because autoregister() eagerly imports every ragbits.*.cli module. Rather than guarding every import with try/except, declare them as proper dependencies since ragbits-evaluate cannot function without them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The issue is that |
@sleter Makes sense, keeping it lightweight is a good call. The |
It sounds like what I need to do is reintroduce the try/except blocks, and make the dependency optional, and for Is that right? |
ragbits.document_searchimports inragbits/evaluate/pipelines/__init__.pywith atry/except ImportErrorguardragbits-document-searchis not a dependency ofragbits-evaluate, but a hard top-level import causedModuleNotFoundErrorwhen it wasn't installedautoregister()eagerly imports everyragbits.*.climodule on startup, this broke all CLI commands — not justragbits evaluate