From 9578b6073410437a0e62e3d54ba34faa1c053859 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:52:54 +0000 Subject: [PATCH] fix: add missing name() method to WatsonEmbeddingFunction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3597 - ChromaDB expects embedding functions to have a name() method for validation. Added static method that returns 'watson' following the same pattern as other embedding functions. - Added comprehensive tests to verify the fix - Ensures compatibility with ChromaDB validation requirements - No regressions in existing Watson embedding functionality Co-Authored-By: João --- .../providers/ibm/embedding_callable.py | 5 ++ .../embeddings/test_watson_embedding_name.py | 75 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/rag/embeddings/test_watson_embedding_name.py diff --git a/src/crewai/rag/embeddings/providers/ibm/embedding_callable.py b/src/crewai/rag/embeddings/providers/ibm/embedding_callable.py index 17181afdf..8a87c489e 100644 --- a/src/crewai/rag/embeddings/providers/ibm/embedding_callable.py +++ b/src/crewai/rag/embeddings/providers/ibm/embedding_callable.py @@ -152,3 +152,8 @@ class WatsonEmbeddingFunction(EmbeddingFunction[Documents]): except Exception as e: print(f"Error during Watson embedding: {e}") raise + + @staticmethod + def name() -> str: + """Return the name identifier for this embedding function.""" + return "watson" diff --git a/tests/rag/embeddings/test_watson_embedding_name.py b/tests/rag/embeddings/test_watson_embedding_name.py new file mode 100644 index 000000000..e0d38b347 --- /dev/null +++ b/tests/rag/embeddings/test_watson_embedding_name.py @@ -0,0 +1,75 @@ +"""Tests for Watson embedding function name method.""" + +import pytest +from unittest.mock import patch, MagicMock + +from crewai.rag.embeddings.providers.ibm.embedding_callable import WatsonEmbeddingFunction + + +class TestWatsonEmbeddingName: + """Test Watson embedding function name method.""" + + def test_watson_embedding_function_has_name_method(self): + """Test that WatsonEmbeddingFunction has a name method.""" + assert hasattr(WatsonEmbeddingFunction, 'name') + assert callable(getattr(WatsonEmbeddingFunction, 'name')) + + def test_watson_embedding_function_name_returns_watson(self): + """Test that the name method returns 'watson'.""" + assert WatsonEmbeddingFunction.name() == "watson" + + def test_watson_embedding_function_name_is_static(self): + """Test that the name method can be called without instantiation.""" + name = WatsonEmbeddingFunction.name() + assert name == "watson" + assert isinstance(name, str) + + def test_watson_embedding_function_name_with_chromadb_validation(self): + """Test that the name method works in ChromaDB validation scenario.""" + config = { + "model_id": "test-model", + "api_key": "test-key", + "url": "https://test.com" + } + + watson_func = WatsonEmbeddingFunction(**config) + + try: + name = watson_func.name() + assert name == "watson" + except AttributeError as e: + pytest.fail(f"ChromaDB validation failed with AttributeError: {e}") + + def test_watson_embedding_function_name_method_signature(self): + """Test that the name method has the correct signature.""" + import inspect + + name_method = getattr(WatsonEmbeddingFunction, 'name') + + assert isinstance(inspect.getattr_static(WatsonEmbeddingFunction, 'name'), staticmethod) + + sig = inspect.signature(name_method) + if sig.return_annotation != inspect.Signature.empty: + assert sig.return_annotation == str + + def test_watson_embedding_function_reproduces_original_issue(self): + """Test that reproduces the original issue scenario from #3597.""" + + + config = { + "model_id": "ibm/slate-125m-english-rtrvr", + "api_key": "test-key", + "url": "https://us-south.ml.cloud.ibm.com", + "project_id": "test-project" + } + + watson_func = WatsonEmbeddingFunction(**config) + + name = watson_func.name() + + assert name == "watson" + assert isinstance(name, str) + + class_name = WatsonEmbeddingFunction.name() + assert class_name == "watson" + assert class_name == name