Skip to content

EmbeddingWithMOLMIM

Embedding class using MOLMIM model from NVIDIA NIM.

EmbeddingWithMOLMIM

Bases: Embeddings

Embedding class using MOLMIM model from NVIDIA NIM

Source code in aiagents4pharma/talk2knowledgegraphs/utils/embeddings/nim_molmim.py
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
class EmbeddingWithMOLMIM(Embeddings):
    """
    Embedding class using MOLMIM model from NVIDIA NIM
    """
    def __init__(self, base_url: str):
        """
        Initialize the EmbeddingWithMOLMIM class.

        Args:
            base_url: The base URL for the NIM/MOLMIM model.
        """
        # Set base URL
        self.base_url = base_url

    def embed_documents(self, texts: List[str]) -> List[float]:
        """
        Generate embedding for a list of SMILES strings using MOLMIM model.

        Args:
            texts: The list of SMILES strings to be embedded.

        Returns:
            The list of embeddings for the given SMILES strings.
        """
        headers = {
            'accept': 'application/json',
            'Content-Type': 'application/json'
        }
        data = json.dumps({"sequences": texts})
        response = requests.post(self.base_url, headers=headers, data=data, timeout=60)
        embeddings = response.json()["embeddings"]
        return embeddings

    def embed_query(self, text: str) -> List[float]:
        """
        Generate embeddings for an input query using MOLMIM model.

        Args:
            text: A query to be embedded.
        Returns:
            The embeddings for the given query.
        """
        # Generate the embedding
        embeddings = self.embed_documents([text])
        return embeddings

__init__(base_url)

Initialize the EmbeddingWithMOLMIM class.

Parameters:

Name Type Description Default
base_url str

The base URL for the NIM/MOLMIM model.

required
Source code in aiagents4pharma/talk2knowledgegraphs/utils/embeddings/nim_molmim.py
14
15
16
17
18
19
20
21
22
def __init__(self, base_url: str):
    """
    Initialize the EmbeddingWithMOLMIM class.

    Args:
        base_url: The base URL for the NIM/MOLMIM model.
    """
    # Set base URL
    self.base_url = base_url

embed_documents(texts)

Generate embedding for a list of SMILES strings using MOLMIM model.

Parameters:

Name Type Description Default
texts List[str]

The list of SMILES strings to be embedded.

required

Returns:

Type Description
List[float]

The list of embeddings for the given SMILES strings.

Source code in aiagents4pharma/talk2knowledgegraphs/utils/embeddings/nim_molmim.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def embed_documents(self, texts: List[str]) -> List[float]:
    """
    Generate embedding for a list of SMILES strings using MOLMIM model.

    Args:
        texts: The list of SMILES strings to be embedded.

    Returns:
        The list of embeddings for the given SMILES strings.
    """
    headers = {
        'accept': 'application/json',
        'Content-Type': 'application/json'
    }
    data = json.dumps({"sequences": texts})
    response = requests.post(self.base_url, headers=headers, data=data, timeout=60)
    embeddings = response.json()["embeddings"]
    return embeddings

embed_query(text)

Generate embeddings for an input query using MOLMIM model.

Parameters:

Name Type Description Default
text str

A query to be embedded.

required

Returns: The embeddings for the given query.

Source code in aiagents4pharma/talk2knowledgegraphs/utils/embeddings/nim_molmim.py
43
44
45
46
47
48
49
50
51
52
53
54
def embed_query(self, text: str) -> List[float]:
    """
    Generate embeddings for an input query using MOLMIM model.

    Args:
        text: A query to be embedded.
    Returns:
        The embeddings for the given query.
    """
    # Generate the embedding
    embeddings = self.embed_documents([text])
    return embeddings