feat: 回忆录证据血缘与内部评测可追溯,顺带对齐本地评测台与 CI

数据库与模型:新增多版迁移(章节证据快照、对话血缘、记忆事实/时间线 lineage 等),把「成稿 ↔ 对话/记忆」的溯源信息落到表结构里。
业务链路:会话与 WS、回忆录/故事流水线、记忆写入与 enrichment 等跟着接上线索与快照;新增章节证据快照与评测侧 EvalTraceService 等模块,方便组评审用的证据包。
内部评测:自动化 run 与手工 memoir 评审共用可追溯证据;rubric/ judge 相关脚本与文档有配套调整。
app-eval-web:Memoir/实验详情里能展开看证据摘要与 evidence_trace(含对话轮次 id);Vite 代理与 development.sh 注入的 API 端口与当前默认内部评测端口一致,避免改端口后页面连错服务。
工程杂项:GitHub Actions / 仓库说明有更新;各适配器与支付/配额/plan 等多处为小改动或跟随主改动的收尾;新增/扩充了?
This commit is contained in:
Kevin
2026-04-08 15:37:09 +08:00
parent 6772e1269c
commit 309a051038
109 changed files with 4125 additions and 858 deletions

View File

@@ -3,6 +3,7 @@ from sqlalchemy import (
Boolean,
Column,
DateTime,
Float,
ForeignKey,
Integer,
String,
@@ -34,11 +35,20 @@ class Chapter(Base):
is_new = Column(Boolean, default=True)
is_active = Column(Boolean, default=True)
source_segments = Column(JSON, nullable=True)
# 物化当前 canonical 对应的证据闭包segment / story / memory ids供评测与审计见 memoir/chapter_evidence_snapshot
evidence_bundle_json = Column(JSON, nullable=True)
# Phase C指向当前生效的 chapter_evidence_snapshots 行(版本链可审计)
current_evidence_snapshot_id = Column(
String,
ForeignKey("chapter_evidence_snapshots.id", ondelete="SET NULL"),
nullable=True,
)
# story-backed 章节story 变更后标 True由 Celery 重组 canonical_markdown
markdown_compose_dirty = Column(Boolean, default=False, nullable=False)
markdown_composed_at = Column(DateTime(timezone=True), nullable=True)
# 与 canonical 同一生成时机物化;无签名 URL读时 hydrate
reading_segments_json = Column(JSON, nullable=True)
source_lineage_json = Column(JSON, nullable=True)
user = relationship("User", back_populates="chapters")
book = relationship("Book", back_populates="chapters")
@@ -69,6 +79,22 @@ class Chapter(Base):
back_populates="chapter",
cascade="all, delete-orphan",
)
evidence_snapshots = relationship(
"ChapterEvidenceSnapshot",
back_populates="chapter",
foreign_keys="ChapterEvidenceSnapshot.chapter_id",
cascade="all, delete-orphan",
)
evidence_links = relationship(
"ChapterEvidenceLink",
back_populates="chapter",
cascade="all, delete-orphan",
)
current_evidence_snapshot = relationship(
"ChapterEvidenceSnapshot",
foreign_keys=[current_evidence_snapshot_id],
post_update=True,
)
class MemoirImage(Base):
@@ -185,6 +211,60 @@ class ChapterStoryLink(Base):
story = relationship("Story", back_populates="chapter_links")
class ChapterEvidenceSnapshot(Base):
"""章节证据闭包版本快照(一行 = 一次物化current 指针在 Chapter 上)。"""
__tablename__ = "chapter_evidence_snapshots"
id = Column(String, primary_key=True)
chapter_id = Column(
String,
ForeignKey("chapters.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
user_id = Column(String, ForeignKey("users.id"), nullable=False, index=True)
version_no = Column(Integer, nullable=False)
schema_version = Column(Integer, nullable=False, default=1)
segment_ids = Column(JSON, nullable=True)
conversation_ids = Column(JSON, nullable=True)
story_ids = Column(JSON, nullable=True)
memory_chunk_ids = Column(JSON, nullable=True)
memory_fact_ids = Column(JSON, nullable=True)
timeline_event_ids = Column(JSON, nullable=True)
summary_ids = Column(JSON, nullable=True)
notes = Column(JSON, nullable=True)
message_lineage_json = Column(JSON, nullable=True)
captured_at = Column(DateTime(timezone=True), default=utc_now)
chapter = relationship(
"Chapter",
back_populates="evidence_snapshots",
foreign_keys=[chapter_id],
)
class ChapterEvidenceLink(Base):
"""与 StoryEvidenceLink 对称:章节当前态绑定的结构化记忆 id按快照刷新时整批替换"""
__tablename__ = "chapter_evidence_links"
id = Column(String, primary_key=True)
chapter_id = Column(
String,
ForeignKey("chapters.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
evidence_type = Column(String, nullable=False)
evidence_id = Column(String, nullable=False)
role = Column(String, nullable=True)
weight = Column(Float, nullable=True)
created_at = Column(DateTime(timezone=True), default=utc_now)
chapter = relationship("Chapter", back_populates="evidence_links")
class Book(Base):
__tablename__ = "books"