File size: 1,285 Bytes
37e46db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from src.entity import InferenceAPIConfig
from src.utils.vector_store_utils import get_embedding, pc_client
from src.utils.data_ingestion_utils import *
from src.utils.inference_utils import extract_ids

class InferenceEps:
    def __init__(self, config:InferenceAPIConfig):
        self.config = config
        self.pc_index=pc_client.Index(self.config.pc_index)
    
    
    def get_vector_ebd(self, query:str) -> list[float]:
        try:
            ebd = get_embedding(query)
            ebd = ebd.flatten().tolist()
            return ebd
        except:
            return 500
    
    
    def vector_search(self, vector):
        try:
            records = self.pc_index.query(
                vector=vector,
                top_k=100,
            )['matches']
        
            ids = extract_ids(records)
            query = {
                'objectID': { 
                    '$in': ids 
                }
            }
        
            records = dataloader(
                db=self.config.cluster_db, 
                collection=self.config.prod_collection, 
                query=query, 
                proj={"_id":0}
            )        
        
            data = [record for record in records]

            return data
        except:
            return 500