[LEADS-356] Bug fix: Allow the use of local Huggingface embedding models#239
Conversation
📝 WalkthroughWalkthroughRagasEmbeddingManager provider routing is refactored to map cloud providers through litellm while preserving native huggingface routing with a use_api=False default. Unit tests verify provider-specific behavior for both cloud and local embedding providers. ChangesRagasEmbeddingManager Provider Routing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/core/embedding/test_ragas.py (1)
11-67: ⚡ Quick winConsider adding test coverage for unknown provider error.
The current tests validate the happy paths for supported providers (HuggingFace, OpenAI, Gemini). Adding a test case for an unknown provider would validate the error handling logic at lines 50-53 in
ragas.py.📝 Optional test case for unknown provider
def test_unknown_provider_raises_configuration_error( self, mocker: MockerFixture, mock_embedding_factory: MockType ) -> None: """Verify unknown providers raise ConfigurationError.""" from lightspeed_evaluation.core.system.exceptions import ConfigurationError mocker.patch( "lightspeed_evaluation.core.embedding.manager.validate_provider_env" ) config = EmbeddingConfig(provider="unknown_provider", model="some-model") embedding_manager = EmbeddingManager(config) with pytest.raises(ConfigurationError, match="Unknown embedding provider"): RagasEmbeddingManager(embedding_manager) mock_embedding_factory.assert_not_called()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/core/embedding/test_ragas.py` around lines 11 - 67, Add a unit test to cover the unknown provider error path: create an EmbeddingConfig(provider="unknown_provider", model="some-model"), build EmbeddingManager(config), patch validate_provider_env like the other tests, then assert that constructing RagasEmbeddingManager(embedding_manager) raises the ConfigurationError from lightspeed_evaluation.core.system.exceptions with a message matching "Unknown embedding provider" (or the actual message used in ragas.py) and verify mock_embedding_factory.assert_not_called(); this ensures RagasEmbeddingManager, EmbeddingConfig, and EmbeddingManager handling for unknown providers is tested.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/unit/core/embedding/test_ragas.py`:
- Around line 11-67: Add a unit test to cover the unknown provider error path:
create an EmbeddingConfig(provider="unknown_provider", model="some-model"),
build EmbeddingManager(config), patch validate_provider_env like the other
tests, then assert that constructing RagasEmbeddingManager(embedding_manager)
raises the ConfigurationError from lightspeed_evaluation.core.system.exceptions
with a message matching "Unknown embedding provider" (or the actual message used
in ragas.py) and verify mock_embedding_factory.assert_not_called(); this ensures
RagasEmbeddingManager, EmbeddingConfig, and EmbeddingManager handling for
unknown providers is tested.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9a1a8bc4-9118-43d8-b4f6-89705b667f5c
📒 Files selected for processing (4)
src/lightspeed_evaluation/core/embedding/ragas.pytests/unit/core/embedding/__init__.pytests/unit/core/embedding/conftest.pytests/unit/core/embedding/test_ragas.py
411e6ce to
7c24841
Compare
Description
huggingfacethe provider is set tohuggingfaceso litellm uses the local Huggingface models, instead of models in the cloudopenai,geminiandhuggingfaceType of change
Tools used to create PR
Identify any AI code assistants used in this PR (for transparency and review context)
Related Tickets & Documents
Checklist before requesting a review
Testing
Summary by CodeRabbit
Refactor
Tests