Skip to content

Watsonx

WatsonXDocumentEmbedder

Bases: DocumentEmbedder

Provides functionality to compute embeddings for documents using WatsonX models.

This class extends ConnectionNode to create embeddings for documents using litellm embedding.

Attributes:

Name Type Description
group Literal[EMBEDDERS]

The group the node belongs to.

name str

The name of the node.

connection WatsonX | None

The connection to the WatsonX API.

model str

The model name to use for embedding.

document_embedder WatsonXDocumentEmbedderComponent

The component for document embedding.

Parameters:

Name Type Description Default
connection Optional[WatsonX]

The connection to the WatsonX API. A new connection is created if none is provided.

required
model str

The model name to use for embedding. Defaults to 'watsonx/ibm/slate-30m-english-rtrvr'.

required
Source code in dynamiq/nodes/embedders/watsonx.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class WatsonXDocumentEmbedder(DocumentEmbedder):
    """
    Provides functionality to compute embeddings for documents using WatsonX models.

    This class extends ConnectionNode to create embeddings for documents using litellm embedding.

    Attributes:
        group (Literal[NodeGroup.EMBEDDERS]): The group the node belongs to.
        name (str): The name of the node.
        connection (WatsonXConnection | None): The connection to the WatsonX API.
        model (str): The model name to use for embedding.
        document_embedder (WatsonXDocumentEmbedderComponent): The component for document embedding.

    Args:
        connection (Optional[WatsonXConnection]): The connection to the WatsonX API. A new connection
            is created if none is provided.
        model (str): The model name to use for embedding. Defaults to 'watsonx/ibm/slate-30m-english-rtrvr'.
    """

    name: str = "WatsonXDocumentEmbedder"
    connection: WatsonXConnection | None = None
    model: str = "watsonx/ibm/slate-30m-english-rtrvr"
    document_embedder: WatsonXEmbedderComponent | None = None

    def __init__(self, **kwargs):
        """
        Initializes the WatsonXDocumentEmbedder.

        If neither client nor connection is provided in kwargs, a new WatsonXConnection is created.

        Args:
            **kwargs: Arbitrary keyword arguments.
        """
        if kwargs.get("client") is None and kwargs.get("connection") is None:
            kwargs["connection"] = WatsonXConnection()
        super().__init__(**kwargs)

    def init_components(self, connection_manager: ConnectionManager | None = None):
        """
        Initializes the components of the WatsonXDocumentEmbedder.

        This method sets up the document_embedder component if it hasn't been initialized yet.

        Args:
            connection_manager (ConnectionManager): The connection manager to use. Defaults to a new
                ConnectionManager instance.
        """
        connection_manager = connection_manager or ConnectionManager()
        super().init_components(connection_manager)
        if self.document_embedder is None:
            self.document_embedder = WatsonXEmbedderComponent(
                connection=self.connection, model=self.model, client=self.client
            )

__init__(**kwargs)

Initializes the WatsonXDocumentEmbedder.

If neither client nor connection is provided in kwargs, a new WatsonXConnection is created.

Parameters:

Name Type Description Default
**kwargs

Arbitrary keyword arguments.

{}
Source code in dynamiq/nodes/embedders/watsonx.py
31
32
33
34
35
36
37
38
39
40
41
42
def __init__(self, **kwargs):
    """
    Initializes the WatsonXDocumentEmbedder.

    If neither client nor connection is provided in kwargs, a new WatsonXConnection is created.

    Args:
        **kwargs: Arbitrary keyword arguments.
    """
    if kwargs.get("client") is None and kwargs.get("connection") is None:
        kwargs["connection"] = WatsonXConnection()
    super().__init__(**kwargs)

init_components(connection_manager=None)

Initializes the components of the WatsonXDocumentEmbedder.

This method sets up the document_embedder component if it hasn't been initialized yet.

Parameters:

Name Type Description Default
connection_manager ConnectionManager

The connection manager to use. Defaults to a new ConnectionManager instance.

None
Source code in dynamiq/nodes/embedders/watsonx.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def init_components(self, connection_manager: ConnectionManager | None = None):
    """
    Initializes the components of the WatsonXDocumentEmbedder.

    This method sets up the document_embedder component if it hasn't been initialized yet.

    Args:
        connection_manager (ConnectionManager): The connection manager to use. Defaults to a new
            ConnectionManager instance.
    """
    connection_manager = connection_manager or ConnectionManager()
    super().init_components(connection_manager)
    if self.document_embedder is None:
        self.document_embedder = WatsonXEmbedderComponent(
            connection=self.connection, model=self.model, client=self.client
        )

WatsonXTextEmbedder

Bases: TextEmbedder

