@@ -59,35 +59,35 @@ async def index(self, payload, msg, verbose=False, field=None, charge=False, ins
59
59
payload .embedding = self .model .encode (
60
60
f"{ instruction } { payload .text } " , normalize_embeddings = True )
61
61
except Exception as e :
62
+ return _f ('fatal' , e )
63
+ await msg .in_progress ()
64
+ try :
65
+ _f ('info' , f'indexing payload' ) if verbose else None
66
+ if not self .is_dupe (q = payload .embedding ):
67
+ self .db .collection .insert ([
68
+ [payload .document ], [payload .text ], [payload .embedding ]
69
+ ])
70
+ self .db .collection .flush (collection_name_array = [
71
+ self .config ['INDEX' ]])
72
+ if charge :
73
+ payload = EmbeddingPayload (
74
+ model = self .config ['MODEL' ],
75
+ embedding = self .model .encode (
76
+ f"{ instruction } { payload .text } " , normalize_embeddings = True ).tolist (),
77
+ text = payload .text ,
78
+ document = payload .document
79
+ )
80
+ if field :
81
+ _f ('info' , f'sending payload\n { payload } ' ) if verbose else None
82
+ await self .field .pulse (payload )
83
+ await msg .ack_sync (timeout = 15 )
84
+ else :
85
+ await msg .ack_sync (timeout = 15 )
86
+ _f ('warn' , f'embedding exists already\n { payload } ' ) if verbose else None
87
+
88
+ except Exception as e :
89
+ await msg .term ()
62
90
_f ('fatal' , e )
63
- else :
64
- await msg .in_progress ()
65
- try :
66
- _f ('info' , f'indexing payload' ) if verbose else None
67
- if not self .is_dupe (q = payload .embedding ):
68
- self .db .collection .insert ([
69
- [payload .document ], [payload .text ], [payload .embedding ]
70
- ])
71
- self .db .collection .flush (collection_name_array = [
72
- self .config ['INDEX' ]])
73
- if charge :
74
- payload = EmbeddingPayload (
75
- model = self .config ['MODEL' ],
76
- embedding = self .model .encode (
77
- f"{ instruction } { payload .text } " , normalize_embeddings = True ).tolist (),
78
- text = payload .text ,
79
- document = payload .document
80
- )
81
- if field :
82
- _f ('info' , f'sending payload\n { payload } ' ) if verbose else None
83
- await self .field .pulse (payload )
84
- await msg .ack_sync (timeout = 15 )
85
- else :
86
- _f ('warn' , f'embedding exists already\n { payload .text } ' ) if verbose else None
87
- await msg .ack_sync (timeout = 15 )
88
- except Exception as e :
89
- await msg .term ()
90
- _f ('fatal' , e )
91
91
92
92
def search (self , payload , limit = 100 , cb = None , instruction = "Represent this sentence for searching relevant passages: " ):
93
93
"""
0 commit comments