Skip to content

Commit 9578b60

Browse files
devin-ai-integration[bot]João
andcommitted
fix: add missing name() method to WatsonEmbeddingFunction
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 <joao@crewai.com>
1 parent b5b10a8 commit 9578b60

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/crewai/rag/embeddings/providers/ibm/embedding_callable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,8 @@ def __call__(self, input: Documents) -> Embeddings:
152152
except Exception as e:
153153
print(f"Error during Watson embedding: {e}")
154154
raise
155+
156+
@staticmethod
157+
def name() -> str:
158+
"""Return the name identifier for this embedding function."""
159+
return "watson"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Tests for Watson embedding function name method."""
2+
3+
import pytest
4+
from unittest.mock import patch, MagicMock
5+
6+
from crewai.rag.embeddings.providers.ibm.embedding_callable import WatsonEmbeddingFunction
7+
8+
9+
class TestWatsonEmbeddingName:
10+
"""Test Watson embedding function name method."""
11+
12+
def test_watson_embedding_function_has_name_method(self):
13+
"""Test that WatsonEmbeddingFunction has a name method."""
14+
assert hasattr(WatsonEmbeddingFunction, 'name')
15+
assert callable(getattr(WatsonEmbeddingFunction, 'name'))
16+
17+
def test_watson_embedding_function_name_returns_watson(self):
18+
"""Test that the name method returns 'watson'."""
19+
assert WatsonEmbeddingFunction.name() == "watson"
20+
21+
def test_watson_embedding_function_name_is_static(self):
22+
"""Test that the name method can be called without instantiation."""
23+
name = WatsonEmbeddingFunction.name()
24+
assert name == "watson"
25+
assert isinstance(name, str)
26+
27+
def test_watson_embedding_function_name_with_chromadb_validation(self):
28+
"""Test that the name method works in ChromaDB validation scenario."""
29+
config = {
30+
"model_id": "test-model",
31+
"api_key": "test-key",
32+
"url": "https://test.com"
33+
}
34+
35+
watson_func = WatsonEmbeddingFunction(**config)
36+
37+
try:
38+
name = watson_func.name()
39+
assert name == "watson"
40+
except AttributeError as e:
41+
pytest.fail(f"ChromaDB validation failed with AttributeError: {e}")
42+
43+
def test_watson_embedding_function_name_method_signature(self):
44+
"""Test that the name method has the correct signature."""
45+
import inspect
46+
47+
name_method = getattr(WatsonEmbeddingFunction, 'name')
48+
49+
assert isinstance(inspect.getattr_static(WatsonEmbeddingFunction, 'name'), staticmethod)
50+
51+
sig = inspect.signature(name_method)
52+
if sig.return_annotation != inspect.Signature.empty:
53+
assert sig.return_annotation == str
54+
55+
def test_watson_embedding_function_reproduces_original_issue(self):
56+
"""Test that reproduces the original issue scenario from #3597."""
57+
58+
59+
config = {
60+
"model_id": "ibm/slate-125m-english-rtrvr",
61+
"api_key": "test-key",
62+
"url": "https://us-south.ml.cloud.ibm.com",
63+
"project_id": "test-project"
64+
}
65+
66+
watson_func = WatsonEmbeddingFunction(**config)
67+
68+
name = watson_func.name()
69+
70+
assert name == "watson"
71+
assert isinstance(name, str)
72+
73+
class_name = WatsonEmbeddingFunction.name()
74+
assert class_name == "watson"
75+
assert class_name == name

0 commit comments

Comments
 (0)