Skip to content

Commit 12fa7e2

Browse files
fix: rename watson to watsonx embedding provider and prefix env vars
- prefix provider env vars with embeddings_ - rename watson → watsonx in providers - add deprecation warning and alias for legacy 'watson' key (to be removed in v1.0.0)
1 parent 091d126 commit 12fa7e2

File tree

7 files changed

+112
-66
lines changed

7 files changed

+112
-66
lines changed

src/crewai/rag/embeddings/factory.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
from __future__ import annotations
44

5+
import warnings
56
from typing import TYPE_CHECKING, TypeVar, overload
67

8+
from typing_extensions import deprecated
9+
710
from crewai.rag.core.base_embeddings_callable import EmbeddingFunction
811
from crewai.rag.core.base_embeddings_provider import BaseEmbeddingsProvider
912
from crewai.utilities.import_utils import import_and_validate_definition
@@ -59,9 +62,12 @@
5962
HuggingFaceProviderSpec,
6063
)
6164
from crewai.rag.embeddings.providers.ibm.embedding_callable import (
62-
WatsonEmbeddingFunction,
65+
WatsonXEmbeddingFunction,
66+
)
67+
from crewai.rag.embeddings.providers.ibm.types import (
68+
WatsonProviderSpec,
69+
WatsonXProviderSpec,
6370
)
64-
from crewai.rag.embeddings.providers.ibm.types import WatsonProviderSpec
6571
from crewai.rag.embeddings.providers.instructor.types import InstructorProviderSpec
6672
from crewai.rag.embeddings.providers.jina.types import JinaProviderSpec
6773
from crewai.rag.embeddings.providers.microsoft.types import AzureProviderSpec
@@ -100,7 +106,8 @@
100106
"sentence-transformer": "crewai.rag.embeddings.providers.sentence_transformer.sentence_transformer_provider.SentenceTransformerProvider",
101107
"text2vec": "crewai.rag.embeddings.providers.text2vec.text2vec_provider.Text2VecProvider",
102108
"voyageai": "crewai.rag.embeddings.providers.voyageai.voyageai_provider.VoyageAIProvider",
103-
"watson": "crewai.rag.embeddings.providers.ibm.watson.WatsonProvider",
109+
"watson": "crewai.rag.embeddings.providers.ibm.watsonx.WatsonXProvider", # Deprecated alias
110+
"watsonx": "crewai.rag.embeddings.providers.ibm.watsonx.WatsonXProvider",
104111
}
105112

106113

