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,41 @@
"""
知识库检索日志模型
记录每次检索的查询、结果、耗时等信息,用于分析检索质量。
"""
from sqlalchemy import Column, String, Text, Integer, Float, JSON, Index
from app.base_model import BaseModel
class KnowledgeRetrievalLog(BaseModel):
"""
知识库检索日志
记录每次检索请求的完整信息,用于检索质量分析和优化。
"""
__tablename__ = "ai_knowledge_retrieval_log"
# 检索请求
query = Column(Text, nullable=False, comment="查询文本")
knowledge_base_ids = Column(JSON, nullable=False, comment="检索的知识库ID列表")
retrieval_mode = Column(String(20), default="hybrid", comment="检索模式: vector/fulltext/hybrid")
top_k = Column(Integer, default=5, comment="请求的返回数量")
score_threshold = Column(Float, default=0.5, comment="相似度阈值")
# 检索结果
result_count = Column(Integer, default=0, comment="实际返回结果数")
results = Column(JSON, nullable=True, comment="检索结果摘要(segment_id/score/kb_id")
rerank_applied = Column(String(5), default="false", comment="是否应用了重排序")
# 性能
elapsed_time = Column(Integer, default=0, comment="耗时(毫秒)")
# 来源
source = Column(String(50), nullable=True, comment="调用来源: api/workflow/chat")
user_id = Column(String(21), nullable=True, comment="操作用户ID")
__table_args__ = (
Index('idx_retrieval_log_query_time', 'sys_create_datetime'),
Index('idx_retrieval_log_user', 'user_id'),
)