Skip to content

Commit 6980087

Browse files
feat: Added support for initialise WatsonxEmbeddings with Embedding object (#82)
* Added support for initialize WatsonxEmbeddings with Embedding object * patch version
1 parent 4933407 commit 6980087

File tree

5 files changed

+256
-145
lines changed

5 files changed

+256
-145
lines changed

libs/ibm/langchain_ibm/embeddings.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class WatsonxEmbeddings(BaseModel, LangChainEmbeddings):
1717
"""IBM watsonx.ai embedding models."""
1818

19-
model_id: str
19+
model_id: Optional[str] = None
2020
"""Type of model to use."""
2121

2222
project_id: Optional[str] = None
@@ -85,7 +85,19 @@ class WatsonxEmbeddings(BaseModel, LangChainEmbeddings):
8585
@model_validator(mode="after")
8686
def validate_environment(self) -> Self:
8787
"""Validate that credentials and python package exists in environment."""
88-
if isinstance(self.watsonx_client, APIClient):
88+
if isinstance(self.watsonx_embed, Embeddings):
89+
self.model_id = getattr(self.watsonx_embed, "model_id")
90+
self.project_id = getattr(
91+
getattr(self.watsonx_embed, "_client"),
92+
"default_project_id",
93+
)
94+
self.space_id = getattr(
95+
getattr(self.watsonx_embed, "_client"), "default_space_id"
96+
)
97+
98+
self.params = getattr(self.watsonx_embed, "params")
99+
100+
elif isinstance(self.watsonx_client, APIClient):
89101
watsonx_embed = Embeddings(
90102
model_id=self.model_id,
91103
params=self.params,

0 commit comments

Comments
 (0)