57 lines
2.6 KiB
Python
57 lines
2.6 KiB
Python
from sqlalchemy import Boolean, Enum, ForeignKey, Integer, JSON, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
from app.models.mixins import TimestampMixin
|
|
|
|
|
|
class KnowledgeSource(TimestampMixin, Base):
|
|
"""知识来源模型:保存指南、专家标准和考试要求来源。"""
|
|
|
|
__tablename__ = "knowledge_sources"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
source_code: Mapped[str] = mapped_column(String(64), nullable=False, unique=True, index=True)
|
|
source_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
source_type: Mapped[str] = mapped_column(
|
|
Enum("national_standard", "department_expert", "exam_requirement", "clinical_guideline", "humanistic_care", "other"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
authority_level: Mapped[int] = mapped_column(Integer, default=1)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
|
|
class KnowledgeDocument(TimestampMixin, Base):
|
|
"""知识文档模型:保存知识来源下的具体文档元数据。"""
|
|
|
|
__tablename__ = "knowledge_documents"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
source_id: Mapped[int] = mapped_column(ForeignKey("knowledge_sources.id"), nullable=False, index=True)
|
|
department_id: Mapped[int | None] = mapped_column(ForeignKey("departments.id"), nullable=True, index=True)
|
|
title: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
task_type: Mapped[str | None] = mapped_column(String(64), index=True)
|
|
summary: Mapped[str | None] = mapped_column(Text)
|
|
file_path: Mapped[str | None] = mapped_column(String(512))
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
source = relationship("KnowledgeSource")
|
|
|
|
|
|
class KnowledgeChunk(Base):
|
|
"""知识片段模型:保存评分前检索和拼接使用的指南片段。"""
|
|
|
|
__tablename__ = "knowledge_chunks"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
document_id: Mapped[int] = mapped_column(ForeignKey("knowledge_documents.id"), nullable=False, index=True)
|
|
department_id: Mapped[int | None] = mapped_column(ForeignKey("departments.id"), nullable=True, index=True)
|
|
task_type: Mapped[str | None] = mapped_column(String(64), index=True)
|
|
chunk_text: Mapped[str] = mapped_column(Text, nullable=False)
|
|
keywords: Mapped[list | None] = mapped_column(JSON)
|
|
weight: Mapped[float] = mapped_column(default=1.0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
document = relationship("KnowledgeDocument")
|