fix: resolve vertexai import error in langchain-community
Issue Link / Problem Description
- Description: Newer versions of
langchain-communityhave sunset and removed the legacy Google Vertex AI modules. Because Ragas attempts a top-level import of these modules insrc/ragas/llms/base.py, it causes a hard crash (ModuleNotFoundError) for anyone installing Ragas alongside a modern LangChain setup.
Traceback
>>> import ragas
Traceback (most recent call last):
File "G:\test\ragas\src\ragas\llms\base.py", line 12, in <module>
from langchain_community.chat_models.vertexai import ChatVertexAI
ModuleNotFoundError: No module named 'langchain_community.chat_models.vertexai'
Changes Made
Wrapped the ChatVertexAI and VertexAI imports inside src/ragas/llms/base.py in a try-except ImportError block.
Made the addition of these classes to the MULTIPLE_COMPLETION_SUPPORTED list conditional on VERTEXAI_AVAILABLE.
This maintains backward compatibility for legacy langchain-community users while preventing the crash on import for modern setups.
Code Review Checklist
[x] All tests pass (make test / uv run pytest)
[x] Code is formatted (make format / uv run ruff)
[x] Type checking passes (make type)
[ ] Documentation is updated (N/A)
[ ] Appropriate tests are included (N/A - proactive fix)
Screenshots/Examples (if applicable)
Verified that running import ragas in the interactive interpreter now succeeds cleanly without throwing an unhandled ModuleNotFoundError.
✅ No documentation update needed — Internal bug fix that makes vertexai imports optional to handle ImportError. No user-facing API changes, no new features, and no changes to usage patterns that would require documentation updates.
Tested this branch against my RAG evaluation pipeline.
Environment: ragas 0.1.dev1148+g18b47dc0d, Python 3.x, Windows
Before this fix, import ragas crashed with the same ModuleNotFoundError
on langchain_community.chat_models.vertexai. After installing from this
branch, import succeeds cleanly with no workaround needed.
Also ran a full evaluation to confirm nothing else broke:
- bypass_n=True on LangchainLLMWrapper: works
- LangchainEmbeddingsWrapper / embed_query for answer_relevancy: works
- evaluate() with faithfulness + answer_relevancy completed successfully
Note: both LangchainLLMWrapper and LangchainEmbeddingsWrapper print deprecation warnings pointing to llm_factory/embedding_factory and ragas.metrics.collections — not a blocker, just flagging in case it's relevant to this PR's scope.
Thanks for the fix — this resolves the crash for me.
Thank you @Meenatchisundari for testing!
Super happy the fix resolves the import crash for you too.