Pavithiran commited on
Commit
2f0b579
·
verified ·
1 Parent(s): 350813f

Create model.py

Browse files
Files changed (1) hide show
  1. model.py +21 -0
model.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer
2
+ import torch
3
+
4
+ class Model:
5
+ def __init__(self):
6
+ # Load the pre-trained model
7
+ self.embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
8
+
9
+ def __call__(self, payload):
10
+ # Extract chunks from the payload
11
+ chunks = payload.get("chunks", [])
12
+
13
+ # Generate embeddings for chunks
14
+ embeddings = self.embedding_model.encode(chunks, convert_to_tensor=True)
15
+
16
+ # Prepare response with tensor embeddings
17
+ response = {
18
+ "embeddings": embeddings.tolist(), # Convert tensor to list for JSON serialization
19
+ "shape": list(embeddings.shape) # Return the shape of the embeddings tensor
20
+ }
21
+ return response