File size: 591 Bytes
98c2017
 
 
 
 
 
 
 
 
 
 
 
41c2439
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from typing import Dict, List, Any
from InstructorEmbedding import INSTRUCTOR

class EndpointHandler():
    def __init__(self, path=""):
        self.model = INSTRUCTOR(path)

    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
        instruction = data.get("instruction", "")
        document = data.get("document", "")
        embedding = self.model.encode([[instruction, document]]).flatten()

        return [
            {
                "embedding": embedding,
                "instruction": instruction,
                "document": document
            }
        ]