feat: RAG 임베딩 자동 동기화 + AI 서비스 개선
- 부적합 라이프사이클 전 과정에서 Qdrant 임베딩 자동 동기화 - 관리함 5개 저장 함수 + 수신함 상태 변경 시 fire-and-forget sync - 30분 주기 전체 재동기화 안전망 (FastAPI lifespan 백그라운드 태스크) - build_document_text에 카테고리(final_category/category) 포함 - RAG 질의에 DB 통계 집계 지원 (카테고리별/부서별 건수) - Qdrant client.search → query_points API 마이그레이션 - AI 어시스턴트 페이지 권한 추가 (tkuser) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI, Request
|
||||
@@ -11,6 +13,8 @@ from db.metadata_store import metadata_store
|
||||
from services.ollama_client import ollama_client
|
||||
from middlewares.auth import verify_token
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PUBLIC_PATHS = {"/", "/api/ai/health", "/api/ai/models"}
|
||||
|
||||
|
||||
@@ -25,11 +29,29 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
||||
return await call_next(request)
|
||||
|
||||
|
||||
async def _periodic_sync():
|
||||
"""30분마다 전체 이슈 재동기화 (안전망)"""
|
||||
await asyncio.sleep(60) # 시작 후 1분 대기 (초기화 완료 보장)
|
||||
while True:
|
||||
try:
|
||||
from services.embedding_service import sync_all_issues
|
||||
result = await sync_all_issues()
|
||||
logger.info(f"Periodic sync completed: {result}")
|
||||
except asyncio.CancelledError:
|
||||
logger.info("Periodic sync task cancelled")
|
||||
return
|
||||
except Exception as e:
|
||||
logger.warning(f"Periodic sync failed: {e}")
|
||||
await asyncio.sleep(1800) # 30분
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
vector_store.initialize()
|
||||
metadata_store.initialize()
|
||||
sync_task = asyncio.create_task(_periodic_sync())
|
||||
yield
|
||||
sync_task.cancel()
|
||||
await ollama_client.close()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user