PMFlow/backend/app/services/adaptive_rag_service/shared_imports.py

58 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""全自适应 RAG 服务。
能力:
1. 意图识别(question / statement / mixed)
2. 多域路由(结构化 DB + 向量检索)
3. 回答生成与来源引用
4. QA 记录、反馈、JSONL 导出
5. 知识库文档/URL/飞书消息入库向量化
"""
from __future__ import annotations
import ast
import asyncio
import hashlib
import json
import math
import os
from pathlib import Path
import re
import time
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any, Optional
import httpx
from sqlalchemy import and_, bindparam, delete, func, or_, select, text
from sqlalchemy.ext.asyncio import AsyncSession
from ..config.ai_prompts import PROMPT_RAG_ANSWER, PROMPT_RAG_DB_PROJECT_QA, PROMPT_RAG_INTENT_CLASSIFICATION
from ..database import AsyncSessionLocal
from ..models import (
KnowledgeBaseChunk,
KnowledgeBaseDoc,
KGEvidence,
KGEntity,
KGRelation,
Project,
ProjectSignalLink,
QAFeedback,
QARecord,
QASession,
QASessionState,
Signal,
Task,
TruthNode,
User,
UserProject,
UserWorkload,
)
from .context_cache import context_cache_service
from .llm import LLMService
from .signal_source_orchestration_service import SignalSourceOrchestrationService
from .symbol_index_service import SymbolIndexService
from ..utils.timezone import CN_TZ, now_cn_aware, now_cn_naive