IDEA-2/1/5/7: 스마트 알림, 대화 기반 RAG, CRAG, 파라미터 자동 튜닝

- IDEA-2 스마트 알림: td_reminders 테이블, set_reminder/list_reminders 도구,
  SchedulerService(asyncio 60초 루프, D-7/D-1/D-0 Telegram push),
  FastAPI lifespan 연동, GET /reminders/{user_id} 엔드포인트

- IDEA-1 대화 기반 RAG: IngestionService.store_text() 추가,
  AgentService._maybe_index_conversation() — 응답 후 LLM 판단 → Qdrant 저장
  (CONV_RAG_ENABLED=true 활성화, background task로 응답 속도 무관)

- IDEA-5 CRAG: AgentState에 crag_fallback_used 플래그 추가,
  crag_check LangGraph 노드 — search_documents 결과 없으면 web_search 자동 주입,
  route_after_crag으로 fallback 1회 루프 제어 (CRAG_ENABLED=true 활성화)

- IDEA-7 RAG Auto-Eval: eval/auto_tune.py — API 서버 없이 파라미터 조합별
  context_precision/recall 비교, 최적 설정 추천

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sal
2026-06-04 10:04:05 +09:00
parent c264573a67
commit 0b50444e43
11 changed files with 715 additions and 11 deletions
+26 -2
View File
@@ -21,6 +21,7 @@
import json
import os
import tempfile
from contextlib import asynccontextmanager
from dotenv import load_dotenv
load_dotenv()
@@ -32,12 +33,21 @@ from pydantic import BaseModel
from container import Container
from services.agent.agent_service import AgentService
app = FastAPI(title="율봇 API", version="1.0")
_container = Container()
_container.db_service().connect()
_container.db_service().init_schema()
@asynccontextmanager
async def lifespan(app: FastAPI):
scheduler = _container.scheduler_service()
scheduler.start()
yield
scheduler.shutdown()
app = FastAPI(title="율봇 API", version="1.0", lifespan=lifespan)
_cfg = _container.config()
_agent_cache: dict[str, AgentService] = {}
@@ -58,6 +68,10 @@ def _get_agent(user_id: str) -> AgentService:
query_rewrite_enabled=_cfg.query_rewrite_enabled,
user_profile_repository=_container.user_profile_repository(),
conversation_repository=_container.conversation_repository(),
reminder_repository=_container.reminder_repository(),
ingestion_service=_container.ingestion_service() if _cfg.conv_rag_enabled else None,
crag_enabled=_cfg.crag_enabled,
conv_rag_enabled=_cfg.conv_rag_enabled,
user_id=user_id,
)
if _vision_model:
@@ -182,3 +196,13 @@ async def delete_document(source: str, _=Depends(_auth)):
"""source 경로에 해당하는 모든 청크 삭제."""
_container.retriever_service().delete_document(source)
return {"deleted": source}
@app.get("/reminders/{user_id}")
async def list_reminders(user_id: str, days_ahead: int = 30, _=Depends(_auth)):
"""user_id의 예정 알림 목록 반환 (기본 30일 이내)."""
items = _container.reminder_repository().get_upcoming(user_id, days_ahead=days_ahead)
return {"reminders": [
{"id": r["id"], "remind_date": str(r["remind_date"]), "message": r["message"]}
for r in items
]}