|
2 | 2 | from magnet.ize import memory
|
3 | 3 | from magnet.ron import llm
|
4 | 4 |
|
| 5 | +from magnet.utils.globals import _f |
| 6 | + |
5 | 7 | class Electrode:
|
6 | 8 | def __init__(self, config: dict = None):
|
7 |
| - self.config = config if config else { |
8 |
| - "MILVUS_URI": "192.168.2.69" |
9 |
| - , "MILVUS_PORT": 19530 |
10 |
| - , "MILVUS_USER": "root" |
11 |
| - , "MILVUS_PASSWORD": "Rrr/Yp6k#<M19rB3j1>Mi4Ta" |
12 |
| - , "NATS_URL": "192.168.2.69" |
13 |
| - , "NATS_USER": "my-user" |
14 |
| - , "NATS_PASSWORD": "T0pS3cr3t" |
15 |
| - , "NATS_CATEGORY": "non_nlp_chunks" |
16 |
| - , "NATS_STREAM": "documents" |
17 |
| - , "NATS_SESSION": "bge_large_en_v15" |
18 |
| - , "DIMENSION": 1024 |
19 |
| - , "EMBEDDING_MODEL": "BAAI/bge-large-en-v1.5" |
20 |
| - , "INDEX": "bge_non_nlp" |
21 |
| - , "INDEX_PARAMS": { |
22 |
| - 'metric_type': 'COSINE', |
23 |
| - 'index_type':'HNSW', |
24 |
| - 'params': { |
25 |
| - "efConstruction": 40 |
26 |
| - , "M": 48 |
27 |
| - }, |
28 |
| - } |
29 |
| - , "JOB_TYPE": "index" |
30 |
| - , "JOB_N": 10 |
31 |
| - , "GENERATION_MODEL": "mistralai/Mistral-7B-Instruct-v0.1" |
32 |
| - , "CREATE": True |
33 |
| - } |
| 9 | + self.config = config if config else _f('fatal', 'no config applied') |
34 | 10 | async def auto(self):
|
35 | 11 | match self.config['JOB_TYPE']:
|
36 | 12 | case 'index':
|
37 | 13 | self.reso = field.Resonator(f"{self.config['NATS_USER']}:{self.config['NATS_PASSWORD']}@{self.config['NATS_URL']}")
|
38 | 14 | self.embedder = memory.Embedder(self.config, create=self.config["CREATE"])
|
39 |
| - await self.reso.on(category=self.config['NATS_CATEGORY'], session=self.config['NATS_SESSION'], stream=self.config['NATS_STREAM']) |
| 15 | + await self.reso.on(category=self.config['NATS_CATEGORY'], session=self.config['NATS_SESSION'], stream=self.config['NATS_STREAM'], job=True) |
40 | 16 | await self.reso.listen(cb=self.embedder.index, job_n=self.config['JOB_N'])
|
41 | 17 |
|
42 | 18 |
|
|
0 commit comments