@@ -169,7 +176,14 @@ def build_embedder_from_dict(
169176

170177

171178
@overload
172-
def build_embedder_from_dict(spec: WatsonProviderSpec) -> WatsonEmbeddingFunction: ...
179+
def build_embedder_from_dict(spec: WatsonXProviderSpec) -> WatsonXEmbeddingFunction: ...
180+
181+
182+
@overload
183+
@deprecated(
184+
'The "WatsonProviderSpec" provider spec is deprecated and will be removed in v1.0.0. Use "WatsonXProviderSpec" instead.'
185+
)
186+
def build_embedder_from_dict(spec: WatsonProviderSpec) -> WatsonXEmbeddingFunction: ...
173187

174188

175189
@overload
@@ -233,6 +247,14 @@ def build_embedder_from_dict(spec):
233247
if not provider_name:
234248
raise ValueError("Missing 'provider' key in specification")
235249

250+
if provider_name == "watson":
251+
warnings.warn(
252+
'The "watson" provider key is deprecated and will be removed in v1.0.0. '
253+
'Use "watsonx" instead.',
254+
DeprecationWarning,
255+
stacklevel=2,
256+
)
257+
236258
if provider_name not in PROVIDER_PATHS:
237259
raise ValueError(
238260
f"Unknown provider: {provider_name}. Available providers: {list(PROVIDER_PATHS.keys())}"
@@ -300,7 +322,14 @@ def build_embedder(spec: VoyageAIProviderSpec) -> VoyageAIEmbeddingFunction: ...
300322

301323

302324
@overload
303-
def build_embedder(spec: WatsonProviderSpec) -> WatsonEmbeddingFunction: ...
325+
def build_embedder(spec: WatsonXProviderSpec) -> WatsonXEmbeddingFunction: ...
326+
327+
328+
@overload
329+
@deprecated(
330+
'The "WatsonProviderSpec" provider spec is deprecated and will be removed in v1.0.0. Use "WatsonXProviderSpec" instead.'
331+
)
332+
def build_embedder(spec: WatsonProviderSpec) -> WatsonXEmbeddingFunction: ...
304333

305334

306335
@overload
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"""IBM embedding providers."""
22

33
from crewai.rag.embeddings.providers.ibm.types import (
4-
WatsonProviderConfig,
54
WatsonProviderSpec,
5+
WatsonXProviderConfig,
6+
WatsonXProviderSpec,
67
)
7-
from crewai.rag.embeddings.providers.ibm.watson import (
8-
WatsonProvider,
8+
from crewai.rag.embeddings.providers.ibm.watsonx import (
9+
WatsonXProvider,
910
)
1011

1112
__all__ = [
12-
"WatsonProvider",
13-
"WatsonProviderConfig",
1413
"WatsonProviderSpec",
14+
"WatsonXProvider",
15+
"WatsonXProviderConfig",
16+
"WatsonXProviderSpec",
1517
]

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
"""IBM Watson embedding function implementation."""
1+
"""IBM WatsonX embedding function implementation."""
22

33
from typing import cast
44

55
from typing_extensions import Unpack
66

77
from crewai.rag.core.base_embeddings_callable import EmbeddingFunction
88
from crewai.rag.core.types import Documents, Embeddings
9-
from crewai.rag.embeddings.providers.ibm.types import WatsonProviderConfig
9+
from crewai.rag.embeddings.providers.ibm.types import WatsonXProviderConfig
1010

1111

12-
class WatsonEmbeddingFunction(EmbeddingFunction[Documents]):
13-
"""Embedding function for IBM Watson models."""
12+
class WatsonXEmbeddingFunction(EmbeddingFunction[Documents]):
13+
"""Embedding function for IBM WatsonX models."""
1414

15-
def __init__(self, **kwargs: Unpack[WatsonProviderConfig]) -> None:
16-
"""Initialize Watson embedding function.
15+
def __init__(self, **kwargs: Unpack[WatsonXProviderConfig]) -> None:
16+
"""Initialize WatsonX embedding function.
1717
1818
Args:
19-
**kwargs: Configuration parameters for Watson Embeddings and Credentials.
19+
**kwargs: Configuration parameters for WatsonX Embeddings and Credentials.
2020
"""
2121
self._config = kwargs
2222

@@ -40,7 +40,7 @@ def __call__(self, input: Documents) -> Embeddings:
4040

4141
except ImportError as e:
4242
raise ImportError(
43-
"ibm-watsonx-ai is required for watson embeddings. "
43+
"ibm-watsonx-ai is required for watsonx embeddings. "
4444
"Install it with: uv add ibm-watsonx-ai"
4545
) from e
4646

@@ -150,5 +150,5 @@ def __call__(self, input: Documents) -> Embeddings:
150150
embeddings = embedding.embed_documents(input)
151151
return cast(Embeddings, embeddings)
152152
except Exception as e:
153-
print(f"Error during Watson embedding: {e}")
153+
print(f"Error during WatsonX embedding: {e}")
154154
raise

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
"""Type definitions for IBM Watson embedding providers."""
1+
"""Type definitions for IBM WatsonX embedding providers."""
22

33
from typing import Annotated, Any, Literal
44

5-
from typing_extensions import Required, TypedDict
5+
from typing_extensions import Required, TypedDict, deprecated
66

77

8-
class WatsonProviderConfig(TypedDict, total=False):
9-
"""Configuration for Watson provider."""
8+
class WatsonXProviderConfig(TypedDict, total=False):
9+
"""Configuration for WatsonX provider."""
1010

1111
model_id: str
1212
url: str
@@ -37,8 +37,22 @@ class WatsonProviderConfig(TypedDict, total=False):
3737
proxies: dict
3838

3939

40+
class WatsonXProviderSpec(TypedDict, total=False):
41+
"""WatsonX provider specification."""
42+
43+
provider: Required[Literal["watsonx"]]
44+
config: WatsonXProviderConfig
45+
46+
47+
@deprecated(
48+
'The "WatsonProviderSpec" provider spec is deprecated and will be removed in v1.0.0. Use "WatsonXProviderSpec" instead.'
49+
)
4050
class WatsonProviderSpec(TypedDict, total=False):
41-
"""Watson provider specification."""
51+
"""Watson provider specification (deprecated).
52+
53+
Notes:
54+
- This is deprecated. Use WatsonXProviderSpec with provider="watsonx" instead.
55+
"""
4256

4357
provider: Required[Literal["watson"]]
44-
config: WatsonProviderConfig
58+
config: WatsonXProviderConfig

src/crewai/rag/embeddings/providers/ibm/watson.py renamed to src/crewai/rag/embeddings/providers/ibm/watsonx.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""IBM Watson embeddings provider."""
1+
"""IBM WatsonX embeddings provider."""
22

33
from typing import Any
44

@@ -7,130 +7,130 @@
77

88
from crewai.rag.core.base_embeddings_provider import BaseEmbeddingsProvider
99
from crewai.rag.embeddings.providers.ibm.embedding_callable import (
10-
WatsonEmbeddingFunction,
10+
WatsonXEmbeddingFunction,
1111
)
1212

1313

14-
class WatsonProvider(BaseEmbeddingsProvider[WatsonEmbeddingFunction]):
15-
"""IBM Watson embeddings provider.
14+
class WatsonXProvider(BaseEmbeddingsProvider[WatsonXEmbeddingFunction]):
15+
"""IBM WatsonX embeddings provider.
1616
17-
Note: Requires custom implementation as Watson uses a different interface.
17+
Note: Requires custom implementation as WatsonX uses a different interface.
1818
"""
1919

20-
embedding_callable: type[WatsonEmbeddingFunction] = Field(
21-
default=WatsonEmbeddingFunction, description="Watson embedding function class"
20+
embedding_callable: type[WatsonXEmbeddingFunction] = Field(
21+
default=WatsonXEmbeddingFunction, description="WatsonX embedding function class"
2222
)
2323
model_id: str = Field(
24-
description="Watson model ID", validation_alias="EMBEDDINGS_WATSON_MODEL_ID"
24+
description="WatsonX model ID", validation_alias="EMBEDDINGS_WATSONX_MODEL_ID"
2525
)
2626
params: dict[str, str | dict[str, str]] | None = Field(
2727
default=None, description="Additional parameters"
2828
)
29-
credentials: Any | None = Field(default=None, description="Watson credentials")
29+
credentials: Any | None = Field(default=None, description="WatsonX credentials")
3030
project_id: str | None = Field(
3131
default=None,
32-
description="Watson project ID",
33-
validation_alias="EMBEDDINGS_WATSON_PROJECT_ID",
32+
description="WatsonX project ID",
33+
validation_alias="EMBEDDINGS_WATSONX_PROJECT_ID",
3434
)
3535
space_id: str | None = Field(
3636
default=None,
37-
description="Watson space ID",
38-
validation_alias="EMBEDDINGS_WATSON_SPACE_ID",
37+
description="WatsonX space ID",
38+
validation_alias="EMBEDDINGS_WATSONX_SPACE_ID",
3939
)
40-
api_client: Any | None = Field(default=None, description="Watson API client")
40+
api_client: Any | None = Field(default=None, description="WatsonX API client")
4141
verify: bool | str | None = Field(
4242
default=None,
4343
description="SSL verification",
44-
validation_alias="EMBEDDINGS_WATSON_VERIFY",
44+
validation_alias="EMBEDDINGS_WATSONX_VERIFY",
4545
)
4646
persistent_connection: bool = Field(
4747
default=True,
4848
description="Use persistent connection",
49-
validation_alias="EMBEDDINGS_WATSON_PERSISTENT_CONNECTION",
49+
validation_alias="EMBEDDINGS_WATSONX_PERSISTENT_CONNECTION",
5050
)
5151
batch_size: int = Field(
5252
default=100,
5353
description="Batch size for processing",
54-
validation_alias="EMBEDDINGS_WATSON_BATCH_SIZE",
54+
validation_alias="EMBEDDINGS_WATSONX_BATCH_SIZE",
5555
)
5656
concurrency_limit: int = Field(
5757
default=10,
5858
description="Concurrency limit",
59-
validation_alias="EMBEDDINGS_WATSON_CONCURRENCY_LIMIT",
59+
validation_alias="EMBEDDINGS_WATSONX_CONCURRENCY_LIMIT",
6060
)
6161
max_retries: int | None = Field(
6262
default=None,
6363
description="Maximum retries",
64-
validation_alias="EMBEDDINGS_WATSON_MAX_RETRIES",
64+
validation_alias="EMBEDDINGS_WATSONX_MAX_RETRIES",
6565
)
6666
delay_time: float | None = Field(
6767
default=None,
6868
description="Delay time between retries",
69-
validation_alias="EMBEDDINGS_WATSON_DELAY_TIME",
69+
validation_alias="EMBEDDINGS_WATSONX_DELAY_TIME",
7070
)
7171
retry_status_codes: list[int] | None = Field(
7272
default=None, description="HTTP status codes to retry on"
7373
)
7474
url: str = Field(
75-
description="Watson API URL", validation_alias="EMBEDDINGS_WATSON_URL"
75+
description="WatsonX API URL", validation_alias="EMBEDDINGS_WATSONX_URL"
7676
)
7777
api_key: str = Field(
78-
description="Watson API key", validation_alias="EMBEDDINGS_WATSON_API_KEY"
78+
description="WatsonX API key", validation_alias="EMBEDDINGS_WATSONX_API_KEY"
7979
)
8080
name: str | None = Field(
8181
default=None,
8282
description="Service name",
83-
validation_alias="EMBEDDINGS_WATSON_NAME",
83+
validation_alias="EMBEDDINGS_WATSONX_NAME",
8484
)
8585
iam_serviceid_crn: str | None = Field(
8686
default=None,
8787
description="IAM service ID CRN",
88-
validation_alias="EMBEDDINGS_WATSON_IAM_SERVICEID_CRN",
88+
validation_alias="EMBEDDINGS_WATSONX_IAM_SERVICEID_CRN",
8989
)
9090
trusted_profile_id: str | None = Field(
9191
default=None,
9292
description="Trusted profile ID",
93-
validation_alias="EMBEDDINGS_WATSON_TRUSTED_PROFILE_ID",
93+
validation_alias="EMBEDDINGS_WATSONX_TRUSTED_PROFILE_ID",
9494
)
9595
token: str | None = Field(
9696
default=None,
9797
description="Bearer token",
98-
validation_alias="EMBEDDINGS_WATSON_TOKEN",
98+
validation_alias="EMBEDDINGS_WATSONX_TOKEN",
9999
)
100100
projects_token: str | None = Field(
101101
default=None,
102102
description="Projects token",
103-
validation_alias="EMBEDDINGS_WATSON_PROJECTS_TOKEN",
103+
validation_alias="EMBEDDINGS_WATSONX_PROJECTS_TOKEN",
104104
)
105105
username: str | None = Field(
106106
default=None,
107107
description="Username",
108-
validation_alias="EMBEDDINGS_WATSON_USERNAME",
108+
validation_alias="EMBEDDINGS_WATSONX_USERNAME",
109109
)
110110
password: str | None = Field(
111111
default=None,
112112
description="Password",
113-
validation_alias="EMBEDDINGS_WATSON_PASSWORD",
113+
validation_alias="EMBEDDINGS_WATSONX_PASSWORD",
114114
)
115115
instance_id: str | None = Field(
116116
default=None,
117117
description="Service instance ID",
118-
validation_alias="EMBEDDINGS_WATSON_INSTANCE_ID",
118+
validation_alias="EMBEDDINGS_WATSONX_INSTANCE_ID",
119119
)
120120
version: str | None = Field(
121121
default=None,
122122
description="API version",
123-
validation_alias="EMBEDDINGS_WATSON_VERSION",
123+
validation_alias="EMBEDDINGS_WATSONX_VERSION",
124124
)
125125
bedrock_url: str | None = Field(
126126
default=None,
127127
description="Bedrock URL",
128-
validation_alias="EMBEDDINGS_WATSON_BEDROCK_URL",
128+
validation_alias="EMBEDDINGS_WATSONX_BEDROCK_URL",
129129
)
130130
platform_url: str | None = Field(
131131
default=None,
132132
description="Platform URL",
133-
validation_alias="EMBEDDINGS_WATSON_PLATFORM_URL",
133+
validation_alias="EMBEDDINGS_WATSONX_PLATFORM_URL",
134134
)
135135
proxies: dict | None = Field(default=None, description="Proxy configuration")
136136

src/crewai/rag/embeddings/types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
VertexAIProviderSpec,
1212
)
1313
from crewai.rag.embeddings.providers.huggingface.types import HuggingFaceProviderSpec
14-
from crewai.rag.embeddings.providers.ibm.types import WatsonProviderSpec
14+
from crewai.rag.embeddings.providers.ibm.types import WatsonXProviderSpec
1515
from crewai.rag.embeddings.providers.instructor.types import InstructorProviderSpec
1616
from crewai.rag.embeddings.providers.jina.types import JinaProviderSpec
1717
from crewai.rag.embeddings.providers.microsoft.types import AzureProviderSpec
@@ -44,7 +44,7 @@
4444
| Text2VecProviderSpec
4545
| VertexAIProviderSpec
4646
| VoyageAIProviderSpec
47-
| WatsonProviderSpec
47+
| WatsonXProviderSpec
4848
)
4949

5050
AllowedEmbeddingProviders = Literal[
@@ -65,7 +65,8 @@
6565
"sentence-transformer",
6666
"text2vec",
6767
"voyageai",
68-
"watson",
68+
"watsonx",
69+
"watson", # for backward compatibility until v1.0.0
6970
]
7071

7172
EmbedderConfig: TypeAlias = (

0 commit comments

Comments
 (0)