A component designed to embed strings using specified WatsonX models.

This class extends ConnectionNode to provide text embedding functionality using WatsonX API.

Parameters:

Name Type Description Default
connection Optional[WatsonX]

An existing connection to WatsonX API. If not provided, a new connection will be established using environment variables.

required
model str

The identifier of the WatsonX model for text embeddings. Defaults to 'watsonx/ibm/slate-30m-english-rtrvr'.

required

Attributes:

Name Type Description
group Literal[EMBEDDERS]

The group the node belongs to.

name str

The name of the node.

connection WatsonX | None

The connection to WatsonX's API.

model str

The WatsonX model identifier for text embeddings.

text_embedder WatsonXTextEmbedderComponent

The component for text embedding.

Source code in dynamiq/nodes/embedders/watsonx.py
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class WatsonXTextEmbedder(TextEmbedder):
    """
    A component designed to embed strings using specified WatsonX models.

    This class extends ConnectionNode to provide text embedding functionality using WatsonX API.

    Args:
        connection (Optional[WatsonXConnection]): An existing connection to WatsonX API. If not
            provided, a new connection will be established using environment variables.
        model (str): The identifier of the WatsonX model for text embeddings. Defaults to
            'watsonx/ibm/slate-30m-english-rtrvr'.

    Attributes:
        group (Literal[NodeGroup.EMBEDDERS]): The group the node belongs to.
        name (str): The name of the node.
        connection (WatsonXConnection | None): The connection to WatsonX's API.
        model (str): The WatsonX model identifier for text embeddings.
        text_embedder (WatsonXTextEmbedderComponent): The component for text embedding.

    """

    name: str = "WatsonXTextEmbedder"
    connection: WatsonXConnection | None = None
    model: str = "watsonx/ibm/slate-30m-english-rtrvr"
    text_embedder: WatsonXEmbedderComponent = None

    def __init__(self, **kwargs):
        """Initialize the WatsonXTextEmbedder.

        If neither client nor connection is provided in kwargs, a new WatsonXConnection is created.

        Args:
            **kwargs: Keyword arguments to initialize the node.
        """
        if kwargs.get("client") is None and kwargs.get("connection") is None:
            kwargs["connection"] = WatsonXConnection()
        super().__init__(**kwargs)

    @property
    def to_dict_exclude_params(self):
        return super().to_dict_exclude_params | {"text_embedder": True}

    def init_components(self, connection_manager: ConnectionManager | None = None):
        """
        Initialize the components of the WatsonXTextEmbedder.

        This method sets up the text_embedder component if it hasn't been initialized yet.

        Args:
            connection_manager (ConnectionManager): The connection manager to use. Defaults to a new
                ConnectionManager instance.
        """
        connection_manager = connection_manager or ConnectionManager()
        super().init_components(connection_manager)
        if self.text_embedder is None:
            self.text_embedder = WatsonXEmbedderComponent(
                connection=self.connection, model=self.model, client=self.client
            )

__init__(**kwargs)

Initialize the WatsonXTextEmbedder.

If neither client nor connection is provided in kwargs, a new WatsonXConnection is created.

Parameters:

Name Type Description Default
**kwargs

Keyword arguments to initialize the node.

{}
Source code in dynamiq/nodes/embedders/watsonx.py
88
89
90
91
92
93
94
95
96
97
98
def __init__(self, **kwargs):
    """Initialize the WatsonXTextEmbedder.

    If neither client nor connection is provided in kwargs, a new WatsonXConnection is created.

    Args:
        **kwargs: Keyword arguments to initialize the node.
    """
    if kwargs.get("client") is None and kwargs.get("connection") is None:
        kwargs["connection"] = WatsonXConnection()
    super().__init__(**kwargs)

init_components(connection_manager=None)

Initialize the components of the WatsonXTextEmbedder.

This method sets up the text_embedder component if it hasn't been initialized yet.

Parameters:

Name Type Description Default
connection_manager ConnectionManager

The connection manager to use. Defaults to a new ConnectionManager instance.

None
Source code in dynamiq/nodes/embedders/watsonx.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def init_components(self, connection_manager: ConnectionManager | None = None):
    """
    Initialize the components of the WatsonXTextEmbedder.

    This method sets up the text_embedder component if it hasn't been initialized yet.

    Args:
        connection_manager (ConnectionManager): The connection manager to use. Defaults to a new
            ConnectionManager instance.
    """
    connection_manager = connection_manager or ConnectionManager()
    super().init_components(connection_manager)
    if self.text_embedder is None:
        self.text_embedder = WatsonXEmbedderComponent(
            connection=self.connection, model=self.model, client=self.client
        )