Files
life-echo/api/app/tasks/memory_enrichment_tasks.py
Kevin 064ad2161d refactor(eval+memoir):精简内部评测路由与服务,composite/对话摘要与 judge 能力补强
- 访谈:新增 interview_state_hints,联动 orchestrator 与提示词
- 回忆录:story_pipeline_sync/state/memory/post_commit 与 Celery 任务调整
- 基建:开发用 celery broker、compose/development 脚本、依赖注入
- eval-web:移除数据集/实验/版本等页面与流式轮询,突出 Playground
- 文档与单测同步
2026-04-08 21:36:12 +08:00

46 lines
1.5 KiB
Python

"""
Memory enrichment Celery task — runs asynchronously after ingest to generate
summaries, facts, and timeline events without blocking the memoir hot path.
"""
from celery import shared_task
from sqlalchemy.orm import Session
from app.core.config import settings
from app.core.db import get_sync_db
from app.core.logging import get_logger
logger = get_logger(__name__)
@shared_task(bind=True, max_retries=2, default_retry_delay=30)
def enrich_memory_source(self, user_id: str, source_id: str):
"""
Post-ingest enrichment: session summary, rolling summary, facts, timeline.
Runs outside the memoir Phase1 hot path so narrative generation isn't blocked.
"""
if not settings.memory_enrichment_enabled:
return {"status": "disabled"}
try:
with get_sync_db() as db:
from app.features.memory.enrichment import enrich_memory_after_ingest_sync
enrich_memory_after_ingest_sync(db, user_id, source_id, llm=None)
db.commit()
logger.info(
"event=memory_enrichment_done user_id={} source_id={}",
user_id,
source_id,
)
return {"status": "success", "source_id": source_id}
except Exception as e:
logger.warning(
"event=memory_enrichment_failed user_id={} source_id={} exc={} exc_type={}",
user_id,
source_id,
e,
type(e).__name__,
)
raise self.retry(exc=e) from e