feat(backend): knowledge iteration + vision + neo4j + response contract source

dependencies.py 拆分为 dependencies/ 包; 新增 vision/ragflow_ingestion/neo4j 客户端与 h5_ai_task; alembic 045 图置信度迁移; 响应契约统一收尾。
This commit is contained in:
Simon
2026-07-09 11:47:16 +08:00
parent f5374fce9b
commit ead5f83bee
39 changed files with 5276 additions and 545 deletions
+88 -2
View File
@@ -8,9 +8,9 @@
import uuid
from datetime import datetime
from typing import List, Optional
from typing import Any, Dict, List, Optional
from sqlalchemy import DateTime, Index, Integer, JSON, String, Text
from sqlalchemy import Boolean, DateTime, Float, Index, JSON, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
@@ -114,6 +114,89 @@ class KnowledgeSuggestion(Base):
comment="相关会话ID或标注ID列表",
)
# --------------------------------------------------------------------------
# Tier0 扩展字段 — 图结构 + 置信度 + 受众 + 状态(D1/D3/D7/D8
# --------------------------------------------------------------------------
# AI 生成置信度(0.0-1.0D3 门控阈值 0.7
confidence: Mapped[Optional[float]] = mapped_column(
Float,
nullable=True,
comment="AI 生成置信度(0.0-1.0",
)
# 受众类型(D8employee_quick_reply / engineer_workguide
audience: Mapped[Optional[str]] = mapped_column(
String(30),
nullable=True,
comment="受众类型:employee_quick_reply / engineer_workguide",
)
# 图结构字段 — 问题名称(对应 Neo4j Issue.name
issue: Mapped[Optional[str]] = mapped_column(
String(256),
nullable=True,
comment="图节点:问题名称",
)
# 图结构字段 — 动作名称(对应 Neo4j Action.name
action: Mapped[Optional[str]] = mapped_column(
String(256),
nullable=True,
comment="图节点:动作名称",
)
# 图关系类型(LEADS_TO / RELATES_TO / CAN_JUMP_TO
relation_type: Mapped[Optional[str]] = mapped_column(
String(30),
nullable=True,
comment="图关系类型",
)
# 父 Issue 名称(用于构建 Issue→Issue 关系)
parent_issue: Mapped[Optional[str]] = mapped_column(
String(256),
nullable=True,
comment="父 Issue 名称",
)
# 图结构扩展元数据(JSON,存放额外的图属性)
graph_meta: Mapped[Optional[Dict[str, Any]]] = mapped_column(
JSON,
nullable=True,
comment="图结构扩展元数据",
)
# 图同步状态(pending / synced / failed
graph_sync_status: Mapped[str] = mapped_column(
String(20),
nullable=False,
default="pending",
comment="图同步状态:pending / synced / failed",
)
# AI 生成失败标记(Dify 不可用或置信度不足时置 True)
source_failed: Mapped[bool] = mapped_column(
Boolean,
nullable=False,
default=False,
comment="AI 生成失败标记",
)
# 入队列时间
queued_at: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True),
nullable=True,
comment="入独立队列时间",
)
# 应用到 KB 的时间
applied_at: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True),
nullable=True,
comment="应用到 KB 的时间",
)
# 生成理由
reason: Mapped[Optional[str]] = mapped_column(
Text,
@@ -166,6 +249,9 @@ class KnowledgeSuggestion(Base):
Index("idx_suggestion_status", "status"),
Index("idx_suggestion_type", "suggestion_type"),
Index("idx_suggestion_created", "created_at"),
Index("idx_suggestion_audience", "audience"),
Index("idx_suggestion_confidence", "confidence"),
Index("idx_suggestion_graph_sync", "graph_sync_status"),
)
def __repr__(self) -> str: