fix: 補建 AIInsight ORM 模型(ai_insights 表缺少 class 定義)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m15s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m15s
ai_insights 表在 DB 存在且有 39 筆資料,但 database/ai_models.py 從未定義 AIInsight class,導致 quality_rescore_task、openclaw_learning_service 以及所有 AI KM 讀寫全部 ImportError 崩潰。 同步補入 __all__ 匯出,修復 embedding_retry_queue 2 筆卡住。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -119,7 +119,50 @@ class AIUsageTracking(Base):
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None
|
||||
}
|
||||
|
||||
class AIInsight(Base):
|
||||
"""
|
||||
AI 洞察知識庫(ai_insights 表)— KM 沉澱核心,支援 RAG 向量化。
|
||||
對應 openclaw_learning_service / scheduler 各任務寫入。
|
||||
"""
|
||||
__tablename__ = 'ai_insights'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
insight_type = Column(String(50), nullable=False) # backup_status / human_review / auto_heal_playbook 等
|
||||
period = Column(String(50)) # 分析週期,e.g. "2026-04-20"
|
||||
product_sku = Column(String(50))
|
||||
content = Column(Text, nullable=False)
|
||||
metadata_json = Column(Text) # JSON extra payload
|
||||
avg_quality = Column(Float, default=0.0)
|
||||
status = Column(String(20), default='active') # active / archived
|
||||
decay_exempt = Column(Boolean, default=False)
|
||||
ai_model = Column(String(50))
|
||||
feedback_up = Column(Integer, default=0)
|
||||
feedback_down = Column(Integer, default=0)
|
||||
confidence = Column(Float, default=1.0)
|
||||
created_by = Column(String(50))
|
||||
created_at = Column(DateTime, default=datetime.now)
|
||||
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
|
||||
# embedding 欄位為 pgvector 型別,透過 raw SQL 寫入,此處不聲明以避免型別衝突
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'insight_type': self.insight_type,
|
||||
'period': self.period,
|
||||
'product_sku': self.product_sku,
|
||||
'content': self.content,
|
||||
'avg_quality': self.avg_quality,
|
||||
'status': self.status,
|
||||
'ai_model': self.ai_model,
|
||||
'feedback_up': self.feedback_up,
|
||||
'feedback_down': self.feedback_down,
|
||||
'confidence': self.confidence,
|
||||
'created_by': self.created_by,
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
}
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AgentContext", "ActionPlan", "ActionOutcome", "AgentStrategyWeights",
|
||||
"AIGenerationHistory", "AIPromptTemplate", "AIUsageTracking"
|
||||
"AIGenerationHistory", "AIPromptTemplate", "AIUsageTracking", "AIInsight",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user