"""知识库表的 ORM 映射。 按 docs/00 基线与 docs/02 建表设计逐列对齐现库;milvus_collection 是基线自带字段, 不需要新增迁移。本模块只做映射,读写由 Repository/Service 负责。 """ from datetime import date, datetime from typing import Any from sqlalchemy import JSON, BigInteger, Date, DateTime, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.model.base import Base class KnowledgeMeta(Base): __tablename__ = "fin_knowledge_meta" id: Mapped[int] = mapped_column(BigInteger, primary_key=True) knowledge_type: Mapped[str] = mapped_column(String(32), nullable=False) title: Mapped[str] = mapped_column(String(256), nullable=False) source_file: Mapped[str | None] = mapped_column(String(256)) minio_path: Mapped[str | None] = mapped_column(String(512)) milvus_collection: Mapped[str] = mapped_column(String(64), nullable=False) version: Mapped[str | None] = mapped_column(String(16)) effective_date: Mapped[date | None] = mapped_column(Date) expire_date: Mapped[date | None] = mapped_column(Date) content_text: Mapped[str] = mapped_column(Text, nullable=False) tags: Mapped[dict[str, Any] | None] = mapped_column(JSON) reviewer_id: Mapped[int | None] = mapped_column(BigInteger) review_status: Mapped[str] = mapped_column( String(16), nullable=False, default="pending") status: Mapped[str] = mapped_column(String(16), nullable=False) created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False) updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False) class FaqSynonym(Base): __tablename__ = "agent_faq_synonym" id: Mapped[int] = mapped_column(BigInteger, primary_key=True) knowledge_id: Mapped[int] = mapped_column(BigInteger, nullable=False) phrase: Mapped[str] = mapped_column(String(500), nullable=False) normalized_phrase: Mapped[str] = mapped_column(String(500), nullable=False) phrase_hash: Mapped[str] = mapped_column(String(64), nullable=False) language_code: Mapped[str] = mapped_column( String(16), nullable=False, default="zh-CN") source_type: Mapped[str] = mapped_column( String(24), nullable=False, default="manual") hit_count: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0) status: Mapped[str] = mapped_column(String(16), nullable=False, default="pending") created_by: Mapped[int] = mapped_column(BigInteger, nullable=False) reviewer_id: Mapped[int | None] = mapped_column(BigInteger) reviewed_at: Mapped[datetime | None] = mapped_column(DateTime) created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False) updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False) # 知识生命周期代码沿用该名称;保留别名避免重复声明同一张表。 FinKnowledgeMeta = KnowledgeMeta