Build lightweight AI agent admin

This commit is contained in:
Codex
2026-06-08 18:14:59 +08:00
commit e164840f43
2530 changed files with 435693 additions and 0 deletions
@@ -0,0 +1,39 @@
"""
知识库文档模型
"""
from sqlalchemy import Column, String, Text, Integer, Boolean, DateTime, BigInteger
from app.base_model import BaseModel
class KnowledgeDocument(BaseModel):
"""
知识库文档
记录上传到知识库的文档信息及处理状态
"""
__tablename__ = "ai_knowledge_document"
knowledge_base_id = Column(String(21), nullable=False, index=True, comment="所属知识库ID(逻辑外键关联ai_knowledge_base")
file_id = Column(String(21), nullable=True, comment="关联文件ID(逻辑外键关联core_file_manager")
name = Column(String(255), nullable=False, comment="文档名称")
file_type = Column(String(20), nullable=True, comment="文件类型: pdf/docx/txt/md/xlsx/csv/html/pptx")
file_size = Column(BigInteger, default=0, comment="文件大小(字节)")
content_hash = Column(String(64), nullable=True, index=True, comment="内容MD5(用于去重)")
# 处理结果
segment_count = Column(Integer, default=0, comment="分段数量")
token_count = Column(Integer, default=0, comment="Token 总数")
char_count = Column(Integer, default=0, comment="字符总数")
# 处理状态
status = Column(String(20), default="pending", index=True, comment="状态: pending/indexing/completed/failed/disabled")
error_message = Column(Text, nullable=True, comment="错误信息")
indexing_started_at = Column(DateTime, nullable=True, comment="索引开始时间")
indexing_completed_at = Column(DateTime, nullable=True, comment="索引完成时间")
# 去重
duplicate_warning = Column(Text, nullable=True, comment="内容重复警告(跨知识库检测)")
# 是否启用
enabled = Column(Boolean, default=True, comment="是否启用(禁用后不参与检索)")