Download this file

55 lines (46 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 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
"""
Embedding class using MOLMIM model from NVIDIA NIM.
"""
import json
from typing import List
import requests
from .embeddings import Embeddings
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