-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrag_memecoin_update_workflow.py
More file actions
119 lines (97 loc) · 3.99 KB
/
rag_memecoin_update_workflow.py
File metadata and controls
119 lines (97 loc) · 3.99 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
RAG Memecoin Update Workflow
Orchestrates the complete update pipeline:
1. MemoryMemecoinInputSource - Single-item input
2. RAGMemecoinUpdateProcessor - Validation + re-embedding
3. MemecoinUpdateExecutor - Atomic vector DB updates
Returns success status after execution.
"""
import asyncio
import logging
from typing import Dict, Optional
from src.domain.input_source.memory_memecoin_input_source import (
MemoryMemecoinInputSource,
)
from src.domain.processor.rag_memecoin_update_processor import (
RAGMemecoinUpdateProcessor,
)
from src.domain.executor.memecoin_update_executor import MemecoinUpdateExecutor
from src.domain.workflow.default_workflow import DefaultWorkflow
from src.services.ai.clip_embedding_service import CLIPEmbeddingService
from src.vector_store.memecoin_store import MemecoinVectorStore
logger = logging.getLogger(__name__)
class RAGMemecoinUpdateWorkflow:
"""
Workflow for updating existing memecoins in vector database.
Flow:
1. MemoryMemecoinInputSource emits single MemecoinReadEvent
2. RAGMemecoinUpdateProcessor validates and re-embeds captions
3. MemecoinUpdateExecutor atomically updates all 5 vector DB collections
4. Returns success/failure status
"""
def __init__(
self,
clip_service: CLIPEmbeddingService,
vector_store: MemecoinVectorStore,
):
self.clip_service = clip_service
self.vector_store = vector_store
self.workflow: Optional[DefaultWorkflow] = None
self.input_source: Optional[MemoryMemecoinInputSource] = None
async def run(
self, memecoin_data: Dict, token_address: str
) -> tuple[bool, str]:
"""
Run the update workflow for a single memecoin.
Args:
memecoin_data: Dict with updated memecoin data (must include caption_structured)
token_address: Token address to update
Returns:
tuple[bool, str]: (success, message)
"""
try:
logger.info(
f"🚀 Starting RAGMemecoinUpdateWorkflow for {token_address}"
)
# Create input source
self.input_source = MemoryMemecoinInputSource(memecoin_data)
# Create processor
processor = RAGMemecoinUpdateProcessor(
clip_service=self.clip_service,
token_address=token_address,
)
# Create executor
executor = MemecoinUpdateExecutor(vector_store=self.vector_store)
# Create workflow
self.workflow = DefaultWorkflow(
input_source=self.input_source,
processor=processor,
executor=executor,
)
# Initialize and run workflow
await self.workflow.initialize()
# Start workflow (runs until input source stops)
await self.workflow.run_indefinitely()
# Verify that processing actually succeeded by checking executor execution count
# If validation failed or processing was terminated, executor.execute() was never called
if executor.execution_count == 0:
logger.error(
f"❌ RAGMemecoinUpdateWorkflow validation failed for {token_address}"
)
return False, f"Validation failed or processing incomplete for {token_address}"
logger.info(
f"✅ RAGMemecoinUpdateWorkflow completed for {token_address}"
)
return True, f"Successfully updated {token_address}"
except Exception as e:
error_msg = f"Update workflow failed for {token_address}: {e}"
logger.error(f"❌ {error_msg}")
return False, error_msg
async def cleanup(self):
"""Cleanup workflow resources"""
try:
if self.workflow:
await self.workflow.stop()
logger.info("🧹 Update workflow cleaned up")
except Exception as e:
logger.error(f"❌ Error during cleanup: {e}")